https://gcc.gnu.org/g:a71504c4120daff6fc2ae198fc588e1ce5acaa93
commit r17-4900-ga71504c4120daff6fc2ae198fc588e1ce5acaa93 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 d29e376dcb58..88a52d7c0ea8 100644 --- a/gcc/config/pa/pa.cc +++ b/gcc/config/pa/pa.cc @@ -1667,23 +1667,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; }
