| 1 |
/* { dg-skip-if "No undefined weak" { ! { posix_memalign } } } */ |
| 2 |
/* { dg-additional-options "--param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */ |
| 3 |
|
| 4 |
#define SIZE 1023 |
| 5 |
#define ALIGN 64 |
| 6 |
|
| 7 |
extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size); |
| 8 |
extern void free (void *); |
| 9 |
|
| 10 |
void __attribute__((noinline)) |
| 11 |
test_citer (int * __restrict__ a, |
| 12 |
int * __restrict__ b, |
| 13 |
int * __restrict__ c) |
| 14 |
{ |
| 15 |
int i; |
| 16 |
|
| 17 |
a = (int *)__builtin_assume_aligned (a, ALIGN); |
| 18 |
b = (int *)__builtin_assume_aligned (b, ALIGN); |
| 19 |
c = (int *)__builtin_assume_aligned (c, ALIGN); |
| 20 |
|
| 21 |
for (i = 0; i < SIZE; i++) |
| 22 |
c[i] = a[i] + b[i]; |
| 23 |
} |
| 24 |
|
| 25 |
void __attribute__((noinline)) |
| 26 |
test_viter (int * __restrict__ a, |
| 27 |
int * __restrict__ b, |
| 28 |
int * __restrict__ c, |
| 29 |
int size) |
| 30 |
{ |
| 31 |
int i; |
| 32 |
|
| 33 |
a = (int *)__builtin_assume_aligned (a, ALIGN); |
| 34 |
b = (int *)__builtin_assume_aligned (b, ALIGN); |
| 35 |
c = (int *)__builtin_assume_aligned (c, ALIGN); |
| 36 |
|
| 37 |
for (i = 0; i < size; i++) |
| 38 |
c[i] = a[i] + b[i]; |
| 39 |
} |
| 40 |
|
| 41 |
void __attribute__((noinline)) |
| 42 |
init_data (int * __restrict__ a, |
| 43 |
int * __restrict__ b, |
| 44 |
int * __restrict__ c, |
| 45 |
int size) |
| 46 |
{ |
| 47 |
for (int i = 0; i < size; i++) |
| 48 |
{ |
| 49 |
a[i] = i; |
| 50 |
b[i] = -i; |
| 51 |
c[i] = 0; |
| 52 |
asm volatile("": : :"memory"); |
| 53 |
} |
| 54 |
a[size] = b[size] = c[size] = size; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
void __attribute__((noinline)) |
| 59 |
run_test () |
| 60 |
{ |
| 61 |
int *a; |
| 62 |
int *b; |
| 63 |
int *c; |
| 64 |
int i; |
| 65 |
|
| 66 |
if (posix_memalign ((void **)&a, ALIGN, (SIZE + 1) * sizeof (int)) != 0) |
| 67 |
return; |
| 68 |
if (posix_memalign ((void **)&b, ALIGN, (SIZE + 1) * sizeof (int)) != 0) |
| 69 |
return; |
| 70 |
if (posix_memalign ((void **)&c, ALIGN, (SIZE + 1) * sizeof (int)) != 0) |
| 71 |
return; |
| 72 |
|
| 73 |
init_data (a, b, c, SIZE); |
| 74 |
test_citer (a, b, c); |
| 75 |
#pragma GCC novector |
| 76 |
for (i = 0; i < SIZE; i++) |
| 77 |
if (c[i] != a[i] + b[i]) |
| 78 |
__builtin_abort (); |
| 79 |
if (a[SIZE] != SIZE || b[SIZE] != SIZE || c[SIZE] != SIZE) |
| 80 |
__builtin_abort (); |
| 81 |
|
| 82 |
init_data (a, b, c, SIZE); |
| 83 |
test_viter (a, b, c, SIZE); |
| 84 |
#pragma GCC novector |
| 85 |
for (i = 0; i < SIZE; i++) |
| 86 |
if (c[i] != a[i] + b[i]) |
| 87 |
__builtin_abort (); |
| 88 |
if (a[SIZE] != SIZE || b[SIZE] != SIZE || c[SIZE] != SIZE) |
| 89 |
__builtin_abort (); |
| 90 |
|
| 91 |
free (a); |
| 92 |
free (b); |
| 93 |
free (c); |
| 94 |
} |
| 95 |
|
| 96 |
int |
| 97 |
main (int argc, const char **argv) |
| 98 |
{ |
| 99 |
run_test (); |
| 100 |
return 0; |
| 101 |
} |
| 102 |
|
| 103 |
/* { dg-final { scan-tree-dump-times "LOOP VECTORIZED" 2 "vect" { target avx2_runtime } } } */ |
| 104 |
/* { dg-final { scan-tree-dump-times "LOOP EPILOGUE VECTORIZED \\(MODE=V16QI\\)" 2 "vect" { target avx2_runtime } } } */ |