1 #define N 200
2 #define DIST 32
3
4 typedef signed char sc;
5 typedef unsigned char uc;
6 typedef signed short ss;
7 typedef unsigned short us;
8 typedef int si;
9 typedef unsigned int ui;
10 typedef signed long long sll;
11 typedef unsigned long long ull;
12
13 #define FOR_EACH_TYPE(M) \
14 M (sc) M (uc) \
15 M (ss) M (us) \
16 M (si) M (ui) \
17 M (sll) M (ull) \
18 M (float) M (double)
19
20 #define ADD_TEST(TYPE) \
21 TYPE a_##TYPE[N * 2]; \
22 void __attribute__((noinline, noclone)) \
23 test_##TYPE (int x, int y) \
24 { \
25 for (int i = 0; i < N; ++i) \
26 { \
27 a_##TYPE[i + x] = i; \
28 a_##TYPE[i + y] = 42 - i * 2; \
29 } \
30 }
31
32 #define DO_TEST(TYPE) \
33 for (int i = 0; i < DIST * 2; ++i) \
34 { \
35 __builtin_memset (a_##TYPE, 0, sizeof (a_##TYPE)); \
36 test_##TYPE (DIST, i); \
37 for (int j = 0; j < N + DIST * 2; ++j) \
38 { \
39 TYPE expected = 0; \
40 if (i > DIST && j >= i && j < i + N) \
41 expected = 42 - (j - i) * 2; \
42 if (j >= DIST && j < DIST + N) \
43 expected = j - DIST; \
44 if (i <= DIST && j >= i && j < i + N) \
45 expected = 42 - (j - i) * 2; \
46 if (expected != a_##TYPE[j]) \
47 __builtin_abort (); \
48 } \
49 }
50
51 FOR_EACH_TYPE (ADD_TEST)
52
53 int
54 main (void)
55 {
56 FOR_EACH_TYPE (DO_TEST)
57 return 0;
58 }
59
60 /* { dg-final { scan-tree-dump {flags: *WAW\n} "vect" { target vect_int } } } */
61 /* { dg-final { scan-tree-dump "using an index-based WAR/WAW test" "vect" } } */
62 /* { dg-final { scan-tree-dump-not "using an address-based" "vect" } } */