| 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 16 |
| 9 |
|
| 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}; |
| 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. */ |
| 84 |
|
| 85 |
__attribute__ ((noinline)) int |
| 86 |
main1 () |
| 87 |
{ |
| 88 |
int i,j; |
| 89 |
|
| 90 |
/* Test 1: copy chars. */ |
| 91 |
for (i = 0; i < N; i++) |
| 92 |
{ |
| 93 |
ca[i] = cb[i]; |
| 94 |
} |
| 95 |
/* check results: */ |
| 96 |
#pragma GCC novector |
| 97 |
for (i = 0; i < N; i++) |
| 98 |
{ |
| 99 |
if (ca[i] != cb[i]) |
| 100 |
abort (); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
/* Test 2: fp mult. */ |
| 105 |
for (i = 0; i < N; i++) |
| 106 |
{ |
| 107 |
a[i] = b[i] * c[i]; |
| 108 |
} |
| 109 |
fbar_mul (a); |
| 110 |
|
| 111 |
|
| 112 |
/* Test 3: mixed types (int, fp), same nunits in vector. */ |
| 113 |
for (i = 0; i < N; i++) |
| 114 |
{ |
| 115 |
a[i] = b[i] + c[i] + d[i]; |
| 116 |
e[i] = b[i] + c[i] + d[i]; |
| 117 |
ia[i] = ib[i] + ic[i]; |
| 118 |
} |
| 119 |
ibar_add (ia); |
| 120 |
fbar_add (a); |
| 121 |
fbar_add (e); |
| 122 |
|
| 123 |
|
| 124 |
/* Test 4: access with offset. */ |
| 125 |
for (i = 0; i < N/2; i++) |
| 126 |
{ |
| 127 |
a[i] = b[i+N/2] * c[i+N/2] - b[i] * c[i]; |
| 128 |
e[i+N/2] = b[i] * c[i+N/2] + b[i+N/2] * c[i]; |
| 129 |
} |
| 130 |
fbar1 (a); |
| 131 |
fbar2 (e); |
| 132 |
|
| 133 |
|
| 134 |
/* Test 5: access with offset */ |
| 135 |
for (i = 1; i <=N-4; i++) |
| 136 |
{ |
| 137 |
a[i+3] = b[i-1]; |
| 138 |
} |
| 139 |
/* check results: */ |
| 140 |
#pragma GCC novector |
| 141 |
for (i = 1; i <=N-4; i++) |
| 142 |
{ |
| 143 |
if (a[i+3] != b[i-1]) |
| 144 |
abort (); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
/* Test 6 - loop induction with stride != 1. */ |
| 149 |
i = 0; |
| 150 |
j = 0; |
| 151 |
while (i < 5*N) |
| 152 |
{ |
| 153 |
a[j] = c[j]; |
| 154 |
i += 5; |
| 155 |
j++; |
| 156 |
} |
| 157 |
/* check results: */ |
| 158 |
#pragma GCC novector |
| 159 |
for (i = 0; i <N; i++) |
| 160 |
{ |
| 161 |
if (a[i] != c[i]) |
| 162 |
abort (); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
/* Test 7 - reverse access. */ |
| 167 |
for (i = N; i > 0; i--) |
| 168 |
{ |
| 169 |
a[N-i] = d[N-i]; |
| 170 |
} |
| 171 |
/* check results: */ |
| 172 |
#pragma GCC novector |
| 173 |
for (i = 0; i <N; i++) |
| 174 |
{ |
| 175 |
if (a[i] != d[i]) |
| 176 |
abort (); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
/* Tests 8,9,10 - constants. */ |
| 181 |
for (i = 0; i < N; i++) |
| 182 |
{ |
| 183 |
a[i] = 5.0; |
| 184 |
} |
| 185 |
/* check results: */ |
| 186 |
#pragma GCC novector |
| 187 |
for (i = 0; i < N; i++) |
| 188 |
{ |
| 189 |
if (a[i] != 5.0) |
| 190 |
abort (); |
| 191 |
} |
| 192 |
|
| 193 |
for (i = 0; i < N; i++) |
| 194 |
{ |
| 195 |
sa[i] = 5; |
| 196 |
} |
| 197 |
/* check results: */ |
| 198 |
#pragma GCC novector |
| 199 |
for (i = 0; i < N; i++) |
| 200 |
{ |
| 201 |
if (sa[i] != 5) |
| 202 |
abort (); |
| 203 |
} |
| 204 |
|
| 205 |
for (i = 0; i < N; i++) |
| 206 |
{ |
| 207 |
ia[i] = ib[i] + 5; |
| 208 |
} |
| 209 |
/* check results: */ |
| 210 |
#pragma GCC novector |
| 211 |
for (i = 0; i < N; i++) |
| 212 |
{ |
| 213 |
if (ia[i] != ib[i] + 5) |
| 214 |
abort (); |
| 215 |
} |
| 216 |
|
| 217 |
return 0; |
| 218 |
} |
| 219 |
|
| 220 |
int main (void) |
| 221 |
{ |
| 222 |
check_vect (); |
| 223 |
|
| 224 |
return main1 (); |
| 225 |
} |
| 226 |
|
| 227 |
/* { dg-final { scan-tree-dump-times "vectorized 10 loops" 1 "vect" } } */ |
| 228 |
/* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 0 "vect" { target { { vect_aligned_arrays } && {! vect_sizes_32B_16B} } } } } */ |
| 229 |
/* { dg-final { scan-tree-dump-times "Vectorizing an unaligned access" 1 "vect" { target { {! vect_aligned_arrays } && {vect_sizes_32B_16B} } } } } */ |
| 230 |
/* { dg-final { scan-tree-dump-times "Alignment of access forced using peeling" 0 "vect" } } */ |