]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: Fix up constant handling in emit_conditional_move [PR111260]
authorAndrew Pinski <quic_apinski@quicinc.com>
Wed, 13 Dec 2023 05:55:50 +0000 (21:55 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Thu, 14 Dec 2023 21:38:57 +0000 (13:38 -0800)
After r14-2667-gceae1400cf24f329393e96dd9720, we force a constant to a register
if it is shared with one of the other operands. The problem is used the comparison
mode for the register but that could be different from the operand mode. This
causes some issues on some targets.
To fix it, we need to make sure the mode of the comparison matches the mode
of the other operands, before we can compare the constants (CONST_INT has no
modes so compare_rtx returns true if they have the same value even if the usage
is in a different mode).

Bootstrapped and tested on both aarch64-linux-gnu and x86_64-linux.

PR middle-end/111260

gcc/ChangeLog:

* optabs.cc (emit_conditional_move): Change the modes to be
equal before forcing the constant to a register.

gcc/testsuite/ChangeLog:

* gcc.c-torture/compile/condmove-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/optabs.cc
gcc/testsuite/gcc.c-torture/compile/condmove-1.c [new file with mode: 0644]

index f0a048a6bdbb08dab68503b6d246f57af89461ed..6a34276c239756581b1c5720f859c63a3f3eaf8a 100644 (file)
@@ -5131,6 +5131,7 @@ emit_conditional_move (rtx target, struct rtx_comparison comp,
          /* If we are optimizing, force expensive constants into a register
             but preserve an eventual equality with op2/op3.  */
          if (CONSTANT_P (orig_op0) && optimize
+             && cmpmode == mode
              && (rtx_cost (orig_op0, mode, COMPARE, 0,
                            optimize_insn_for_speed_p ())
                  > COSTS_N_INSNS (1))
@@ -5142,6 +5143,7 @@ emit_conditional_move (rtx target, struct rtx_comparison comp,
                op3p = XEXP (comparison, 0) = force_reg (cmpmode, orig_op0);
            }
          if (CONSTANT_P (orig_op1) && optimize
+             && cmpmode == mode
              && (rtx_cost (orig_op1, mode, COMPARE, 0,
                            optimize_insn_for_speed_p ())
                  > COSTS_N_INSNS (1))
diff --git a/gcc/testsuite/gcc.c-torture/compile/condmove-1.c b/gcc/testsuite/gcc.c-torture/compile/condmove-1.c
new file mode 100644 (file)
index 0000000..3fcc591
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR middle-end/111260 */
+
+/* Used to ICE while expansion of the `(a == b) ? b : 0;` */
+int f1(long long a)
+{
+  int b = 822920;
+  int t = a == b;
+  return t * (int)b;
+}