https://gcc.gnu.org/g:0937fd11d029751f43bdf020ebcd9b4872f2d500

commit r17-5919-g0937fd11d029751f43bdf020ebcd9b4872f2d500
Author: Richard Biener <[email protected]>
Date:   Wed Nov 4 09:47:30 2026 +0100

    tree-optimization/128426 - do not propagate zero to abnormal edge
    
    The following fixes up the odd code in simple-dce that avoids
    releasing defs but instead propagates zeros to uses.  We may not
    do this to PHI arguments flowing in from abnormal edges.
    
            PR tree-optimization/128426
            * tree-ssa-dce.cc (simple_dce_from_worklist): Keep
            PHI defs on abnormal edges.
    
            * gcc.dg/torture/pr128426.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr128426.c | 33 +++++++++++++++++++++++++++++++++
 gcc/tree-ssa-dce.cc                     |  8 +++++---
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr128426.c 
b/gcc/testsuite/gcc.dg/torture/pr128426.c
new file mode 100644
index 000000000000..d9580ad174c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr128426.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+
+int a;
+static void c (int);
+
+void
+d (void)
+{
+  int e = 0;
+  void *f[] = { &&g, &&h, &&i };
+  goto *f[a];
+h:
+  goto k;
+i:
+  e = a;
+  goto l;
+k:
+  c (e);
+  goto m;
+g:
+l:
+  if (e)
+    goto m;
+  goto h;
+m:;
+}
+
+static void
+c (int p)
+{
+  if (p)
+    d ();
+}
diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
index 9d5dce20d03c..b5fe922bfd10 100644
--- a/gcc/tree-ssa-dce.cc
+++ b/gcc/tree-ssa-dce.cc
@@ -2320,9 +2320,11 @@ simple_dce_from_worklist (bitmap worklist, bitmap 
need_eh_cleanup,
            {
              gphi *phi = as_a<gphi *> (t);
              tree zero = build_zero_cst (TREE_TYPE (def));
-             for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i)
-               SET_PHI_ARG_DEF (phi, i, zero);
-             update_stmt (phi);
+             edge_iterator ei;
+             edge e;
+             FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
+               if (!(e->flags & EDGE_ABNORMAL))
+                 SET_PHI_ARG_DEF (phi, e->dest_idx, zero);
              reset_flow_sensitive_info (def);
            }
          else

Reply via email to