https://gcc.gnu.org/g:ee148006fd5d11f438358e1f46367d806c0664a1

commit r15-11646-gee148006fd5d11f438358e1f46367d806c0664a1
Author: John David Anglin <[email protected]>
Date:   Mon Oct 5 10:32:04 2026 -0400

    hppa: Fix hppa_rtx_costs_shadd_p to handle subregs in inner operands
    
    Fixes gcc.target/hppa/shadd-4.c on hppa64-hp-hpux11.11.
    
    2026-10-04  John David Anglin  <[email protected]>
    
    gcc/ChangeLog:
    
            * config/pa/pa.cc (hppa_rtx_costs_shadd_p): Strip SUBREG wrappers
            from inner operands when checking if X represents a possible
            shadd pattern.

Diff:
---
 gcc/config/pa/pa.cc | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/gcc/config/pa/pa.cc b/gcc/config/pa/pa.cc
index 1c3ab056b78d..ada51aa47394 100644
--- a/gcc/config/pa/pa.cc
+++ b/gcc/config/pa/pa.cc
@@ -1660,23 +1660,43 @@ hppa_address_cost (rtx X, machine_mode mode 
ATTRIBUTE_UNUSED,
 static bool
 hppa_rtx_costs_shadd_p (rtx x)
 {
-  if (GET_CODE (x) != PLUS
-      || !REG_P (XEXP (x, 1)))
+  if (GET_CODE (x) != PLUS)
     return false;
+
+  /* Check if operand 1 is a REG or a SUBREG of a REG.  */
+  rtx op1 = XEXP (x, 1);
+  if (SUBREG_P (op1))
+    op1 = SUBREG_REG (op1);
+  if (!REG_P (op1))
+    return false;
+
   rtx op0 = XEXP (x, 0);
   if (GET_CODE (op0) == ASHIFT
-      && CONST_INT_P (XEXP (op0, 1))
-      && REG_P (XEXP (op0, 0)))
+      && CONST_INT_P (XEXP (op0, 1)))
     {
-      unsigned HOST_WIDE_INT x = UINTVAL (XEXP (op0, 1));
-      return x == 1 || x == 2 || x == 3;
+      rtx inner0 = XEXP (op0, 0);
+
+      if (SUBREG_P (inner0))
+       inner0 = SUBREG_REG (inner0);
+
+      if (REG_P (inner0))
+       {
+         unsigned HOST_WIDE_INT shift_val = UINTVAL (XEXP (op0, 1));
+         return shift_val == 1 || shift_val == 2 || shift_val == 3;
+       }
     }
   if (GET_CODE (op0) == MULT
-      && CONST_INT_P (XEXP (op0, 1))
-      && REG_P (XEXP (op0, 0)))
+      && CONST_INT_P (XEXP (op0, 1)))
     {
-      unsigned HOST_WIDE_INT x = UINTVAL (XEXP (op0, 1));
-      return x == 2 || x == 4 || x == 8;
+      rtx inner0 = XEXP (op0, 0);
+      if (SUBREG_P (inner0))
+       inner0 = SUBREG_REG (inner0);
+
+      if (REG_P (inner0))
+       {
+         unsigned HOST_WIDE_INT mult_val = UINTVAL (XEXP (op0, 1));
+         return mult_val == 2 || mult_val == 4 || mult_val == 8;
+       }
     }
   return false;
 }

Reply via email to