2018-01-16 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / vect / vect-tail-nomask-1.c
blob2c3a3c95eb0caab8a277be356667eeb0fd1edbc2
1 /* { dg-do run } */
2 /* { dg-require-weak "" } */
3 /* { dg-skip-if "No undefined weak" { hppa*-*-hpux* && { ! lp64 } } } */
4 /* { dg-skip-if "No undefined weak" { nvptx-*-* } } */
5 /* { dg-additional-options "-Wl,-undefined,dynamic_lookup" { target *-*-darwin* } } */
6 /* { dg-additional-options "-Wl,-flat_namespace" { target *-*-darwin[89]* } } */
7 /* { dg-additional-options "--param vect-epilogues-nomask=1 -mavx2" { target avx2_runtime } } */
9 #define SIZE 1023
10 #define ALIGN 64
12 extern int posix_memalign(void **memptr, __SIZE_TYPE__ alignment, __SIZE_TYPE__ size) __attribute__((weak));
13 extern void free (void *);
15 void __attribute__((noinline))
16 test_citer (int * __restrict__ a,
17 int * __restrict__ b,
18 int * __restrict__ c)
20 int i;
22 a = (int *)__builtin_assume_aligned (a, ALIGN);
23 b = (int *)__builtin_assume_aligned (b, ALIGN);
24 c = (int *)__builtin_assume_aligned (c, ALIGN);
26 for (i = 0; i < SIZE; i++)
27 c[i] = a[i] + b[i];
30 void __attribute__((noinline))
31 test_viter (int * __restrict__ a,
32 int * __restrict__ b,
33 int * __restrict__ c,
34 int size)
36 int i;
38 a = (int *)__builtin_assume_aligned (a, ALIGN);
39 b = (int *)__builtin_assume_aligned (b, ALIGN);
40 c = (int *)__builtin_assume_aligned (c, ALIGN);
42 for (i = 0; i < size; i++)
43 c[i] = a[i] + b[i];
46 void __attribute__((noinline))
47 init_data (int * __restrict__ a,
48 int * __restrict__ b,
49 int * __restrict__ c,
50 int size)
52 for (int i = 0; i < size; i++)
54 a[i] = i;
55 b[i] = -i;
56 c[i] = 0;
57 asm volatile("": : :"memory");
59 a[size] = b[size] = c[size] = size;
63 void __attribute__((noinline))
64 run_test ()
66 int *a;
67 int *b;
68 int *c;
69 int i;
71 if (posix_memalign ((void **)&a, ALIGN, (SIZE + 1) * sizeof (int)) != 0)
72 return;
73 if (posix_memalign ((void **)&b, ALIGN, (SIZE + 1) * sizeof (int)) != 0)
74 return;
75 if (posix_memalign ((void **)&c, ALIGN, (SIZE + 1) * sizeof (int)) != 0)
76 return;
78 init_data (a, b, c, SIZE);
79 test_citer (a, b, c);
80 for (i = 0; i < SIZE; i++)
81 if (c[i] != a[i] + b[i])
82 __builtin_abort ();
83 if (a[SIZE] != SIZE || b[SIZE] != SIZE || c[SIZE] != SIZE)
84 __builtin_abort ();
86 init_data (a, b, c, SIZE);
87 test_viter (a, b, c, SIZE);
88 for (i = 0; i < SIZE; i++)
89 if (c[i] != a[i] + b[i])
90 __builtin_abort ();
91 if (a[SIZE] != SIZE || b[SIZE] != SIZE || c[SIZE] != SIZE)
92 __builtin_abort ();
94 free (a);
95 free (b);
96 free (c);
99 int
100 main (int argc, const char **argv)
102 if (!posix_memalign)
103 return 0;
105 run_test ();
106 return 0;
109 /* { dg-final { scan-tree-dump-times "LOOP VECTORIZED" 2 "vect" { target avx2_runtime } } } */
110 /* { dg-final { scan-tree-dump-times "LOOP EPILOGUE VECTORIZED \\(VS=16\\)" 2 "vect" { target avx2_runtime } } } */