public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work109)] Improve 64->128 bit zero extension on PowerPC
@ 2023-02-27 22:33 Michael Meissner
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Meissner @ 2023-02-27 22:33 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:970d7331da643850a8a9cb3aae1aafbbbd711e9b

commit 970d7331da643850a8a9cb3aae1aafbbbd711e9b
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Mon Feb 27 17:32:44 2023 -0500

    Improve 64->128 bit zero extension on PowerPC
    
    2023-02-17   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            PR target/108958
            * gcc/config/rs6000.md (zero_extendditi2): New insn.

Diff:
---
 gcc/config/rs6000/rs6000.md | 52 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 81bffb04ceb..4bc0b957ac1 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -986,6 +986,58 @@
    (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,wa")
+	(zero_extend:TI
+	 (match_operand:DI 1 "reg_or_mem_operand" "r,m,b,Z,wa")))
+   (clobber (match_scratch:DI 2 "=&X,X,X,X,wa"))]
+  "TARGET_POWERPC64 && TARGET_P9_VECTOR"
+  "@
+   #
+   #
+   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))]
+{
+  rtx dest = operands[0];
+  rtx src = operands[1];
+
+  /* If we are converting a VSX DImode to VSX TImode, we need to move the upper
+     64-bits (DImode) to the lower 64-bits.  We can't just do a xxpermdi
+     instruction to swap the two 64-bit words, because can't rely on the bottom
+     64-bits of the VSX register being 0.  Instead we create a 0 and do the
+     xxpermdi operation to combine the two registers.  */
+  if (vsx_register_operand (dest, TImode)
+      && vsx_register_operand (src, DImode))
+    {
+      rtx tmp = operands[2];
+      emit_move_insn (tmp, const0_rtx);
+
+      rtx hi = tmp;
+      rtx lo = src;
+      if (!BYTES_BIG_ENDIAN)
+	std::swap (hi, lo);
+
+      rtx dest_v2di = gen_rtx_REG (V2DImode, reg_or_subregno (dest));
+      emit_insn (gen_vsx_concat_v2di (dest_v2di, hi, lo));
+      DONE;
+    }
+
+  /* If we are zero extending to a GPR register either from a GPR register,
+     a VSX register or from memory, do the zero extend operation to the
+     lower DI register, and set the upper DI register to 0.  */
+  operands[2] = gen_lowpart (DImode, dest);
+  operands[3] = gen_highpart (DImode, dest);
+}
+  [(set_attr "type" "*,load,vecexts,vecload,vecperm")
+   (set_attr "isa" "*,*,p9v,p10,*")
+   (set_attr "length" "8,8,*,*,8")])
 
 (define_insn "extendqi<mode>2"
   [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v")

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gcc(refs/users/meissner/heads/work109)] Improve 64->128 bit zero extension on PowerPC
@ 2023-03-02 23:47 Michael Meissner
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Meissner @ 2023-03-02 23:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f67f8175c80c65d7fb44cbf839d8449419501e5a

commit f67f8175c80c65d7fb44cbf839d8449419501e5a
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Mar 2 18:47:29 2023 -0500

    Improve 64->128 bit zero extension on PowerPC
    
    2023-03-02   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            PR target/108958
            * gcc/config/rs6000.md (zero_extendditi2): New insn.
    
    gcc/testsuite/
    
            PR target/108958
            * gcc.target/powerpc/zero-extend-di-ti.c: New test.

Diff:
---
 gcc/config/rs6000/rs6000.md                        | 52 ++++++++++++++++++
 .../gcc.target/powerpc/zero-extend-di-ti.c         | 62 ++++++++++++++++++++++
 2 files changed, 114 insertions(+)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 81bffb04ceb..4bc0b957ac1 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -986,6 +986,58 @@
    (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,wa")
+	(zero_extend:TI
+	 (match_operand:DI 1 "reg_or_mem_operand" "r,m,b,Z,wa")))
+   (clobber (match_scratch:DI 2 "=&X,X,X,X,wa"))]
+  "TARGET_POWERPC64 && TARGET_P9_VECTOR"
+  "@
+   #
+   #
+   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))]
+{
+  rtx dest = operands[0];
+  rtx src = operands[1];
+
+  /* If we are converting a VSX DImode to VSX TImode, we need to move the upper
+     64-bits (DImode) to the lower 64-bits.  We can't just do a xxpermdi
+     instruction to swap the two 64-bit words, because can't rely on the bottom
+     64-bits of the VSX register being 0.  Instead we create a 0 and do the
+     xxpermdi operation to combine the two registers.  */
+  if (vsx_register_operand (dest, TImode)
+      && vsx_register_operand (src, DImode))
+    {
+      rtx tmp = operands[2];
+      emit_move_insn (tmp, const0_rtx);
+
+      rtx hi = tmp;
+      rtx lo = src;
+      if (!BYTES_BIG_ENDIAN)
+	std::swap (hi, lo);
+
+      rtx dest_v2di = gen_rtx_REG (V2DImode, reg_or_subregno (dest));
+      emit_insn (gen_vsx_concat_v2di (dest_v2di, hi, lo));
+      DONE;
+    }
+
+  /* If we are zero extending to a GPR register either from a GPR register,
+     a VSX register or from memory, do the zero extend operation to the
+     lower DI register, and set the upper DI register to 0.  */
+  operands[2] = gen_lowpart (DImode, dest);
+  operands[3] = gen_highpart (DImode, dest);
+}
+  [(set_attr "type" "*,load,vecexts,vecload,vecperm")
+   (set_attr "isa" "*,*,p9v,p10,*")
+   (set_attr "length" "8,8,*,*,8")])
 
 (define_insn "extendqi<mode>2"
   [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v")
diff --git a/gcc/testsuite/gcc.target/powerpc/zero-extend-di-ti.c b/gcc/testsuite/gcc.target/powerpc/zero-extend-di-ti.c
new file mode 100644
index 00000000000..9b3b9c4dbd0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/zero-extend-di-ti.c
@@ -0,0 +1,62 @@
+/* { dg-require-effective-target int128     } */
+/* { dg-require-effective-target power10_ok } */
+/* { dg-options "-mdejagnu-cpu=power10 -O2" } */
+
+/* This patch makes sure the various optimization and code paths are done for
+   zero extending DImode to TImode on power10.  */
+
+__uint128_t
+gpr_to_gpr (unsigned long long a)
+{
+  /* li 4,0.  */
+  return a;
+}
+
+__uint128_t
+mem_to_gpr (unsigned long long *p)
+{
+  /* ld 3,0(3); li 4,0.  */
+  return *p;
+}
+
+__uint128_t
+vsx_to_gpr (__uint128_t *p, double d)
+{
+  /* fctiduz 1,1; li 4,0;mfvsrd 3,1.  */
+  return (unsigned long long)d;
+}
+
+void
+gpr_to_vsx (__uint128_t *p, unsigned long long a)
+{
+  /* mtvsrdd 0,0,4; stxv 0,0(3).  */
+  __uint128_t b = a;
+  __asm__ (" # %x0" : "+wa" (b));
+  *p = b;
+}
+
+void
+mem_to_vsx (__uint128_t *p, unsigned long long *q)
+{
+  /* lxvrdx 0,0,4; stxv 0,0(3).  */
+  __uint128_t a = *q;
+  __asm__ (" # %x0" : "+wa" (a));
+  *p = a;
+}
+
+void
+vsx_to_vsx (__uint128_t *p, double d)
+{
+  /* fctiduz 1,1; xxspltib 0,0; xxpermdi 0,0,1,0; stxv 0,0(3).  */
+  __uint128_t a = (unsigned long long)d;
+  __asm__ (" # %x0" : "+wa" (a));
+  *p = a;
+}
+
+/* { dg-final { scan-assembler-times {\mli\M}       3 } } */
+/* { dg-final { scan-assembler-times {\mld\M}       1 } } */
+/* { dg-final { scan-assembler-times {\mlxvrdx\M}   1 } } */
+/* { dg-final { scan-assembler-times {\mmfvsrd\M}   1 } } */
+/* { dg-final { scan-assembler-times {\mmtvsrdd\M}  1 } } */
+/* { dg-final { scan-assembler-times {\mstxv\M}     3 } } */
+/* { dg-final { scan-assembler-times {\mxxpermdi\M} 1 } } */

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gcc(refs/users/meissner/heads/work109)] Improve 64->128 bit zero extension on PowerPC
@ 2023-02-27 22:46 Michael Meissner
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Meissner @ 2023-02-27 22:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1fcb38e47615d383ccbdf8be639e90bcab694066

commit 1fcb38e47615d383ccbdf8be639e90bcab694066
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Mon Feb 27 17:32:44 2023 -0500

    Improve 64->128 bit zero extension on PowerPC
    
    2023-02-17   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            PR target/108958
            * gcc/config/rs6000.md (zero_extendditi2): New insn.

Diff:
---
 gcc/config/rs6000/rs6000.md | 52 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
index 81bffb04ceb..4bc0b957ac1 100644
--- a/gcc/config/rs6000/rs6000.md
+++ b/gcc/config/rs6000/rs6000.md
@@ -986,6 +986,58 @@
    (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,wa")
+	(zero_extend:TI
+	 (match_operand:DI 1 "reg_or_mem_operand" "r,m,b,Z,wa")))
+   (clobber (match_scratch:DI 2 "=&X,X,X,X,wa"))]
+  "TARGET_POWERPC64 && TARGET_P9_VECTOR"
+  "@
+   #
+   #
+   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))]
+{
+  rtx dest = operands[0];
+  rtx src = operands[1];
+
+  /* If we are converting a VSX DImode to VSX TImode, we need to move the upper
+     64-bits (DImode) to the lower 64-bits.  We can't just do a xxpermdi
+     instruction to swap the two 64-bit words, because can't rely on the bottom
+     64-bits of the VSX register being 0.  Instead we create a 0 and do the
+     xxpermdi operation to combine the two registers.  */
+  if (vsx_register_operand (dest, TImode)
+      && vsx_register_operand (src, DImode))
+    {
+      rtx tmp = operands[2];
+      emit_move_insn (tmp, const0_rtx);
+
+      rtx hi = tmp;
+      rtx lo = src;
+      if (!BYTES_BIG_ENDIAN)
+	std::swap (hi, lo);
+
+      rtx dest_v2di = gen_rtx_REG (V2DImode, reg_or_subregno (dest));
+      emit_insn (gen_vsx_concat_v2di (dest_v2di, hi, lo));
+      DONE;
+    }
+
+  /* If we are zero extending to a GPR register either from a GPR register,
+     a VSX register or from memory, do the zero extend operation to the
+     lower DI register, and set the upper DI register to 0.  */
+  operands[2] = gen_lowpart (DImode, dest);
+  operands[3] = gen_highpart (DImode, dest);
+}
+  [(set_attr "type" "*,load,vecexts,vecload,vecperm")
+   (set_attr "isa" "*,*,p9v,p10,*")
+   (set_attr "length" "8,8,*,*,8")])
 
 (define_insn "extendqi<mode>2"
   [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v")

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-02 23:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 22:33 [gcc(refs/users/meissner/heads/work109)] Improve 64->128 bit zero extension on PowerPC Michael Meissner
2023-02-27 22:46 Michael Meissner
2023-03-02 23:47 Michael Meissner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).