[gcc(refs/users/meissner/heads/work251-sha)] Add xvrlw support.

Michael Meissner via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:68858b9bccf0ba47b3e7336c5b6e169c22866a24

commit 68858b9bccf0ba47b3e7336c5b6e169c22866a24
Author: Michael Meissner <[email protected]>
Date:   Thu Jul 16 15:27:15 2026 -0400

    Add xvrlw support.
    
    This patch adds support for a possible new variant of the vector rotate left
    instruction that might be added to a future PowerPC.  This variant (xvrlw) can
    use any VSX register instead of requiring only Altivec registers.
    
    As a potential test, add other variants of vxvrl<x> enabled with the -mxvrld option.
    
    2026-07-16  Michael Meissner  <[email protected]>
    
    gcc/
    
            * config/rs6000/altivec.md (xvrlw): New insn.
            (test_xvrl<VI_char>): Add test insns.
            * config/rs6000/rs6000.h (TARGET_XVRLD): New macro.
    
    gcc/testsuite/
    
            * lib/target-supports.exp

Diff:
---
 gcc/config/rs6000/altivec.md                       | 25 ++++++++++++++++
 gcc/config/rs6000/rs6000.h                         |  3 ++
 gcc/config/rs6000/rs6000.opt                       |  4 +++
 .../gcc.target/powerpc/vector-rotate-left.c        | 34 ++++++++++++++++++++++
 4 files changed, 66 insertions(+)

diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md
index a8f8d039ffc7..aec0fbec7c44 100644
--- a/gcc/config/rs6000/altivec.md
+++ b/gcc/config/rs6000/altivec.md
@@ -2018,6 +2018,31 @@
 }
   [(set_attr "type" "vecperm")])
 
+;; -mcpu=future adds a vector rotate left word variant.  There is no vector
+;; byte/half-word/double-word/quad-word rotate left.  This insn occurs before
+;; altivec_vrl<VI_char> and will match for -mcpu=future, while other cpus will
+;; match the generic insn.
+(define_insn "*xvrlw"
+  [(set (match_operand:V4SI 0 "register_operand" "=v,wa")
+	(rotate:V4SI (match_operand:V4SI 1 "register_operand" "v,wa")
+		     (match_operand:V4SI 2 "register_operand" "v,wa")))]
+  "TARGET_XVRLW"
+  "@
+   vrlw %0,%1,%2
+   xvrlw %x0,%x1,%x2"
+  [(set_attr "type" "vecsimple")])
+
+;; Add a test for the other vector rotate instructions also.
+(define_insn "*test_xvrl<VI_char>"
+  [(set (match_operand:VI2 0 "register_operand" "=v,wa")
+	(rotate:VI2 (match_operand:VI2 1 "register_operand" "v,wa")
+		    (match_operand:VI2 2 "register_operand" "v,wa")))]
+  "TARGET_XVRLD && <MODE>mode != V4SImode"
+  "@
+   vrl<VI_char> %0,%1,%2
+   xvrl<VI_char> %x0,%x1,%x2"
+  [(set_attr "type" "vecsimple")])
+
 (define_insn "altivec_vrl<VI_char>"
   [(set (match_operand:VI2 0 "register_operand" "=v")
         (rotate:VI2 (match_operand:VI2 1 "register_operand" "v")
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 34ae4a149452..75b20d4dcca9 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -569,6 +569,9 @@ extern int rs6000_vector_align[];
    below.  */
 #define RS6000_FN_TARGET_INFO_HTM 1
 
+/* Whether we have XVRLW support.  */
+#define TARGET_XVRLW			TARGET_FUTURE
+
 /* Whether the various reciprocal divide/square root estimate instructions
    exist, and whether we should automatically generate code for the instruction
    by default.  */
diff --git a/gcc/config/rs6000/rs6000.opt b/gcc/config/rs6000/rs6000.opt
index d9e9de92b21a..b82f9164f260 100644
--- a/gcc/config/rs6000/rs6000.opt
+++ b/gcc/config/rs6000/rs6000.opt
@@ -642,6 +642,10 @@ mieee128-constant
 Target Var(TARGET_IEEE128_CONSTANT) Init(1) Save
 Generate (do not generate) code that uses the LXVKQ instruction.
 
+mxvrld
+Target Var(TARGET_XVRLD) Init(0) Save
+Generate (do not generate) code that uses the potential XVRL{B,H,D} instructions.
+
 ; Documented parameters
 
 -param=rs6000-vect-unroll-limit=
diff --git a/gcc/testsuite/gcc.target/powerpc/vector-rotate-left.c b/gcc/testsuite/gcc.target/powerpc/vector-rotate-left.c
new file mode 100644
index 000000000000..f9e87ad4bfcf
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/vector-rotate-left.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target powerpc_future_ok } */
+/* { dg-options "-mdejagnu-cpu=future -O2" } */
+
+/* Test whether the xvrl (vector word rotate left using VSX registers insead of
+   Altivec registers is generated.  */
+
+#include <altivec.h>
+
+typedef vector unsigned int  v4si_t;
+
+v4si_t
+rotl_v4si_scalar (v4si_t x, unsigned long n)
+{
+  __asm__ (" # %x0" : "+f" (x));
+  return (x << n) | (x >> (32 - n));	/* xvrlw.  */
+}
+
+v4si_t
+rotr_v4si_scalar (v4si_t x, unsigned long n)
+{
+  __asm__ (" # %x0" : "+f" (x));
+  return (x >> n) | (x << (32 - n));	/* xvrlw.  */
+}
+
+v4si_t
+rotl_v4si_vector (v4si_t x, v4si_t y)
+{
+  __asm__ (" # %x0" : "+f" (x));	/* xvrlw.  */
+  return vec_rl (x, y);
+}
+
+/* { dg-final { scan-assembler-times {\mxvrlw\M} 3  } } */
+/* { dg-final { scan-assembler-not   {\mvrlw\M}     } } */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.