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