https://gcc.gnu.org/g:654fb68cb70ca96d27792cc7e039e2eb6a3fa9d5

commit r17-5021-g654fb68cb70ca96d27792cc7e039e2eb6a3fa9d5
Author: Jeff Law <[email protected]>
Date:   Fri Oct 9 06:40:43 2026 -0600

    [H8] Fix length computation for HImode shift left by 2^n for H8/SX
    
    One or more changes in the last week or so twiddled code generation in ways
    that triggered this failure:
    
    h8300-sim/-msx/-mint32: gcc: gcc.dg/torture/pr69714.c   -O1  execution test
    
    This was ultimately tracked down to a conditional branch which the compiler
    thought could reach its target, but in fact the target was a couple bytes 
too
    far away.  Naturally this was a mis-computation of the length HImode ashift 
by
    8 positions, but only for the H8/SX variant.  Given this was clearly a bug 
in
    the H8 target, I didn't bother to chase down the offending commit.
    
    The H8/SX variant has more compact & efficient ways to express a shift by a
    power of 2 and the length computations know about those compact forms.  But
    when we have a "shift special" we're not using those more compact and 
efficient
    forms as we emit an assembly string directly.  So that special length
    computation adjustment for H8/SX is simply wrong.  Avoiding it for the 
"shift
    special" case fixes things just fine and the correctness regression goes 
away.
    It does not fix any other failures on the H8/SX port.
    
    gcc/
            * config/h8300/h8300.cc (compute_a_shift_length): Do not do any 
special
            length adjustment for H8/SX for SHIFT_SPECIAL.

Diff:
---
 gcc/config/h8300/h8300.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/gcc/config/h8300/h8300.cc b/gcc/config/h8300/h8300.cc
index ad714f57d660..1598a86996e3 100644
--- a/gcc/config/h8300/h8300.cc
+++ b/gcc/config/h8300/h8300.cc
@@ -4340,8 +4340,11 @@ compute_a_shift_length (rtx operands[3], rtx_code code)
          /* Fall through.  */
 
        case SHIFT_INLINE:
-         /* H8/SX has a richer set of logical shifts.  */
+         /* H8/SX has a richer set of logical shifts, but do not
+            override the length computation if we're using a SHIFT_SPECIAL
+            sequence as those may not exploit the H8/SX special shifts.  */
          if (TARGET_H8300SX
+             && info.alg == SHIFT_SPECIAL
              && (code == ASHIFT || code == LSHIFTRT))
            return (exact_log2 (n) >= 0) ? 2 : 4;

Reply via email to