[committed] Fix regression in ft32 port after recent switch table adjustments

Message ID 335aa6b9-6622-40c9-87e8-2d0553122203@gmail.com
State New
Headers
Series [committed] Fix regression in ft32 port after recent switch table adjustments |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply

Commit Message

Jeff Law Jan. 7, 2025, 7:22 p.m. UTC
  This is a trivial bug that showed up after Mark W's recent patch to not 
apply the size limit on jump tables.

The ft32 port has limited immediate ranges on comparisons and the casesi 
expander didn't honor those.  It'd blindly pass along an out of range 
constant.

This patch adds the trivial adjustment to force an out of range constant 
into a register.  It fixes these regressions:

> Tests that now fail, but worked before (3 tests):
> 
> ft32-sim: gcc: gcc.c-torture/compile/pr34093.c   -O1  (test for excess errors)
> ft32-sim: gcc: gcc.dg/torture/pr106809.c   -O1  (test for excess errors)
> ft32-sim: gcc: gcc.dg/torture/pr106809.c   -O1  (test for excess errors)

Tested in my tester.    No other tests were fixed.

Jeff
commit a550edc3fae828cef67aac050b80179a97bb2fad
Author: Jeff Law <jlaw@ventanamicro.com>
Date:   Tue Jan 7 12:20:15 2025 -0700

    Fix regression in ft32 port after recent switch table adjustments
    
    This is a trivial bug that showed up after Mark W's recent patch to not apply
    the size limit on jump tables.
    
    The ft32 port has limited immediate ranges on comparisons and the casesi
    expander didn't honor those.  It'd blindly pass along an out of range constant.
    
    This patch adds the trivial adjustment to force an out of range constant into a
    register.  It fixes these regressions:
    
    > Tests that now fail, but worked before (3 tests):
    >
    > ft32-sim: gcc: gcc.c-torture/compile/pr34093.c   -O1  (test for excess errors)
    > ft32-sim: gcc: gcc.dg/torture/pr106809.c   -O1  (test for excess errors)
    > ft32-sim: gcc: gcc.dg/torture/pr106809.c   -O1  (test for excess errors)
    Tested in my tester.    No other tests were fixed.
    
    gcc/
            * config/ft32/ft32.md (casesi expander): Force operands[2] into
            a register if it's not a suitable rimm operand.
  

Patch

diff --git a/gcc/config/ft32/ft32.md b/gcc/config/ft32/ft32.md
index a1680666928..4d66abe009e 100644
--- a/gcc/config/ft32/ft32.md
+++ b/gcc/config/ft32/ft32.md
@@ -760,6 +760,12 @@  (define_expand "casesi"
       operands[0] = index;
     }
 
+  /* operands[2] could be an integer that is out of range for
+     the comparison insn we're going to emit.  If so, force
+     it into a register.  */
+  if (!ft32_rimm_operand (operands[2], SImode))
+    operands[2] = force_reg (SImode, operands[2]);
+
   {
     rtx test = gen_rtx_GTU (VOIDmode, operands[0], operands[2]);
     emit_jump_insn (gen_cbranchsi4 (test, operands[0], operands[2], operands[4]));