https://gcc.gnu.org/g:aebbc90d8c7c703c787ce402b9c55fdf2ecbbcd8

commit r16-2648-gaebbc90d8c7c703c787ce402b9c55fdf2ecbbcd8
Author: Andrew Pinski <quic_apin...@quicinc.com>
Date:   Tue Jul 29 08:46:01 2025 -0700

    IFCVT: Fix factor_out_operators correctly for more than 1 phi [PR121295]
    
    r16-2590-ga51bf9e10182cf was not the correct fix for this in the end.
    Instead a much simplier and localized fix is needed, just change the phi
    that is being worked on with the new result and arguments that is from the
    factored out operator.
    This solves the issue of not having result in the IR and causing issues 
that way.
    
    Bootstrapped and tested on x86_64-linux-gnu.
    Note this depends on reverting r16-2590-ga51bf9e10182cf.
    
            PR tree-optimization/121236
            PR tree-optimization/121295
    
    gcc/ChangeLog:
    
            * tree-if-conv.cc (factor_out_operators): Change the phi node
            to the new result and args.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/torture/pr121236-1.c: New test.
            * gcc.dg/torture/pr121295-1.c: New test.
    
    Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com>

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr121236-1.c | 20 ++++++++++++++++++++
 gcc/testsuite/gcc.dg/torture/pr121295-1.c | 13 +++++++++++++
 gcc/tree-if-conv.cc                       |  7 +++++++
 3 files changed, 40 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr121236-1.c 
b/gcc/testsuite/gcc.dg/torture/pr121236-1.c
new file mode 100644
index 000000000000..2b397e340787
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr121236-1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* PR tree-optimization/121236 */
+
+
+unsigned func_26(short *p_27, int gg, int p) {
+  unsigned l_184 = 0;
+  unsigned m = 0;
+  for (int g_59 = 0; g_59 < 10; g_59++)
+    {
+      if (gg)
+       l_184--;
+      else
+       {
+         m |= l_184 |= p;
+         (l_184)--;
+       }
+    }
+ return m;
+}
+
diff --git a/gcc/testsuite/gcc.dg/torture/pr121295-1.c 
b/gcc/testsuite/gcc.dg/torture/pr121295-1.c
new file mode 100644
index 000000000000..7825c6ee91bf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr121295-1.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options " -fno-tree-copy-prop -fno-tree-pre 
-fno-code-hoisting" */
+
+/* PR tree-optimization/121295 */
+
+
+int a, b, c;
+int main() {
+  int *d = &a;
+  while (b)
+    b = (*d &= 10) <= 0 || (*d = c);
+  return 0;
+}
diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc
index ba25c19c50ce..b7ce0720b150 100644
--- a/gcc/tree-if-conv.cc
+++ b/gcc/tree-if-conv.cc
@@ -2291,6 +2291,13 @@ again:
   *arg0 = new_arg0;
   *arg1 = new_arg1;
   *res = new_res;
+
+  /* Update the phi node too. */
+  gimple_phi_set_result (phi, new_res);
+  gimple_phi_arg (phi, 0)->def = new_arg0;
+  gimple_phi_arg (phi, 0)->def = new_arg1;
+  update_stmt (phi);
+
   repeated = true;
   goto again;
 }

Reply via email to