diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 42a73d65fb1..407d652fa99 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -20701,7 +20701,7 @@ avx_vpermilp_parallel (rtx par, machine_mode mode) } for (i = 2; i < 4; ++i) { - if (ipar[i] < 2) + if (ipar[i] < 2 || ipar[i] >= 4) return 0; mask |= (ipar[i] - 2) << i; } diff --git a/gcc/testsuite/gcc.dg/pr124138.c b/gcc/testsuite/gcc.dg/pr124138.c new file mode 100644 index 00000000000..9dc78dca6c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr124138.c @@ -0,0 +1,20 @@ +/* PR target/124138 */ +/* { dg-do run } */ +/* { dg-options "-Wno-psabi" } */ + +typedef __attribute__((__vector_size__ (8 * sizeof (unsigned long long)))) unsigned long long V; + +[[gnu::noipa]] V +foo (V x) +{ + return __builtin_shuffle (x, (V) { 0, 1, 2, 5, 4, 5, 6, 7 }); +} + +int +main () +{ + V x = foo ((V) { 1, 2, 3, 4, 5, 6, 7, 8 }); + if (x[0] != 1 || x[1] != 2 || x[2] != 3 || x[3] != 6 + || x[4] != 5 || x[5] != 6 || x[6] != 7 || x[7] != 8) + __builtin_abort (); +} diff --git a/gcc/testsuite/gcc.target/i386/avx512f-pr124138-1.c b/gcc/testsuite/gcc.target/i386/avx512f-pr124138-1.c new file mode 100644 index 00000000000..79efd2bb221 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512f-pr124138-1.c @@ -0,0 +1,24 @@ +/* PR target/124138 */ +/* { dg-do run } */ +/* { dg-options "-mavx512f" } */ +/* { dg-require-effective-target avx512f } */ + +#define AVX512F +#include "avx512f-helper.h" + +typedef __attribute__((__vector_size__ (64))) unsigned long long V; + +[[gnu::noipa]] V +foo (V x) +{ + return __builtin_shuffle (x, (V) { 0, 1, 2, 5, 4, 5, 6, 7 }); +} + +void +TEST () +{ + V x = foo ((V) { 1, 2, 3, 4, 5, 6, 7, 8 }); + if (x[0] != 1 || x[1] != 2 || x[2] != 3 || x[3] != 6 + || x[4] != 5 || x[5] != 6 || x[6] != 7 || x[7] != 8) + __builtin_abort (); +} diff --git a/gcc/testsuite/gcc.target/i386/avx512f-pr124138-2.c b/gcc/testsuite/gcc.target/i386/avx512f-pr124138-2.c new file mode 100644 index 00000000000..893dbd6c477 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512f-pr124138-2.c @@ -0,0 +1,25 @@ +/* PR target/124138 */ +/* { dg-do run } */ +/* { dg-options "-mavx512f" } */ +/* { dg-require-effective-target avx512f } */ + +#define AVX512F +#include "avx512f-helper.h" + +typedef __attribute__((__vector_size__ (64))) unsigned long long V; +typedef __attribute__((__vector_size__ (64))) double W; + +[[gnu::noipa]] W +foo (W x) +{ + return __builtin_shuffle (x, (V) { 0, 1, 2, 5, 4, 5, 6, 7 }); +} + +void +TEST () +{ + W x = foo ((W) { 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 }); + if (x[0] != 1.5 || x[1] != 2.5 || x[2] != 3.5 || x[3] != 6.5 + || x[4] != 5.5 || x[5] != 6.5 || x[6] != 7.5 || x[7] != 8.5) + __builtin_abort (); +}