[gcc r16-9390] rs6000: Add %W print modifier

jeevitha via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:b94f1183cef3c8c79096e10f2b4ee1415edc82da

commit r16-9390-gb94f1183cef3c8c79096e10f2b4ee1415edc82da
Author: Jeevitha <[email protected]>
Date:   Tue Jul 21 10:27:29 2026 -0500

    rs6000: Add %W print modifier
    
    Add a new %W print modifier to print_operand that prints the VSX
    register number plus two.
    
    Some future Power instruction patterns require printing two VSX
    registers corresponding to a __vector_pair operand. The existing
    %x print modifier emits the first VSX register using VSX register
    numbering. Add a new %W print modifier to emit the second VSX
    register of the pair.
    
    2025-07-16  Jeevitha Palanisamy  <[email protected]>
                Kishan Parmar  <[email protected]>
    
    gcc/
            * config/rs6000/rs6000.cc (print_operand): Add the `%W`
            print modifier to print the VSX register number plus two.
    
    (cherry picked from commit 2ef1fe741998203a107fa81221ab6ce0428ebadc)

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

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index df92de6e4b51..cf2bf52b6585 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -14515,6 +14515,30 @@ print_operand (FILE *file, rtx x, int code)
 	print_operand (file, x, 0);
       return;
 
+    case 'W':
+      /* Like '%x', but prints the VSX register number +2.
+	  TODO: Validate %W operands (e.g. reject V30/V31 to avoid referencing
+	  invalid registers). Ensure GET_MODE_SIZE (GET_MODE (x)) >= 64
+	  before using %W.  */
+      if (!REG_P (x) || !VSX_REGNO_P (REGNO (x)))
+	output_operand_lossage ("invalid %%W value");
+      else
+	{
+	  int reg = REGNO (x);
+	  int vsx_reg = (FP_REGNO_P (reg)
+			 ? reg - 32
+			 : reg - FIRST_ALTIVEC_REGNO + 32);
+	  vsx_reg += 2;
+
+#ifdef TARGET_REGNAMES
+	  if (TARGET_REGNAMES)
+	    fprintf (file, "%%vs%d", vsx_reg);
+	  else
+#endif
+	    fprintf (file, "%d", vsx_reg);
+	}
+      return;
+
     case 'x':
       /* X is a FPR or Altivec register used in a VSX context.  */
       if (!REG_P (x) || !VSX_REGNO_P (REGNO (x)))
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.