https://gcc.gnu.org/g:8b1fb46450c49b48e87bc6e6230f7c95e964bb19

commit 8b1fb46450c49b48e87bc6e6230f7c95e964bb19
Author: Andrew Pinski <[email protected]>
Date:   Mon Dec 22 17:58:35 2025 -0800

    ifcvt: Fix noce_try_cond_zero_arith after get_base_reg change [PR123267]
    
    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 <[email protected]>
    (cherry picked from commit 9e61a171244110a45a87bb010704f2f9d4030181)

Diff:
---
 gcc/ifcvt.cc                              | 6 +++---
 gcc/testsuite/gcc.dg/torture/pr123267-1.c | 7 +++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
index 2a9d6605d85e..2627bf7a8789 100644
--- a/gcc/ifcvt.cc
+++ b/gcc/ifcvt.cc
@@ -3191,13 +3191,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
index 000000000000..d748df69172d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr123267-1.c
@@ -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;
+}

Reply via email to