]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PR rtl-optimization/119099] Avoid infinite loop in ext-dce.
authorAlexey Merzlyakov <alexey.merzlyakov@samsung.com>
Thu, 6 Mar 2025 21:42:59 +0000 (14:42 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Thu, 6 Mar 2025 21:45:17 +0000 (14:45 -0700)
This fixes the ping-ponging of live sets in ext-dce which is left
unresolved can lead to infinite loops in the ext-dce pass as seen by the
P1 regression 119099.

At its core instead of replacing the livein set with the just recomputed
data, we IOR in the just recomputed data to the existing livein set.
That ensures the  existing livein set never shrinks.

Bootstrapped and regression tested on x86.  I've also thrown this into
my tester to verify it across multiple targets and that we aren't
regressing the (limited) tests we have in place for ext-dce's
optimization behavior.

While it's a generic patch, I'll wait for the RISC-V tester to run is
course before committing.

PR rtl-optimization/119099
gcc/
* ext-dce.cc (ext_dce_rd_transfer_n): Do not allow the livein
set to shrink.

gcc/testsuite/
* gcc.dg/torture/pr119099.c: New test.

Co-authored-by: Jeff Law <jlaw@ventanamicro.com>
gcc/ext-dce.cc
gcc/testsuite/gcc.dg/torture/pr119099.c [new file with mode: 0644]

index e257e3bc873aedd3855a3ed7ec2fc01759086383..626c431f601eecb2d422b1be6c5761dc586acfd7 100644 (file)
@@ -1089,16 +1089,9 @@ ext_dce_rd_transfer_n (int bb_index)
 
   ext_dce_process_bb (bb);
 
-  /* We may have narrowed the set of live objects at the start
-     of this block.  If so, update the bitmaps and indicate to
-     the generic dataflow code that something changed.  */
-  if (!bitmap_equal_p (&livein[bb_index], livenow))
-    {
-      bitmap_copy (&livein[bb_index], livenow);
-      return true;
-    }
-
-  return false;
+  /* We only allow widening the set of objects live at the start
+     of a block.  Otherwise we run the risk of not converging.  */
+  return bitmap_ior_into (&livein[bb_index], livenow);
 }
 
 /* Dummy function for the df_simple_dataflow API.  */
diff --git a/gcc/testsuite/gcc.dg/torture/pr119099.c b/gcc/testsuite/gcc.dg/torture/pr119099.c
new file mode 100644 (file)
index 0000000..2189859
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+
+int a, b;
+
+void func2(short);
+
+void func1() {
+  while (1) {
+    int loc = 8;
+    while (1) {
+      func2(loc);
+      if (a)
+        loc = 3;
+      else if (b)
+        break;
+      loc |= a;
+    }
+  }
+}