]> git.feebdaed.xyz Git - 0xmirror/gcc.git/commitdiff
ifcvt: Fix noce_try_cond_zero_arith after get_base_reg change [PR123267]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 23 Dec 2025 01:58:35 +0000 (17:58 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 23 Dec 2025 06:19:27 +0000 (22:19 -0800)
A few fixes are needed after the change to get_base_reg of
r16-6333-gac64ceb33bf05b. First we need to use the correct target mode
of the operand, this means if we are doing a subreg of QI mode, using
QImode for the conditional move.
Second we also need to use the original operands instead of the ones
removing the subreg still.

Pushed as obvious after a bootstrap/test on x86_64-linux-gnu.

PR rtl-optimization/123267
gcc/ChangeLog:

* ifcvt.cc (noce_try_cond_zero_arith): Pass the original operands
of a instead of the stripped off values. The mode of the operand
which is being used.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr123267-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/ifcvt.cc
gcc/testsuite/gcc.dg/torture/pr123267-1.c [new file with mode: 0644]

index 802c5e99afcbff8d6d48dddb14ef9f60d0ae64a7..d7df8773839ec041dde4979dc7a949d7971aa029 100644 (file)
@@ -3188,13 +3188,13 @@ noce_try_cond_zero_arith (struct noce_if_info *if_info)
 
   start_sequence ();
 
-  target = gen_reg_rtx (mode);
+  target = gen_reg_rtx (GET_MODE (XEXP (a, op != AND)));
 
   /* AND requires !cond, instead we swap ops around.  */
   target = noce_emit_cmove (if_info, target, GET_CODE (if_info->cond),
                            XEXP (if_info->cond, 0), XEXP (if_info->cond, 1),
-                           op != AND ? a_op1 : const0_rtx,
-                           op != AND ? const0_rtx : a_op0);
+                           op != AND ? XEXP (a, 1) : const0_rtx,
+                           op != AND ? const0_rtx : XEXP (a, 0));
   if (!target)
     goto end_seq_n_fail;
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr123267-1.c b/gcc/testsuite/gcc.dg/torture/pr123267-1.c
new file mode 100644 (file)
index 0000000..d748df6
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+
+/* PR rtl-optimization/123267 */
+
+int j(long e, int k, int i) {
+  return (i&-3) == 0 ? k : k - e;
+}