diff --git a/gcc/testsuite/gcc.dg/vect/vect-cond-11.c b/gcc/testsuite/gcc.dg/vect/vect-cond-11.c new file mode 100644 index 00000000000..0301c890979 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-cond-11.c @@ -0,0 +1,116 @@ +#include "tree-vect.h" + +#define N 1024 +typedef int V __attribute__((vector_size (4))); +unsigned int a[N * 2] __attribute__((aligned)); +unsigned int b[N * 2] __attribute__((aligned)); +V c[N]; + +__attribute__((noinline, noclone)) unsigned int +foo (unsigned int *a, unsigned int *b) +{ + int i; + unsigned int r = 0; + for (i = 0; i < N; i++) + { + unsigned int x = a[i], y = b[i]; + if (x < 32) + { + x = x + 127; + y = y * 2; + } + else + { + x = x - 16; + y = y + 1; + } + a[i] = x; + b[i] = y; + r += x; + } + return r; +} + +__attribute__((noinline, noclone)) unsigned int +bar (unsigned int *a, unsigned int *b) +{ + int i; + unsigned int r = 0; + for (i = 0; i < N; i++) + { + unsigned int x = a[i], y = b[i]; + if (x < 32) + { + x = x + 127; + y = y * 2; + } + else + { + x = x - 16; + y = y + 1; + } + a[i] = x; + b[i] = y; + c[i] = c[i] + 1; + r += x; + } + return r; +} + +void +baz (unsigned int *a, unsigned int *b, + unsigned int (*fn) (unsigned int *, unsigned int *)) +{ + int i; + for (i = -64; i < 0; i++) + { + a[i] = 19; + b[i] = 17; + } + for (; i < N; i++) + { + a[i] = i - 512; + b[i] = i; + } + for (; i < N + 64; i++) + { + a[i] = 27; + b[i] = 19; + } + if (fn (a, b) != -512U - (N - 32) * 16U + 32 * 127U) + __builtin_abort (); + for (i = -64; i < 0; i++) + if (a[i] != 19 || b[i] != 17) + __builtin_abort (); + for (; i < N; i++) + if (a[i] != (i - 512U < 32U ? i - 512U + 127 : i - 512U - 16) + || b[i] != (i - 512U < 32U ? i * 2U : i + 1U)) + __builtin_abort (); + for (; i < N + 64; i++) + if (a[i] != 27 || b[i] != 19) + __builtin_abort (); +} + +int +main () +{ + int i; + check_vect (); + baz (a + 512, b + 512, foo); + baz (a + 512, b + 512, bar); + baz (a + 512 + 1, b + 512 + 1, foo); + baz (a + 512 + 1, b + 512 + 1, bar); + baz (a + 512 + 31, b + 512 + 31, foo); + baz (a + 512 + 31, b + 512 + 31, bar); + baz (a + 512 + 1, b + 512, foo); + baz (a + 512 + 1, b + 512, bar); + baz (a + 512 + 31, b + 512, foo); + baz (a + 512 + 31, b + 512, bar); + baz (a + 512, b + 512 + 1, foo); + baz (a + 512, b + 512 + 1, bar); + baz (a + 512, b + 512 + 31, foo); + baz (a + 512, b + 512 + 31, bar); + return 0; +} + +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-mask-load-1.c b/gcc/testsuite/gcc.dg/vect/vect-mask-load-1.c new file mode 100644 index 00000000000..2c30830bee2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-mask-load-1.c @@ -0,0 +1,52 @@ +/* { dg-do run } */ +/* { dg-additional-options "-Ofast -fno-common" } */ +/* { dg-additional-options "-Ofast -fno-common -mavx" { target avx_runtime } } */ + +#include +#include "tree-vect.h" + +__attribute__((noinline, noclone)) void +foo (double *x, double *y) +{ + double *p = __builtin_assume_aligned (x, 16); + double *q = __builtin_assume_aligned (y, 16); + double z, h; + int i; + for (i = 0; i < 1024; i++) + { + if (p[i] < 0.0) + z = q[i], h = q[i] * 7.0 + 3.0; + else + z = p[i] + 6.0, h = p[1024 + i]; + p[i] = z + 2.0 * h; + } +} + +double a[2048] __attribute__((aligned (16))); +double b[1024] __attribute__((aligned (16))); + +int +main () +{ + int i; + check_vect (); + for (i = 0; i < 1024; i++) + { + a[i] = (i & 1) ? -i : 2 * i; + a[i + 1024] = i; + b[i] = 7 * i; + asm (""); + } + foo (a, b); + for (i = 0; i < 1024; i++) + if (a[i] != ((i & 1) + ? 7 * i + 2.0 * (7 * i * 7.0 + 3.0) + : 2 * i + 6.0 + 2.0 * i) + || b[i] != 7 * i + || a[i + 1024] != i) + abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "note: vectorized 1 loops" 1 "vect" { target avx_runtime } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-mask-loadstore-1.c b/gcc/testsuite/gcc.dg/vect/vect-mask-loadstore-1.c new file mode 100644 index 00000000000..ecc164fe1ff --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-mask-loadstore-1.c @@ -0,0 +1,50 @@ +/* { dg-do run } */ +/* { dg-additional-options "-Ofast -fno-common" } */ +/* { dg-additional-options "-Ofast -fno-common -mavx" { target avx_runtime } } */ + +#include +#include "tree-vect.h" + +__attribute__((noinline, noclone)) void +foo (float *__restrict x, float *__restrict y, float *__restrict z) +{ + float *__restrict p = __builtin_assume_aligned (x, 32); + float *__restrict q = __builtin_assume_aligned (y, 32); + float *__restrict r = __builtin_assume_aligned (z, 32); + int i; + for (i = 0; i < 1024; i++) + { + if (p[i] < 0.0f) + q[i] = p[i] + 2.0f; + else + p[i] = r[i] + 3.0f; + } +} + +float a[1024] __attribute__((aligned (32))); +float b[1024] __attribute__((aligned (32))); +float c[1024] __attribute__((aligned (32))); + +int +main () +{ + int i; + check_vect (); + for (i = 0; i < 1024; i++) + { + a[i] = (i & 1) ? -i : i; + b[i] = 7 * i; + c[i] = a[i] - 3.0f; + asm (""); + } + foo (a, b, c); + for (i = 0; i < 1024; i++) + if (a[i] != ((i & 1) ? -i : i) + || b[i] != ((i & 1) ? a[i] + 2.0f : 7 * i) + || c[i] != a[i] - 3.0f) + abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "note: vectorized 1 loops" 1 "vect" { target avx_runtime } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.target/i386/avx2-gather-5.c b/gcc/testsuite/gcc.target/i386/avx2-gather-5.c new file mode 100644 index 00000000000..892a20034e1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx2-gather-5.c @@ -0,0 +1,47 @@ +/* { dg-do run } */ +/* { dg-require-effective-target avx2 } */ +/* { dg-options "-O3 -mavx2 -fno-common" } */ + +#include "avx2-check.h" + +#define N 1024 +float vf1[N+16], vf2[N], vf3[N]; +int k[N]; + +__attribute__((noinline, noclone)) void +foo (void) +{ + int i; + for (i = 0; i < N; i++) + { + float f; + if (vf3[i] < 0.0f) + f = vf1[k[i]]; + else + f = 7.0f; + vf2[i] = f; + } +} + +static void +avx2_test (void) +{ + int i; + for (i = 0; i < N + 16; i++) + { + vf1[i] = 5.5f * i; + if (i >= N) + continue; + vf2[i] = 2.0f; + vf3[i] = (i & 1) ? i : -i - 1; + k[i] = (i & 1) ? ((i & 2) ? -i : N / 2 + i) : (i * 7) % N; + asm (""); + } + foo (); + for (i = 0; i < N; i++) + if (vf1[i] != 5.5 * i + || vf2[i] != ((i & 1) ? 7.0f : 5.5f * ((i * 7) % N)) + || vf3[i] != ((i & 1) ? i : -i - 1) + || k[i] != ((i & 1) ? ((i & 2) ? -i : N / 2 + i) : ((i * 7) % N))) + abort (); +} diff --git a/gcc/testsuite/gcc.target/i386/avx2-gather-6.c b/gcc/testsuite/gcc.target/i386/avx2-gather-6.c new file mode 100644 index 00000000000..38e2009da73 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx2-gather-6.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -mavx2 -fno-common -fdump-tree-vect-details" } */ + +#include "avx2-gather-5.c" + +/* { dg-final { scan-tree-dump-times "note: vectorized 1 loops in function" 1 "vect" } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ diff --git a/gcc/testsuite/gcc.target/i386/vect-cond-1.c b/gcc/testsuite/gcc.target/i386/vect-cond-1.c new file mode 100644 index 00000000000..12ae771038e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/vect-cond-1.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -mavx2" { target avx2 } } */ + +int a[1024]; + +int +foo (int *p) +{ + int i; + for (i = 0; i < 1024; i++) + { + int t; + if (a[i] < 30) + t = *p; + else + t = a[i] + 12; + a[i] = t; + } +} + +/* { dg-final { cleanup-tree-dump "vect" } } */