]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/117979 - failed irreducible loop update from DCE
authorRichard Biener <rguenther@suse.de>
Wed, 8 Jan 2025 08:25:52 +0000 (09:25 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 26 May 2025 09:33:36 +0000 (11:33 +0200)
When CD-DCE creates forwarders to reduce false control dependences
it fails to update the irreducible state of edge and the forwarder
block in case the fowarder groups both normal (entry) and edges
from an irreducible region (necessarily backedges).  This is because
when we split the first edge, if that's a normal edge, the forwarder
and its edge to the original block will not be marked as part
of the irreducible region but when we then redirect an edge from
within the region it becomes so.

The following fixes this up.

Note I think creating a forwarder that includes backedges is
likely not going to help, but at this stage I don't want to change
the CFG going into DCE.  For regular loops we'll have a single
entry and a single backedge by means of loop init and will never
create a forwarder - so this is solely happening for irreducible
regions where it's harder to prove that such forwarder doesn't help.

PR tree-optimization/117979
* tree-ssa-dce.cc (make_forwarders_with_degenerate_phis):
Properly update the irreducible region state.

* gcc.dg/torture/pr117979.c: New testcase.

(cherry picked from commit eca04660a2c9546c8ecefc5288395eb8a9fdc168)

gcc/testsuite/gcc.dg/torture/pr117979.c [new file with mode: 0644]
gcc/tree-ssa-dce.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr117979.c b/gcc/testsuite/gcc.dg/torture/pr117979.c
new file mode 100644 (file)
index 0000000..646cd70
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+
+int a, b;
+void foo (void);
+int __attribute__((returns_twice)) bar (int);
+
+int __attribute__((const))
+baz (int f)
+{
+  if (f)
+    {
+      l:;
+      for (f = 0; f < 6; ++f)
+        if (bar (b))
+          goto l;
+      for (;; a--)
+        ;
+    }
+  foo ();
+  return 0;
+}
index 0ae998f86f9839ba5a95c5fc1a22cd2f12b5cdad..8de1a276288dec8c0abf1b30a082b964baaac7d9 100644 (file)
@@ -1857,12 +1857,22 @@ make_forwarders_with_degenerate_phis (function *fn)
                    }
                  free_dominance_info (fn, CDI_DOMINATORS);
                  basic_block forwarder = split_edge (args[start].first);
+                 bool irr = false;
                  for (unsigned j = start + 1; j < i; ++j)
                    {
                      edge e = args[j].first;
+                     if (e->flags & EDGE_IRREDUCIBLE_LOOP)
+                       irr = true;
                      redirect_edge_and_branch_force (e, forwarder);
                      redirect_edge_var_map_clear (e);
                    }
+                 if (irr)
+                   {
+                     forwarder->flags |= BB_IRREDUCIBLE_LOOP;
+                     single_succ_edge (forwarder)->flags
+                       |= EDGE_IRREDUCIBLE_LOOP;
+                   }
+
                  if (vphi)
                    {
                      tree def = copy_ssa_name (vphi_args[0]);