aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/tree-ssa/ldist-rawmemchr-1.c
blob: adf53b10deff9d2036718c273e011cbb82db3d24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* { dg-do run { target { { s390x-*-* } || { riscv_v } } } } */
/* { dg-options "-O2 -ftree-loop-distribution -fdump-tree-ldist-details" } */
/* { dg-additional-options "-march=z13 -mzarch" { target s390x-*-* } } */
/* { dg-final { scan-tree-dump-times "generated rawmemchrQI" 2 "ldist" { target { { s390x-*-* } || { riscv_v } } } } } */
/* { dg-final { scan-tree-dump-times "generated rawmemchrHI" 2 "ldist" { target { { s390x-*-* } || { riscv_v } } } } } */
/* { dg-final { scan-tree-dump-times "generated rawmemchrSI" 2 "ldist" { target { { s390x-*-* } || { riscv_v } } } } } */

/* Rawmemchr pattern: reduction stmt and no store */

#include <stdint.h>
#include <assert.h>

typedef __SIZE_TYPE__ size_t;
extern void* malloc (size_t);
extern void* memset (void*, int, size_t);

#define test(T, pattern)   \
__attribute__((noinline))  \
T *test_##T (T *p)         \
{                          \
  while (*p != (T)pattern) \
    ++p;                   \
  return p;                \
}

test (uint8_t,  0xab)
test (uint16_t, 0xabcd)
test (uint32_t, 0xabcdef15)

test (int8_t,  0xab)
test (int16_t, 0xabcd)
test (int32_t, 0xabcdef15)

#define run(T, pattern, i)      \
{                               \
T *q = p;                       \
q[i] = (T)pattern;              \
assert (test_##T (p) == &q[i]); \
q[i] = 0;                       \
}

int main(void)
{
  void *p = malloc (1024);
  assert (p);
  memset (p, 0, 1024);

  run (uint8_t, 0xab, 0);
  run (uint8_t, 0xab, 1);
  run (uint8_t, 0xab, 13);

  run (uint16_t, 0xabcd, 0);
  run (uint16_t, 0xabcd, 1);
  run (uint16_t, 0xabcd, 13);

  run (uint32_t, 0xabcdef15, 0);
  run (uint32_t, 0xabcdef15, 1);
  run (uint32_t, 0xabcdef15, 13);

  run (int8_t, 0xab, 0);
  run (int8_t, 0xab, 1);
  run (int8_t, 0xab, 13);

  run (int16_t, 0xabcd, 0);
  run (int16_t, 0xabcd, 1);
  run (int16_t, 0xabcd, 13);

  run (int32_t, 0xabcdef15, 0);
  run (int32_t, 0xabcdef15, 1);
  run (int32_t, 0xabcdef15, 13);

  return 0;
}