libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / ldist-rawmemchr-1.c
blobadf53b10deff9d2036718c273e011cbb82db3d24
1 /* { dg-do run { target { { s390x-*-* } || { riscv_v } } } } */
2 /* { dg-options "-O2 -ftree-loop-distribution -fdump-tree-ldist-details" } */
3 /* { dg-additional-options "-march=z13 -mzarch" { target s390x-*-* } } */
4 /* { dg-final { scan-tree-dump-times "generated rawmemchrQI" 2 "ldist" { target { { s390x-*-* } || { riscv_v } } } } } */
5 /* { dg-final { scan-tree-dump-times "generated rawmemchrHI" 2 "ldist" { target { { s390x-*-* } || { riscv_v } } } } } */
6 /* { dg-final { scan-tree-dump-times "generated rawmemchrSI" 2 "ldist" { target { { s390x-*-* } || { riscv_v } } } } } */
8 /* Rawmemchr pattern: reduction stmt and no store */
10 #include <stdint.h>
11 #include <assert.h>
13 typedef __SIZE_TYPE__ size_t;
14 extern void* malloc (size_t);
15 extern void* memset (void*, int, size_t);
17 #define test(T, pattern) \
18 __attribute__((noinline)) \
19 T *test_##T (T *p) \
20 { \
21 while (*p != (T)pattern) \
22 ++p; \
23 return p; \
26 test (uint8_t, 0xab)
27 test (uint16_t, 0xabcd)
28 test (uint32_t, 0xabcdef15)
30 test (int8_t, 0xab)
31 test (int16_t, 0xabcd)
32 test (int32_t, 0xabcdef15)
34 #define run(T, pattern, i) \
35 { \
36 T *q = p; \
37 q[i] = (T)pattern; \
38 assert (test_##T (p) == &q[i]); \
39 q[i] = 0; \
42 int main(void)
44 void *p = malloc (1024);
45 assert (p);
46 memset (p, 0, 1024);
48 run (uint8_t, 0xab, 0);
49 run (uint8_t, 0xab, 1);
50 run (uint8_t, 0xab, 13);
52 run (uint16_t, 0xabcd, 0);
53 run (uint16_t, 0xabcd, 1);
54 run (uint16_t, 0xabcd, 13);
56 run (uint32_t, 0xabcdef15, 0);
57 run (uint32_t, 0xabcdef15, 1);
58 run (uint32_t, 0xabcdef15, 13);
60 run (int8_t, 0xab, 0);
61 run (int8_t, 0xab, 1);
62 run (int8_t, 0xab, 13);
64 run (int16_t, 0xabcd, 0);
65 run (int16_t, 0xabcd, 1);
66 run (int16_t, 0xabcd, 13);
68 run (int32_t, 0xabcdef15, 0);
69 run (int32_t, 0xabcdef15, 1);
70 run (int32_t, 0xabcdef15, 13);
72 return 0;