Small ChangeLog tweak.
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-all-big-array.c
blob4826cdb93e8f10033fe8cb24a28ccd472a9b4f56
1 /* { dg-require-effective-target vect_int } */
2 /* { dg-require-effective-target vect_float } */
3 /* { dg-add-options bind_pic_locally } */
5 #include <stdarg.h>
6 #include "tree-vect.h"
8 #define N 128
10 int iadd_results[N];
11 float fadd_results[N];
12 float fmul_results[N];
13 float fresults1[N];
14 float fresults2[N];
16 /****************************************************/
17 __attribute__ ((noinline))
18 void icheck_results (int *a, int *results)
20 int i;
21 for (i = 0; i < N; i++)
23 if (a[i] != results[i])
24 abort ();
28 __attribute__ ((noinline))
29 void fcheck_results (float *a, float *results)
31 int i;
32 for (i = 0; i < N; i++)
34 if (a[i] != results[i])
35 abort ();
39 __attribute__ ((noinline)) void
40 fbar_mul (float *a)
42 fcheck_results (a, fmul_results);
45 __attribute__ ((noinline)) void
46 fbar_add (float *a)
48 fcheck_results (a, fadd_results);
51 __attribute__ ((noinline)) void
52 ibar_add (int *a)
54 icheck_results (a, iadd_results);
57 __attribute__ ((noinline)) void
58 fbar1 (float *a)
60 fcheck_results (a, fresults1);
63 __attribute__ ((noinline)) void
64 fbar2 (float *a)
66 fcheck_results (a, fresults2);
69 float a[N];
70 float e[N];
71 float b[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
72 float c[N] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
73 float d[N] = {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30};
74 int ic[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
75 int ib[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
76 int ia[N];
77 char cb[N] = {0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45};
78 char ca[N];
79 short sa[N];
81 volatile int y = 0;
83 /* All of the loops below are currently vectorizable, except
84 initialization ones. */
86 __attribute__ ((noinline)) int
87 main1 ()
89 int i,j;
90 /* Initialization. */
91 for (i = 0; i < N; i++)
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 if (y)
105 abort ();
108 /* Test 1: copy chars. */
109 for (i = 0; i < N; i++)
111 ca[i] = cb[i];
113 /* check results: */
114 for (i = 0; i < N; i++)
116 if (ca[i] != cb[i])
117 abort ();
121 /* Test 2: fp mult. */
122 for (i = 0; i < N; i++)
124 a[i] = b[i] * c[i];
126 fbar_mul (a);
129 /* Test 3: mixed types (int, fp), same nunits in vector. */
130 for (i = 0; i < N; i++)
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];
136 ibar_add (ia);
137 fbar_add (a);
138 fbar_add (e);
140 /* Initialization. */
141 for (i = 0; i < N; i++)
143 fresults1[i] = a[i];
144 fresults2[i] = e[i];
145 if (y)
146 abort ();
148 for (i = 0; i < N/2; i++)
150 fresults1[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i];
151 fresults2[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i];
152 if (y)
153 abort ();
155 /* Test 4: access with offset. */
156 for (i = 0; i < N/2; i++)
158 a[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i];
159 e[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i];
161 fbar1 (a);
162 fbar2 (e);
165 /* Test 5: access with offset. */
166 for (i = 1; i <=N-4; i++)
168 a[i+3] = b[i-1];
170 /* check results: */
171 for (i = 1; i <=N-4; i++)
173 if (a[i+3] != b[i-1])
174 abort ();
178 /* Test 6 - loop induction with stride != 1. */
179 i = 0;
180 j = 0;
181 while (i < 5*N)
183 a[j] = c[j];
184 i += 5;
185 j++;
187 /* check results: */
188 for (i = 0; i <N; i++)
190 if (a[i] != c[i])
191 abort ();
195 /* Test 7 - reverse access. */
196 for (i = N; i > 0; i--)
198 a[N-i] = d[N-i];
200 /* check results: */
201 for (i = 0; i <N; i++)
203 if (a[i] != d[i])
204 abort ();
208 /* Tests 8,9,10 - constants. */
209 for (i = 0; i < N; i++)
211 a[i] = 5.0;
213 /* check results: */
214 for (i = 0; i < N; i++)
216 if (a[i] != 5.0)
217 abort ();
220 for (i = 0; i < N; i++)
222 sa[i] = 5;
224 /* check results: */
225 for (i = 0; i < N; i++)
227 if (sa[i] != 5)
228 abort ();
231 for (i = 0; i < N; i++)
233 ia[i] = ib[i] + 5;
235 /* check results: */
236 for (i = 0; i < N; i++)
238 if (ia[i] != ib[i] + 5)
239 abort ();
242 return 0;
245 int main (void)
247 check_vect ();
249 return main1 ();
252 /* { dg-final { scan-tree-dump-times "vectorized 10 loops" 1 "vect" } } */
253 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" { target { { vect_aligned_arrays } && {! vect_sizes_32B_16B} } } } } */
254 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 1 "vect" { target { {! vect_aligned_arrays } && {vect_sizes_32B_16B} } } } } */
255 /* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 0 "vect" } } */