]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/103458 - avoid creating new loops in CD-DCE
authorRichard Biener <rguenther@suse.de>
Mon, 29 Nov 2021 08:15:47 +0000 (09:15 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 29 Nov 2021 08:20:27 +0000 (09:20 +0100)
When creating forwarders in CD-DCE we have to avoid creating loops
where we formerly did not consider those because of abnormal
predecessors.  At this point simply excuse us when there are any
abnormal predecessors.

2021-11-29  Richard Biener  <rguenther@suse.de>

PR tree-optimization/103458
* tree-ssa-dce.c (make_forwarders_with_degenerate_phis): Do not
create forwarders for blocks with abnormal predecessors.

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

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr103458.c b/gcc/testsuite/gcc.dg/torture/pr103458.c
new file mode 100644 (file)
index 0000000..3fd3b5f
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-Wno-div-by-zero" } */
+
+__attribute__ ((returns_twice)) int
+bar (void);
+
+void
+foo (int *p, int x)
+{
+  *p = 0;
+  while (*p < 1)
+    {
+      x = 0;
+      while (x < 1)
+        bar ();
+
+      x /= 0;
+    }
+
+  foo (p, x);
+}
index e3e6f0955b7d15d3afbeb6898f53ad21741ef591..1f817b95faba63de7af31e4bb591c3fdfe0b1352 100644 (file)
@@ -1650,8 +1650,12 @@ make_forwarders_with_degenerate_phis (function *fn)
       /* Only PHIs with three or more arguments have opportunities.  */
       if (EDGE_COUNT (bb->preds) < 3)
        continue;
-      /* Do not touch loop headers.  */
-      if (bb->loop_father->header == bb)
+      /* Do not touch loop headers or blocks with abnormal predecessors.
+        ???  This is to avoid creating valid loops here, see PR103458.
+        We might want to improve things to either explicitely add those
+        loops or at least consider blocks with no backedges.  */
+      if (bb->loop_father->header == bb
+         || bb_has_abnormal_pred (bb))
        continue;
 
       /* Take one PHI node as template to look for identical