libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-simd-13.c
blob3ef4aa9a991c0b6259f3b3057616c1aa298663d9
1 /* { dg-require-effective-target size32plus } */
2 /* { dg-additional-options "-fopenmp-simd" } */
3 /* { dg-additional-options "-mavx" { target avx_runtime } } */
4 /* { dg-final { scan-tree-dump-times "vectorized \[1-3] loops" 2 "vect" { target i?86-*-* x86_64-*-* } } } */
6 #ifndef main
7 #include "tree-vect.h"
8 #endif
10 int r, a[1024], b[1024];
12 #pragma omp declare reduction (foo: int: omp_out += omp_in) initializer (omp_priv = 0)
14 __attribute__((noipa)) void
15 foo (int *a, int *b)
17 #pragma omp simd reduction (inscan, foo:r)
18 for (int i = 0; i < 1024; i++)
20 b[i] = r;
21 #pragma omp scan exclusive(r)
22 r += a[i];
26 __attribute__((noipa)) int
27 bar (void)
29 int s = 0;
30 #pragma omp simd reduction (inscan, foo:s)
31 for (int i = 0; i < 1024; i++)
33 b[i] = s;
34 #pragma omp scan exclusive(s)
35 s += 2 * a[i];
37 return s;
40 __attribute__((noipa)) void
41 baz (int *a, int *b)
43 #pragma omp simd reduction (inscan, foo:r) if (simd: 0)
44 for (int i = 0; i < 1024; i++)
46 b[i] = r;
47 #pragma omp scan exclusive(r)
48 r += a[i];
52 __attribute__((noipa)) int
53 qux (void)
55 int s = 0;
56 #pragma omp simd reduction (inscan, foo:s) simdlen (1)
57 for (int i = 0; i < 1024; i++)
59 b[i] = s;
60 #pragma omp scan exclusive(s)
61 s += 2 * a[i];
63 return s;
66 int
67 main ()
69 int s = 0;
70 #ifndef main
71 check_vect ();
72 #endif
73 for (int i = 0; i < 1024; ++i)
75 a[i] = i;
76 b[i] = -1;
77 asm ("" : "+g" (i));
79 foo (a, b);
80 if (r != 1024 * 1023 / 2)
81 abort ();
82 #pragma GCC novector
83 for (int i = 0; i < 1024; ++i)
85 if (b[i] != s)
86 abort ();
87 else
88 b[i] = 25;
89 s += i;
91 if (bar () != 1024 * 1023)
92 abort ();
93 s = 0;
94 #pragma GCC novector
95 for (int i = 0; i < 1024; ++i)
97 if (b[i] != s)
98 abort ();
99 else
100 b[i] = -1;
101 s += 2 * i;
103 r = 0;
104 baz (a, b);
105 if (r != 1024 * 1023 / 2)
106 abort ();
107 s = 0;
108 #pragma GCC novector
109 for (int i = 0; i < 1024; ++i)
111 if (b[i] != s)
112 abort ();
113 else
114 b[i] = -25;
115 s += i;
117 if (qux () != 1024 * 1023)
118 abort ();
119 s = 0;
120 #pragma GCC novector
121 for (int i = 0; i < 1024; ++i)
123 if (b[i] != s)
124 abort ();
125 s += 2 * i;
127 return 0;