public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work054)] PR 99293: Optimize splat of vec_extract for V2DI/V2DF.
@ 2021-06-04 22:59 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2021-06-04 22:59 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:144b6ce4d7db5ff457881c27940981f7abfd8973

commit 144b6ce4d7db5ff457881c27940981f7abfd8973
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Jun 4 18:58:43 2021 -0400

    PR 99293: Optimize splat of vec_extract for V2DI/V2DF.
    
    We had optimizations for splat of a vector extract for the other vector
    types, but we missed having one for V2DI and V2DF.  This patch adds a
    combiner insn to do this optimization.
    
    gcc/
    2021-06-03  Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/99293
            * config/rs6000/vsx.md (vsx_splat_extract_<mode): New insn.
    
    gcc/testsuite/
    2021-06-03  Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/99293
            * gcc.target/powerpc/pr99293.c: New test.

Diff:
---
 gcc/config/rs6000/vsx.md                   | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/powerpc/pr99293.c | 20 ++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md
index b49d5b44573..ecad45a43d1 100644
--- a/gcc/config/rs6000/vsx.md
+++ b/gcc/config/rs6000/vsx.md
@@ -5020,6 +5020,24 @@
   "lxvdsx %x0,%y1"
   [(set_attr "type" "vecload")])
 
+;; Optimize SPLAT of an extract from a V2DF/V2DI vector with a constant element
+(define_insn "*vsx_splat_extract_<mode>"
+  [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
+	(vec_duplicate:VSX_D
+	 (vec_select:<VS_scalar>
+	  (match_operand:VSX_D 1 "vsx_register_operand" "wa")
+	  (parallel [(match_operand 2 "const_0_to_1_operand" "n")]))))]
+  "VECTOR_MEM_VSX_P (<MODE>mode)"
+{
+  int which_word = INTVAL (operands[2]);
+  if (!BYTES_BIG_ENDIAN)
+    which_word = 1 - which_word;
+
+  operands[3] = GEN_INT (which_word ? 3 : 0);
+  return "xxpermdi %x0,%x1,%x1,%3";
+}
+  [(set_attr "type" "vecperm")])
+
 ;; V4SI splat support
 (define_insn "vsx_splat_v4si"
   [(set (match_operand:V4SI 0 "vsx_register_operand" "=we,we")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr99293.c b/gcc/testsuite/gcc.target/powerpc/pr99293.c
new file mode 100644
index 00000000000..7e2ba6aef10
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr99293.c
@@ -0,0 +1,20 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-mvsx" } */
+
+/* Test for PR 99263, which wants to do:
+	__builtin_vec_splats (__builtin_vec_extract (v, n))
+
+   where v is a V2DF or V2DI vector and n is either 0 or 1.  */
+
+vector long long splat_dup_l_0 (vector long long v)
+{
+  return __builtin_vec_splats (__builtin_vec_extract (v, 0));
+}
+
+vector long long splat_dup_l_1 (vector long long v)
+{
+  return __builtin_vec_splats (__builtin_vec_extract (v, 1));
+}
+
+/* { dg-final { scan-assembler-times "xxpermdi" 2 } } */


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

* [gcc(refs/users/meissner/heads/work054)] PR 99293: Optimize splat of vec_extract for V2DI/V2DF.
@ 2021-06-05  0:19 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2021-06-05  0:19 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4c0bcf0b4ab14dc93416ec6e0ac6abfdd79f790c

commit 4c0bcf0b4ab14dc93416ec6e0ac6abfdd79f790c
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Jun 4 20:19:18 2021 -0400

    PR 99293: Optimize splat of vec_extract for V2DI/V2DF.
    
    We had optimizations for splat of a vector extract for the other vector
    types, but we missed having one for V2DI and V2DF.  This patch adds a
    combiner insn to do this optimization.
    
    gcc/
    2021-06-04  Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/99293
            * config/rs6000/vsx.md (vsx_splat_extract_<mode): New insn.
    
    gcc/testsuite/
    2021-06-04  Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/99293
            * gcc.target/powerpc/pr99293.c: New test.

Diff:
---
 gcc/config/rs6000/vsx.md                   | 18 ++++++++++++++++++
 gcc/testsuite/gcc.target/powerpc/pr99293.c | 22 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md
index b49d5b44573..ecad45a43d1 100644
--- a/gcc/config/rs6000/vsx.md
+++ b/gcc/config/rs6000/vsx.md
@@ -5020,6 +5020,24 @@
   "lxvdsx %x0,%y1"
   [(set_attr "type" "vecload")])
 
+;; Optimize SPLAT of an extract from a V2DF/V2DI vector with a constant element
+(define_insn "*vsx_splat_extract_<mode>"
+  [(set (match_operand:VSX_D 0 "vsx_register_operand" "=wa")
+	(vec_duplicate:VSX_D
+	 (vec_select:<VS_scalar>
+	  (match_operand:VSX_D 1 "vsx_register_operand" "wa")
+	  (parallel [(match_operand 2 "const_0_to_1_operand" "n")]))))]
+  "VECTOR_MEM_VSX_P (<MODE>mode)"
+{
+  int which_word = INTVAL (operands[2]);
+  if (!BYTES_BIG_ENDIAN)
+    which_word = 1 - which_word;
+
+  operands[3] = GEN_INT (which_word ? 3 : 0);
+  return "xxpermdi %x0,%x1,%x1,%3";
+}
+  [(set_attr "type" "vecperm")])
+
 ;; V4SI splat support
 (define_insn "vsx_splat_v4si"
   [(set (match_operand:V4SI 0 "vsx_register_operand" "=we,we")
diff --git a/gcc/testsuite/gcc.target/powerpc/pr99293.c b/gcc/testsuite/gcc.target/powerpc/pr99293.c
new file mode 100644
index 00000000000..20adc1f27f6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr99293.c
@@ -0,0 +1,22 @@
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+/* { dg-options "-O2 -mvsx" } */
+
+/* Test for PR 99263, which wants to do:
+	__builtin_vec_splats (__builtin_vec_extract (v, n))
+
+   where v is a V2DF or V2DI vector and n is either 0 or 1.  Previously the
+   compiler would do a direct move to the GPR registers to select the item and a
+   direct move from the GPR registers to do the splat.  */
+
+vector long long splat_dup_l_0 (vector long long v)
+{
+  return __builtin_vec_splats (__builtin_vec_extract (v, 0));
+}
+
+vector long long splat_dup_l_1 (vector long long v)
+{
+  return __builtin_vec_splats (__builtin_vec_extract (v, 1));
+}
+
+/* { dg-final { scan-assembler-times "xxpermdi" 2 } } */


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

end of thread, other threads:[~2021-06-05  0:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04 22:59 [gcc(refs/users/meissner/heads/work054)] PR 99293: Optimize splat of vec_extract for V2DI/V2DF Michael Meissner
2021-06-05  0:19 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).