https://gcc.gnu.org/g:83e485e74b736938063a8b9edc95255f78d633cc
commit 83e485e74b736938063a8b9edc95255f78d633cc Author: Michael Meissner <meiss...@linux.ibm.com> Date: Sun Nov 17 19:11:17 2024 -0500 PR target/108958 -- use mtvsrdd to zero extend GPR DImode to VSX TImode Previously GCC would zero externd a DImode GPR value to TImode by first zero extending the DImode value into a GPR TImode value, and then do a MTVSRDD to move this value to a VSX register. This patch does the move directly, since if the middle argument to MTVSRDD is 0, it does the zero extend. This patch also generates LXVRDX if the DImode value is in memory. Finally, it the DImode is already in a vector register, it does a XXSPLTIB and XXPERMDI to get the value into the bottom 64-bits of the register. I have built GCC with the patches in this patch set applied on both little and big endian PowerPC systems and there were no regressions. Can I apply this patch to GCC 15? 2024-11-17 Michael Meissner <meiss...@linux.ibm.com> gcc/ * gcc/config/rs6000/rs6000.md (zero_extendditi2): New insn. gcc/testsuite/ * gcc.target/powerpc/pr108958.c: New test. Diff: --- gcc/config/rs6000/rs6000.md | 25 +++++++++++++++ gcc/testsuite/gcc.target/powerpc/pr108958.c | 47 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index d266f93ff2e4..ccd98676d878 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -1026,6 +1026,31 @@ (set_attr "dot" "yes") (set_attr "length" "4,8")]) +(define_insn_and_split "zero_extendditi2" + [(set (match_operand:TI 0 "gpc_reg_operand" "=r,r,wa,wa") + (zero_extend:TI + (match_operand:DI 1 "reg_or_mem_operand" "r,m,r,Z")))] + "TARGET_DIRECT_MOVE_64BIT" + "@ + # + # + mtvsrdd %x0,0,%1 + lxvrdx %x0,%y1" + "&& reload_completed + && (int_reg_operand (operands[0], TImode) + || (vsx_register_operand (operands[0], TImode) + && vsx_register_operand (operands[1], DImode)))" + [(set (match_dup 2) + (match_dup 1)) + (set (match_dup 3) + (const_int 0))] +{ + operands[2] = gen_lowpart (DImode, operands[0]); + operands[3] = gen_highpart (DImode, operands[0]); +} + [(set_attr "type" "*,load,mtvsr,vecload") + (set_attr "length" "8,8,*,*") + (set_attr "isa" "*,*,*,p10")]) (define_insn "extendqi<mode>2" [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v") diff --git a/gcc/testsuite/gcc.target/powerpc/pr108958.c b/gcc/testsuite/gcc.target/powerpc/pr108958.c new file mode 100644 index 000000000000..aa79dc880c8e --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr108958.c @@ -0,0 +1,47 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target int128 } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-require-effective-target power10_ok } */ +/* { dg-options "-mdejagnu-cpu=power10 -O2" } */ + +/* PR target/108958, use mtvsrdd to zero extend gpr to vsx register. */ + +void +arg_to_vsx (unsigned long long x, __uint128_t *p) +{ + /* mtvsrdd vsx,0,gpr. */ + __uint128_t y = x; + __asm__ (" # %x0" : "+wa" (y)); + *p = y; +} + +void +mem_to_vsx (unsigned long long *p, __uint128_t *q) +{ + /* lxrdx vsx,0,ptr. */ + __uint128_t y = *p; + __asm__ (" # %x0" : "+wa" (y)); + *q = y; +} + + +void +arg_to_gpr (unsigned long long x, __uint128_t *p) +{ + /* mr gpr1_lo,gpr2; li gpr1_hi,0. */ + __uint128_t y = x; + __asm__ (" # %0" : "+r" (y)); + *p = y; +} + +void +mem_to_gpr (unsigned long long *p, __uint128_t *q) +{ + /* ld gpr1_lo,addr; li gpr1_hi,0. */ + __uint128_t y = *p; + __asm__ (" # %0" : "+r" (y)); + *q = y; +} + +/* { dg-final { scan-assembler-times {\mmtvsrdd .*,0,.*\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mlxvrdx\M} 1 } } */