libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-simd-15.c
blob6982a59da78276bad2779827ee0b8c1e1691e2e3
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];
11 unsigned short r2, b2[1024];
12 unsigned char r3, b3[1024];
14 __attribute__((noipa)) void
15 foo (int *a, int *b, unsigned short *b2, unsigned char *b3)
17 #pragma omp simd reduction (inscan, +:r, r2, r3)
18 for (int i = 0; i < 1024; i++)
21 b[i] = r;
22 b2[i] = r2;
23 b3[i] = r3;
25 #pragma omp scan exclusive(r, r2, r3)
26 { r += a[i]; r2 += a[i]; r3 += a[i]; }
30 __attribute__((noipa)) int
31 bar (unsigned short *s2p, unsigned char *s3p)
33 int s = 0;
34 unsigned short s2 = 0;
35 unsigned char s3 = 0;
36 #pragma omp simd reduction (inscan, +:s, s2, s3)
37 for (int i = 0; i < 1024; i++)
39 { b[i] = s; b2[i] = s2; b3[i] = s3; }
40 #pragma omp scan exclusive(s, s2, s3)
42 s += 2 * a[i];
43 s2 += 2 * a[i];
44 s3 += 2 * a[i];
47 *s2p = s2;
48 *s3p = s3;
49 return s;
52 __attribute__((noipa)) void
53 baz (int *a, int *b, unsigned short *b2, unsigned char *b3)
55 #pragma omp simd reduction (inscan, +:r, r2, r3) if (simd: 0)
56 for (int i = 0; i < 1024; i++)
59 b[i] = r;
60 b2[i] = r2;
61 b3[i] = r3;
63 #pragma omp scan exclusive(r, r2, r3)
65 r += a[i];
66 r2 += a[i];
67 r3 += a[i];
72 __attribute__((noipa)) int
73 qux (unsigned short *s2p, unsigned char *s3p)
75 int s = 0;
76 unsigned short s2 = 0;
77 unsigned char s3 = 0;
78 #pragma omp simd reduction (inscan, +:s, s2, s3) simdlen (1)
79 for (int i = 0; i < 1024; i++)
81 { b[i] = s; b2[i] = s2; b3[i] = s3; }
82 #pragma omp scan exclusive(s, s2, s3)
83 { s += 2 * a[i]; s2 += 2 * a[i]; s3 += 2 * a[i]; }
85 *s2p = s2;
86 *s3p = s3;
87 return s;
90 int
91 main ()
93 int s = 0;
94 unsigned short s2;
95 unsigned char s3;
96 #ifndef main
97 check_vect ();
98 #endif
99 for (int i = 0; i < 1024; ++i)
101 a[i] = i;
102 b[i] = -1;
103 b2[i] = -1;
104 b3[i] = -1;
105 asm ("" : "+g" (i));
107 foo (a, b, b2, b3);
108 if (r != 1024 * 1023 / 2
109 || r2 != (unsigned short) r
110 || r3 != (unsigned char) r)
111 abort ();
112 #pragma GCC novector
113 for (int i = 0; i < 1024; ++i)
115 if (b[i] != s
116 || b2[i] != (unsigned short) s
117 || b3[i] != (unsigned char) s)
118 abort ();
119 else
121 b[i] = 25;
122 b2[i] = 24;
123 b3[i] = 26;
125 s += i;
127 if (bar (&s2, &s3) != 1024 * 1023)
128 abort ();
129 if (s2 != (unsigned short) (1024 * 1023)
130 || s3 != (unsigned char) (1024 * 1023))
131 abort ();
132 s = 0;
133 #pragma GCC novector
134 for (int i = 0; i < 1024; ++i)
136 if (b[i] != s
137 || b2[i] != (unsigned short) s
138 || b3[i] != (unsigned char) s)
139 abort ();
140 else
142 b[i] = -1;
143 b2[i] = -1;
144 b3[i] = -1;
146 s += 2 * i;
148 r = 0;
149 r2 = 0;
150 r3 = 0;
151 baz (a, b, b2, b3);
152 if (r != 1024 * 1023 / 2
153 || r2 != (unsigned short) r
154 || r3 != (unsigned char) r)
155 abort ();
156 s = 0;
157 #pragma GCC novector
158 for (int i = 0; i < 1024; ++i)
160 if (b[i] != s
161 || b2[i] != (unsigned short) s
162 || b3[i] != (unsigned char) s)
163 abort ();
164 else
166 b[i] = 25;
167 b2[i] = 24;
168 b3[i] = 26;
170 s += i;
172 s2 = 0;
173 s3 = 0;
174 if (qux (&s2, &s3) != 1024 * 1023)
175 abort ();
176 if (s2 != (unsigned short) (1024 * 1023)
177 || s3 != (unsigned char) (1024 * 1023))
178 abort ();
179 s = 0;
180 #pragma GCC novector
181 for (int i = 0; i < 1024; ++i)
183 if (b[i] != s
184 || b2[i] != (unsigned short) s
185 || b3[i] != (unsigned char) s)
186 abort ();
187 s += 2 * i;
189 return 0;