https://gcc.gnu.org/g:ac2ae1888c6a35711c886eb3c75ac63b915de76c
commit r17-5799-gac2ae1888c6a35711c886eb3c75ac63b915de76c Author: Hu, Lin1 <[email protected]> Date: Wed Oct 28 09:56:52 2026 +0800 i386: Don't use xmm16-xmm31 for vpextrw/vpinsrw without AVX512BW Some word move and extract alternatives use "v", allowing xmm16-xmm31 without AVX512BW. This can produce EVEX vpextrw or vpinsrw instructions, which require AVX512BW. Use "YW" for the affected alternatives, and require AVX512BW for *vec_extract<mode>_0. gcc/ChangeLog: * config/i386/i386.md (*movhi_internal): Use YW instead of v for the vpinsrw and vpextrw alternatives. (*mov<mode>_internal): Likewise for HFBF. * config/i386/sse.md (*vec_extract<mode>_0): Require TARGET_AVX512BW. (*vec_extract<mode>): Use YW instead of v for the vpextrw alternatives. gcc/testsuite/ChangeLog: * gcc.target/i386/avx512vl-no-avx512bw-pextrw-1.c: New test. Diff: --- gcc/config/i386/i386.md | 8 ++--- gcc/config/i386/sse.md | 4 +-- .../i386/avx512vl-no-avx512bw-pextrw-1.c | 41 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 15ff3d0902ae..3a52e4845b90 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -3068,9 +3068,9 @@ (define_insn "*movhi_internal" [(set (match_operand:HI 0 "nonimmediate_operand" - "=r,r,r,m ,*k,*k ,r ,m ,*k ,?r,?*v,*Yv,*v,*v,jm,m") + "=r,r,r,m ,*k,*k ,r ,m ,*k ,?r,?*v,*Yv,*v,*YW,jm,m") (match_operand:HI 1 "general_operand" - "r ,n,m,rn,r ,*km,*k,*k,CBC,*v,r ,C ,*v,m ,*x,*v"))] + "r ,n,m,rn,r ,*km,*k,*k,CBC,*v,r ,C ,*v,m ,*x,*YW"))] "!(MEM_P (operands[0]) && MEM_P (operands[1])) && ix86_hardreg_mov_ok (operands[0], operands[1])" { @@ -4594,9 +4594,9 @@ (define_insn "*mov<mode>_internal" [(set (match_operand:HFBF 0 "nonimmediate_operand" - "=?r,?r,?r,?m ,Yv,v,?r,jm,m,?v,v") + "=?r,?r,?r,?m ,Yv,v,?r,jm,m,?v,YW") (match_operand:HFBF 1 "general_operand" - "r ,F ,m ,r<hfbfconstf>,C ,v, v,v ,v,r ,m"))] + "r ,F ,m ,r<hfbfconstf>,C ,v, v,v ,YW,r ,m"))] "!(MEM_P (operands[0]) && MEM_P (operands[1])) && (lra_in_progress || reload_completed diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 6f0b2c5f7160..c1eab141ea60 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -14264,7 +14264,7 @@ (vec_select:<ssescalarmode> (match_operand:VHFBF 1 "nonimmediate_operand" "vm,v,m") (parallel [(const_int 0)])))] - "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))" + "TARGET_AVX512BW && !(MEM_P (operands[0]) && MEM_P (operands[1]))" "#" "&& reload_completed" [(set (match_dup 0) (match_dup 1))] @@ -14273,7 +14273,7 @@ (define_insn "*vec_extract<mode>" [(set (match_operand:HFBF 0 "register_sse4nonimm_operand" "=?r,jm,m,x,Yw") (vec_select:HFBF - (match_operand:<ssevecmode> 1 "register_operand" "v,x,v,0,YW") + (match_operand:<ssevecmode> 1 "register_operand" "YW,x,YW,0,YW") (parallel [(match_operand:SI 2 "const_0_to_7_operand")])))] "TARGET_SSE2" diff --git a/gcc/testsuite/gcc.target/i386/avx512vl-no-avx512bw-pextrw-1.c b/gcc/testsuite/gcc.target/i386/avx512vl-no-avx512bw-pextrw-1.c new file mode 100644 index 000000000000..c2fb79766b87 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512vl-no-avx512bw-pextrw-1.c @@ -0,0 +1,41 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O2 -mavx512f -mavx512vl -mno-avx512bw" } */ + +/* vpextrw and vpinsrw require AVX512BW to access xmm16-xmm31. */ + +typedef __bf16 v8bf __attribute__ ((vector_size (16))); +typedef _Float16 v8hf __attribute__ ((vector_size (16))); + +void +f1 (v8bf v, __bf16 *p) +{ + register v8bf x __asm__ ("xmm17") = v; + __asm__ volatile ("" : "+v" (x)); + *p = x[1]; +} + +void +f2 (v8bf v, __bf16 *p) +{ + register v8bf x __asm__ ("xmm17") = v; + __asm__ volatile ("" : "+v" (x)); + *p = x[0]; +} + +void +f3 (v8hf v, _Float16 *p) +{ + register v8hf x __asm__ ("xmm17") = v; + __asm__ volatile ("" : "+v" (x)); + *p = x[3]; +} + +void +f4 (__bf16 *p) +{ + register __bf16 x __asm__ ("xmm17") = *p; + __asm__ volatile ("" : "+v" (x)); + *p = x; +} + +/* { dg-final { scan-assembler-not "vp(?:extr|insr)w\[^\n\]*%xmm(?:1\[6-9\]|2\[0-9\]|3\[01\])" } } */
