*vec_extract<mode><ssescalarmodelower>_valign requires only AVX512F,
but can select forms that require AVX512VL or AVX512DQ. Use the 512-bit
source form without AVX512VL and the 32x4 forms without AVX512DQ. An
unmasked extract returns the same 128-bit lane.
gcc/ChangeLog:
* config/i386/sse.md (*vec_extract<mode><ssescalarmodelower>_valign):
Use the 256-bit source form only with TARGET_AVX512VL and the 64x2
forms only with TARGET_AVX512DQ.
gcc/testsuite/ChangeLog:
* gcc.target/i386/avx512f-vec-extract-novl-1.c: New test.
* gcc.target/i386/avx512f-vec-extract-novl-2.c: Ditto.
---
gcc/config/i386/sse.md | 14 ++++++++++----
.../i386/avx512f-vec-extract-novl-1.c | 17 +++++++++++++++++
.../i386/avx512f-vec-extract-novl-2.c | 16 ++++++++++++++++
3 files changed, 43 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-1.c
create mode 100644 gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-2.c
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 1456c92e498..c61704464d9 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -15085,10 +15085,16 @@ (define_insn
"*vec_extract<mode><ssescalarmodelower>_valign"
if (byte_offset % 16 == 0)
{
operands[2] = GEN_INT (byte_offset / 16);
- if (byte_offset / 16 == 1)
- return "vextract<shuffletype><extract_suf>\t{%2, %t1, %x0|%x0, %t1,
%2}";
- else
- return "vextract<shuffletype><extract_suf>\t{%2, %1, %x0|%x0, %1, %2}";
+ /* The 256-bit source form needs AVX512VL and the 64x2 forms need
+ AVX512DQ. An unmasked 32x4 extract gives the same result. */
+ bool ymm_p = (byte_offset / 16 == 1) && TARGET_AVX512VL;
+ if (GET_MODE_UNIT_SIZE (<MODE>mode) == 8 && !TARGET_AVX512DQ)
+ return (ymm_p
+ ? "vextract<shuffletype>32x4\t{%2, %t1, %x0|%x0, %t1, %2}"
+ : "vextract<shuffletype>32x4\t{%2, %1, %x0|%x0, %1, %2}");
+ return (ymm_p
+ ? "vextract<shuffletype><extract_suf>\t{%2, %t1, %x0|%x0, %t1,
%2}"
+ : "vextract<shuffletype><extract_suf>\t{%2, %1, %x0|%x0, %1,
%2}");
}
else
return "valign<ternlogsuffix>\t{%2, %1, %1, %<xtg_mode>0|%<xtg_mode>0, %1,
%1, %2}";
diff --git a/gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-1.c
b/gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-1.c
new file mode 100644
index 00000000000..1fd3d102209
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-1.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f -mno-avx512vl -mno-avx512dq" } */
+
+typedef int v16si __attribute__ ((vector_size (64)));
+typedef float v16sf __attribute__ ((vector_size (64)));
+typedef long long v8di __attribute__ ((vector_size (64)));
+typedef double v8df __attribute__ ((vector_size (64)));
+
+int f1 (v16si v) { return v[4]; }
+float f2 (v16sf v) { return v[4]; }
+long long f3 (v8di v) { return v[2]; }
+double f4 (v8df v) { return v[2]; }
+
+/* EVEX vextract needs AVX512VL for YMM sources and AVX512DQ for 64x2. */
+/* { dg-final { scan-assembler-not "vextract\[^\n\]*%ymm" } } */
+/* { dg-final { scan-assembler-not "vextract\[if\]64x2" } } */
+/* { dg-final { scan-assembler-times "vextract\[if\]32x4\[\t \]+\\\$1, %zmm" 4
} } */
diff --git a/gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-2.c
b/gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-2.c
new file mode 100644
index 00000000000..2573830bdcb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx512f-vec-extract-novl-2.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f -mavx512dq -mno-avx512vl" } */
+
+typedef int v16si __attribute__ ((vector_size (64)));
+typedef float v16sf __attribute__ ((vector_size (64)));
+typedef long long v8di __attribute__ ((vector_size (64)));
+typedef double v8df __attribute__ ((vector_size (64)));
+
+int f1 (v16si v) { return v[4]; }
+float f2 (v16sf v) { return v[4]; }
+long long f3 (v8di v) { return v[2]; }
+double f4 (v8df v) { return v[2]; }
+
+/* { dg-final { scan-assembler-not "vextract\[^\n\]*%ymm" } } */
+/* { dg-final { scan-assembler-times "vextract\[if\]32x4\[\t \]+\\\$1, %zmm" 2
} } */
+/* { dg-final { scan-assembler-times "vextract\[if\]64x2\[\t \]+\\\$1, %zmm" 2
} } */
--
2.31.1