PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-all.c
blobcc41e2dd3d313a0557dea16204564a5a0c694950
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 16
10 int iadd_results[N] = {0,6,12,18,24,30,36,42,48,54,60,66,72,78,84,90};
11 float fadd_results[N] = {0.0,6.0,12.0,18.0,24.0,30.0,36.0,42.0,48.0,54.0,60.0,66.0,72.0,78.0,84.0,90.0};
12 float fmul_results[N] = {0.0,3.0,12.0,27.0,48.0,75.0,108.0,147.0,192.0,243.0,300.0,363.0,432.0,507.0,588.0,675.0};
13 float fresults1[N] = {192.00,240.00,288.00,336.00,384.00,432.00,480.00,528.00,48.00,54.00,60.00,66.00,72.00,78.00,84.00,90.00};
14 float fresults2[N] = {0.00,6.00,12.00,18.00,24.00,30.00,36.00,42.00,0.00,54.00,120.00,198.00,288.00,390.00,504.00,630.00};
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 /* All of the loops below are currently vectorizable. */
83 __attribute__ ((noinline)) int
84 main1 ()
86 int i,j;
88 /* Test 1: copy chars. */
89 for (i = 0; i < N; i++)
91 ca[i] = cb[i];
93 /* check results: */
94 for (i = 0; i < N; i++)
96 if (ca[i] != cb[i])
97 abort ();
101 /* Test 2: fp mult. */
102 for (i = 0; i < N; i++)
104 a[i] = b[i] * c[i];
106 fbar_mul (a);
109 /* Test 3: mixed types (int, fp), same nunits in vector. */
110 for (i = 0; i < N; i++)
112 a[i] = b[i] + c[i] + d[i];
113 e[i] = b[i] + c[i] + d[i];
114 ia[i] = ib[i] + ic[i];
116 ibar_add (ia);
117 fbar_add (a);
118 fbar_add (e);
121 /* Test 4: access with offset. */
122 for (i = 0; i < N/2; i++)
124 a[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i];
125 e[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i];
127 fbar1 (a);
128 fbar2 (e);
131 /* Test 5: access with offset */
132 for (i = 1; i <=N-4; i++)
134 a[i+3] = b[i-1];
136 /* check results: */
137 for (i = 1; i <=N-4; i++)
139 if (a[i+3] != b[i-1])
140 abort ();
144 /* Test 6 - loop induction with stride != 1. */
145 i = 0;
146 j = 0;
147 while (i < 5*N)
149 a[j] = c[j];
150 i += 5;
151 j++;
153 /* check results: */
154 for (i = 0; i <N; i++)
156 if (a[i] != c[i])
157 abort ();
161 /* Test 7 - reverse access. */
162 for (i = N; i > 0; i--)
164 a[N-i] = d[N-i];
166 /* check results: */
167 for (i = 0; i <N; i++)
169 if (a[i] != d[i])
170 abort ();
174 /* Tests 8,9,10 - constants. */
175 for (i = 0; i < N; i++)
177 a[i] = 5.0;
179 /* check results: */
180 for (i = 0; i < N; i++)
182 if (a[i] != 5.0)
183 abort ();
186 for (i = 0; i < N; i++)
188 sa[i] = 5;
190 /* check results: */
191 for (i = 0; i < N; i++)
193 if (sa[i] != 5)
194 abort ();
197 for (i = 0; i < N; i++)
199 ia[i] = ib[i] + 5;
201 /* check results: */
202 for (i = 0; i < N; i++)
204 if (ia[i] != ib[i] + 5)
205 abort ();
208 return 0;
211 int main (void)
213 check_vect ();
215 return main1 ();
218 /* { dg-final { scan-tree-dump-times "vectorized 10 loops" 1 "vect" } } */
219 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" { target { { vect_aligned_arrays } && {! vect_sizes_32B_16B} } } } } */
220 /* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 1 "vect" { target { {! vect_aligned_arrays } && {vect_sizes_32B_16B} } } } } */
221 /* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 0 "vect" } } */