[V2,2/12] rs6000: Add %W print modifier

Message ID ec0812b0-867b-41d4-b3c2-385c6039efc4@linux.ibm.com
State New
Headers
Series None |

Commit Message

jeevitha July 16, 2026, 4:46 p.m. UTC
  Hi All,

The following patch has been bootstrapped and regtested on powerpc64le-linux.

changes form v1:
* Moved the case 'W' below 'w'.

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  <jeevitha@linux.ibm.com>
	    Kishan Parmar  <kishan@linux.ibm.com>

gcc/
	* config/rs6000/rs6000.cc (print_operand): Add the `%W`
	print modifier to print the VSX register number plus two.
  

Comments

Michael Meissner July 20, 2026, 4:21 p.m. UTC | #1
On Thu, Jul 16, 2026 at 10:16:30PM +0530, jeevitha wrote:
> Hi All,
> 
> The following patch has been bootstrapped and regtested on powerpc64le-linux.
> 
> changes form v1:
> * Moved the case 'W' below 'w'.
> 
> 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  <jeevitha@linux.ibm.com>
> 	    Kishan Parmar  <kishan@linux.ibm.com>
> 
> gcc/
> 	* config/rs6000/rs6000.cc (print_operand): Add the `%W`
> 	print modifier to print the VSX register number plus two.

This is fine for the master branch and back port to GCC 16.x.
  
Michael Meissner July 21, 2026, 10:37 p.m. UTC | #2
On Thu, Jul 16, 2026 at 10:16:30PM +0530, jeevitha wrote:
> Hi All,
> 
> The following patch has been bootstrapped and regtested on powerpc64le-linux.
> 
> changes form v1:
> * Moved the case 'W' below 'w'.
> 
> 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.

All of these patches are cleared to be back ported to the GCC 16 branch
after a short delay to make sure the master branch was not broken,
given they only modify PowerPC specific files or documentation files.
  

Patch

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 7743c9cdc4a..3a7327a68c6 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -14516,6 +14516,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)))