[PATCH] tree-optimization/96548 - fix failure to recompute RPO after CFG change

Richard Biener rguenther@suse.de
Tue Aug 25 11:55:08 GMT 2020


This recomputes RPO after store-motion changes the CFG.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2020-08-25  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/96548
	PR tree-optimization/96760
	* tree-ssa-loop-im.c (tree_ssa_lim): Recompute RPO after
	store-motion.

	* gcc.dg/torture/pr96548.c: New testcase.
	* gcc.dg/torture/pr96760.c: Likewise.
---
 gcc/testsuite/gcc.dg/torture/pr96548.c | 20 ++++++++++++++++++++
 gcc/testsuite/gcc.dg/torture/pr96760.c | 22 ++++++++++++++++++++++
 gcc/tree-ssa-loop-im.c                 |  4 ++++
 3 files changed, 46 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr96548.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr96760.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr96548.c b/gcc/testsuite/gcc.dg/torture/pr96548.c
new file mode 100644
index 00000000000..a0547427d29
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr96548.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+
+int c9, d3;
+
+void
+sg (int *rs, int f2)
+{
+  for (;;)
+    {
+      if (*rs < 1)
+        __builtin_unreachable ();
+
+      for (c9 = 0; c9 < 1; ++c9)
+        while (f2 < 1)
+          ++c9;
+
+      if (d3)
+        c9 += !!f2 ? 0 : d3;
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/torture/pr96760.c b/gcc/testsuite/gcc.dg/torture/pr96760.c
new file mode 100644
index 00000000000..4f6bbe96faf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr96760.c
@@ -0,0 +1,22 @@
+/* { dg-do run } */
+
+char a = 0, f = 0, c = 5;
+unsigned long d = 0;
+int g = 0;
+int *e = &g;
+
+int main() {
+  char  b = 0;
+  for (;;) {
+    for (a = 0; a < 2; a++) { // no UB I believe
+      if (c) {
+        if (d != 0)
+          __builtin_abort ();
+        return 0;
+      }
+    }
+    f = (d++, *e);
+  }
+
+  return 1;
+}
diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c
index 8b7eb57514f..d8fb28ec5bd 100644
--- a/gcc/tree-ssa-loop-im.c
+++ b/gcc/tree-ssa-loop-im.c
@@ -3114,6 +3114,10 @@ tree_ssa_lim (function *fun)
      out of the loops as well.  */
   do_store_motion ();
 
+  free (rpo);
+  rpo = XNEWVEC (int, last_basic_block_for_fn (fun));
+  n = pre_and_rev_post_order_compute_fn (fun, NULL, rpo, false);
+
   /* Move the expressions that are expensive enough.  */
   for (int i = 0; i < n; ++i)
     todo |= move_computations_worker (BASIC_BLOCK_FOR_FN (fun, rpo[i]));
-- 
2.26.2


More information about the Gcc-patches mailing list