diff --git a/gcc/config/ft32/ft32.md b/gcc/config/ft32/ft32.md
index a1680666928a52fbfb1e1affc3a09684aa8e7486..4d66abe009e1e72676b0253dd8ae693db4070b1a 100644
--- a/gcc/config/ft32/ft32.md
+++ b/gcc/config/ft32/ft32.md
@@ -760,6 +760,12 @@
       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]));