Debian Codegraph @

gcc/testsuite/gcc.dg/vect/vect-all-big-array.c

raw
1 /* { dg-require-effective-target vect_int } */
2 /* { dg-require-effective-target vect_float } */
3 /* { dg-add-options bind_pic_locally } */
4
5 #include <stdarg.h>
6 #include "tree-vect.h"
7
8 #define N 128
9
10 int iadd_results[N];
11 float fadd_results[N];
12 float fmul_results[N];
13 float fresults1[N];
14 float fresults2[N];
15
16 /****************************************************/
17 __attribute__ ((noinline))
18 void icheck_results (int *a, int *results)
19 {
20 int i;
21 #pragma GCC novector
22 for (i = 0; i < N; i++)
23 {
24 if (a[i] != results[i])
25 abort ();
26 }
27 }
28
29 __attribute__ ((noinline))
30 void fcheck_results (float *a, float *results)
31 {
32 int i;
33 #pragma GCC novector
34 for (i = 0; i < N; i++)
35 {
36 if (a[i] != results[i])
37 abort ();
38 }
39 }
40
41 __attribute__ ((noinline)) void
42 fbar_mul (float *a)
43 {
44 fcheck_results (a, fmul_results);
45 }
46
47 __attribute__ ((noinline)) void
48 fbar_add (float *a)
49 {
50 fcheck_results (a, fadd_results);
51 }
52
53 __attribute__ ((noinline)) void
54 ibar_add (int *a)
55 {
56 icheck_results (a, iadd_results);
57 }
58
59 __attribute__ ((noinline)) void
60 fbar1 (float *a)
61 {
62 fcheck_results (a, fresults1);
63 }
64
65 __attribute__ ((noinline)) void
66 fbar2 (float *a)
67 {
68 fcheck_results (a, fresults2);
69 }
70
71 float a[N];
72 float e[N];
73 float b[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
74 float c[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
75 float d[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30};
76 int ic[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
77 int ib[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
78 int ia[N];
79 char cb[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
80 char ca[N];
81 short sa[N];
82
83 /* All of the loops below are currently vectorizable, except
84 initialization ones. */
85
86 __attribute__ ((noinline)) int
87 main1 ()
88 {
89 int i,j;
90 /* Initialization. */
91 for (i = 0; i < N; i++)
92 {
93 b[i] = i*3;
94 c[i] = i;
95 d[i] = i*2;
96 ic[i] = i*3;
97 ib[i] = i*3;
98 cb[i] = i*3;
99 fadd_results[i] = b[i] + c[i] + d[i];
100 iadd_results[i] = ib[i] + ic[i];
101 fmul_results[i] = b[i] * c[i];
102 fresults1[i] = 0;
103 fresults2[i] = 0;
104 asm volatile ("" ::: "memory");
105 }
106
107 /* Test 1: copy chars. */
108 for (i = 0; i < N; i++)
109 {
110 ca[i] = cb[i];
111 }
112 /* check results: */
113 #pragma GCC novector
114 for (i = 0; i < N; i++)
115 {
116 if (ca[i] != cb[i])
117 abort ();
118 }
119
120
121 /* Test 2: fp mult. */
122 for (i = 0; i < N; i++)
123 {
124 a[i] = b[i] * c[i];
125 }
126 fbar_mul (a);
127
128
129 /* Test 3: mixed types (int, fp), same nunits in vector. */
130 for (i = 0; i < N; i++)
131 {
132 a[i] = b[i] + c[i] + d[i];
133 e[i] = b[i] + c[i] + d[i];
134 ia[i] = ib[i] + ic[i];
135 }
136 ibar_add (ia);
137 fbar_add (a);
138 fbar_add (e);
139
140 /* Initialization. */
141 for (i = 0; i < N; i++)
142 {
143 fresults1[i] = a[i];
144 fresults2[i] = e[i];
145 asm volatile ("" ::: "memory");
146 }
147 for (i = 0; i < N/2; i++)
148 {
149 fresults1[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i];
150 fresults2[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i];
151 asm volatile ("" ::: "memory");
152 }
153 /* Test 4: access with offset. */
154 for (i = 0; i < N/2; i++)
155 {
156 a[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i];
157 e[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i];
158 }
159 fbar1 (a);
160 fbar2 (e);
161
162
163 /* Test 5: access with offset. */
164 for (i = 1; i <=N-4; i++)
165 {
166 a[i+3] = b[i-1];
167 }
168 /* check results: */
169 #pragma GCC novector
170 for (i = 1; i <=N-4; i++)
171 {
172 if (a[i+3] != b[i-1])
173 abort ();
174 }
175
176
177 /* Test 6 - loop induction with stride != 1. */
178 i = 0;
179 j = 0;
180 while (i < 5*N)
181 {
182 a[j] = c[j];
183 i += 5;
184 j++;
185 }
186 /* check results: */
187 #pragma GCC novector
188 for (i = 0; i <N; i++)
189 {
190 if (a[i] != c[i])
191 abort ();
192 }
193
194
195 /* Test 7 - reverse access. */
196 for (i = N; i > 0; i--)
197 {
198 a[N-i] = d[N-i];
199 }
200 /* check results: */
201 #pragma GCC novector
202 for (i = 0; i <N; i++)
203 {
204 if (a[i] != d[i])
205 abort ();
206 }
207
208
209 /* Tests 8,9,10 - constants. */
210 for (i = 0; i < N; i++)
211 {
212 a[i] = 5.0;
213 }
214 /* check results: */
215 #pragma GCC novector
216 for (i = 0; i < N; i++)
217 {
218 if (a[i] != 5.0)
219 abort ();
220 }
221
222 for (i = 0; i < N; i++)
223 {
224 sa[i] = 5;
225 }
226 /* check results: */
227 #pragma GCC novector
228 for (i = 0; i < N; i++)
229 {
230 if (sa[i] != 5)
231 abort ();
232 }
233
234 for (i = 0; i < N; i++)
235 {
236 ia[i] = ib[i] + 5;
237 }
238 /* check results: */
239 #pragma GCC novector
240 for (i = 0; i < N; i++)
241 {
242 if (ia[i] != ib[i] + 5)
243 abort ();
244 }
245
246 return 0;
247 }
248
249 int main (void)
250 {
251 check_vect ();
252
253 return main1 ();
254 }
255
256 /* { dg-final { scan-tree-dump-times "vectorized 10 loops" 1 "vect" } } */
257 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" { target { { vect_aligned_arrays } && {! vect_sizes_32B_16B} } } } } */
258 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 1 "vect" { target { {! vect_aligned_arrays } && {vect_sizes_32B_16B} } } } } */
259 /* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 0 "vect" } } */