tree-optimization/96548 - fix failure to recompute RPO after CFG change
authorRichard Biener <rguenther@suse.de>
Tue, 25 Aug 2020 08:59:24 +0000 (10:59 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 25 Aug 2020 12:11:49 +0000 (14:11 +0200)
This recomputes RPO after store-motion changes the CFG.

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 [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr96760.c [new file with mode: 0644]
gcc/tree-ssa-loop-im.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr96548.c b/gcc/testsuite/gcc.dg/torture/pr96548.c
new file mode 100644 (file)
index 0000000..a054742
--- /dev/null
@@ -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 (file)
index 0000000..4f6bbe9
--- /dev/null
@@ -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;
+}
index 35da1fb26a67f2a53b6a1e4a28153fe58295d5cd..f87c287d74210711ccc0fc8bb19b508824cc2ce8 100644 (file)
@@ -3115,6 +3115,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]));