public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Michael Meissner <meissner@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/meissner/heads/work119)] Enhance vec_extract from int memory with constant element numbers.
Date: Tue, 18 Apr 2023 05:40:03 +0000 (GMT)	[thread overview]
Message-ID: <20230418054003.DB4C13858D28@sourceware.org> (raw)

https://gcc.gnu.org/g:99bd3be639dee32eaed78afc4dbb069263d20ea4

commit 99bd3be639dee32eaed78afc4dbb069263d20ea4
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Tue Apr 18 01:39:39 2023 -0400

    Enhance vec_extract from int memory with constant element numbers.
    
    This patch adds a combine insn that merges loading up a vec_extract of V4SFmode
    where the element number is constant combined with a conversion to DFmode.
    Without this patch, the compiler would load the value into a GPR register and
    then do a direct move if it needs the value in a vector register.
    
    2023-04-18   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/vsx.md (vsx_extract_v4sf_to_df_load): New insn.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/vec-extract-mem-int-1.c: New test.

Diff:
---
 gcc/config/rs6000/vsx.md                           | 33 ++++++++++++----
 .../gcc.target/powerpc/vec-extract-mem-int-1.c     | 44 ++++++++++++++++++++++
 2 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md
index 417aff5e24b..26caf81b01b 100644
--- a/gcc/config/rs6000/vsx.md
+++ b/gcc/config/rs6000/vsx.md
@@ -3930,13 +3930,31 @@
 }
   [(set_attr "type" "mfvsr")])
 
-;; Optimize extracting a single scalar element from memory.
+;; Extract a V4SI element from memory with constant element number.
+(define_insn_and_split "*vsx_extract_v4si_load"
+  [(set (match_operand:SI 0 "register_operand" "=r,r,wa,wa")
+	(vec_select:SI
+	 (match_operand:V4SI 1 "memory_operand" "m,m,Z,Q")
+	 (parallel [(match_operand:QI 2 "const_0_to_3_operand" "0,n,0,n")])))
+   (clobber (match_scratch:DI 3 "=X,&b,X,&b"))]
+  "VECTOR_MEM_VSX_P (V4SImode) && TARGET_DIRECT_MOVE_64BIT"
+  "#"
+  "&& reload_completed"
+  [(set (match_dup 0) (match_dup 4))]
+{
+  operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
+					   operands[3], SImode);
+}
+  [(set_attr "type" "load,load,fpload,fpload")
+   (set_attr "length" "4,8,4,8")])
+
+;; Extract a V8HI/V16QI element from memory with constant element number.
 (define_insn_and_split "*vsx_extract_<mode>_load"
-  [(set (match_operand:<VEC_base> 0 "register_operand" "=r")
+  [(set (match_operand:<VEC_base> 0 "register_operand" "=r,r,v,v")
 	(vec_select:<VEC_base>
-	 (match_operand:VSX_EXTRACT_I 1 "memory_operand" "m")
-	 (parallel [(match_operand:QI 2 "<VSX_EXTRACT_PREDICATE>" "n")])))
-   (clobber (match_scratch:DI 3 "=&b"))]
+	 (match_operand:VSX_EXTRACT_I2 1 "memory_operand" "m,m,Z,Q")
+	 (parallel [(match_operand:QI 2 "<VSX_EXTRACT_PREDICATE>" "0,n,0,n")])))
+   (clobber (match_scratch:DI 3 "=X,&b,X,&b"))]
   "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
   "#"
   "&& reload_completed"
@@ -3945,8 +3963,9 @@
   operands[4] = rs6000_adjust_vec_address (operands[0], operands[1], operands[2],
 					   operands[3], <VEC_base>mode);
 }
-  [(set_attr "type" "load")
-   (set_attr "length" "8")])
+  [(set_attr "type" "load,load,fpload,fpload")
+   (set_attr "length" "4,8,4,8")
+   (set_attr "isa" "*,*,p9v,p9v")])
 
 ;; Variable V16QI/V8HI/V4SI extract from a register
 (define_insn_and_split "vsx_extract_<mode>_var"
diff --git a/gcc/testsuite/gcc.target/powerpc/vec-extract-mem-int-1.c b/gcc/testsuite/gcc.target/powerpc/vec-extract-mem-int-1.c
new file mode 100644
index 00000000000..209ca926b97
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/vec-extract-mem-int-1.c
@@ -0,0 +1,44 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mdejagnu-cpu=power8" } */
+/* { dg-require-effective-target p8vector_hw } */
+
+/* Test to verify that the vec_extract with constant element numbers can load
+   SImode directly into vector registers.  */
+
+#include <altivec.h>
+
+void
+extract_sign_v4si_0 (vector int *p, int *q)
+{
+  int x = vec_extract (*p, 0);
+  __asm__ (" # %x0" : "+wa" (x));	/* lfiwzx or lfiwax.  */
+  *q = x;
+}
+
+void
+extract_sign_v4si_1 (vector int *p, int *q)
+{
+  int x = vec_extract (*p, 1);
+  __asm__ (" # %x0" : "+wa" (x));	/* lfiwzx or lfiwax.  */
+  *q = x;
+}
+
+void
+extract_uns_v4si_0 (vector unsigned int *p, unsigned int *q)
+{
+  int x = vec_extract (*p, 0);
+  __asm__ (" # %x0" : "+wa" (x));	/* lfiwzx or lfiwax.  */
+  *q = x;
+}
+
+void
+extract_v4si_1 (vector unsigned int *p, unsigned int *q)
+{
+  int x = vec_extract (*p, 1);
+  __asm__ (" # %x0" : "+wa" (x));	/* lfiwzx or lfiwax.  */
+  *q = x;
+}
+
+/* { dg-final { scan-assembler-times {\mlfiw[az]x\M|\mlxsiw[az]x\M} 4 } } */
+/* { dg-final { scan-assembler-not   {\mlw[az]x\M}                    } } */
+/* { dg-final { scan-assembler-not   {\mmtvsrw[sz]\M}                 } } */

             reply	other threads:[~2023-04-18  5:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18  5:40 Michael Meissner [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-04-19 17:53 Michael Meissner
2023-04-17 22:35 Michael Meissner
2023-04-17 22:05 Michael Meissner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230418054003.DB4C13858D28@sourceware.org \
    --to=meissner@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).