tree-optimization/97901 - ICE propagating out LC PHIs
authorRichard Biener <rguenther@suse.de>
Thu, 19 Nov 2020 09:43:35 +0000 (10:43 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 19 Nov 2020 10:35:45 +0000 (11:35 +0100)
We need to fold the stmt to canonicalize MEM_REFs which means
we're back to using replace_uses_by.  Which means we need dominators
to not require a CFG cleanup upthread.

2020-11-19  Richard Biener  <rguenther@suse.de>

PR tree-optimization/97901
* tree-ssa-propagate.c (clean_up_loop_closed_phi): Compute
dominators and use replace_uses_by.

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

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr97901.c b/gcc/testsuite/gcc.dg/torture/pr97901.c
new file mode 100644 (file)
index 0000000..a6a89ef
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+
+int a[1], b, *c, *d;
+
+int main() {
+L:
+  d = c;
+  for (b = 0; b < 2; b++)
+    d = &a[0];
+  if (c)
+    goto L;
+  if (*d)
+    __builtin_abort ();
+  return 0;
+}
index 354057b48bf3f960a3c0e9345639af911de6875a..bc656ff76b1ad1c1e3bc9b6574384570442adab8 100644 (file)
@@ -1569,6 +1569,10 @@ clean_up_loop_closed_phi (function *fun)
   if (!loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
     return 0;
 
+  /* replace_uses_by might purge dead EH edges and we want it to also
+     remove dominated blocks.  */
+  calculate_dominance_info  (CDI_DOMINATORS);
+
   /* Walk over loop in function.  */
   FOR_EACH_LOOP_FN (fun, loop, 0)
     {
@@ -1595,23 +1599,7 @@ clean_up_loop_closed_phi (function *fun)
                      fprintf (dump_file, "'\n");
                    }
 
-                 use_operand_p use_p;
-                 imm_use_iterator iter;
-                 gimple *use_stmt;
-                 FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
-                   {
-                     FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
-                       replace_exp (use_p, rhs);
-                     update_stmt (use_stmt);
-
-                     /* Update the invariant flag for ADDR_EXPR if replacing
-                        a variable index with a constant.  */
-                     if (gimple_assign_single_p (use_stmt)
-                         && TREE_CODE (gimple_assign_rhs1 (use_stmt))
-                              == ADDR_EXPR)
-                       recompute_tree_invariant_for_addr_expr (
-                         gimple_assign_rhs1 (use_stmt));
-                   }
+                 replace_uses_by (lhs, rhs);
                  remove_phi_node (&gsi, true);
                }
              else