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