]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/103690 - not up-to-date SSA and PRE DCE
authorRichard Biener <rguenther@suse.de>
Tue, 4 Jan 2022 10:59:35 +0000 (11:59 +0100)
committerRichard Biener <rguenther@suse.de>
Tue, 4 Jan 2022 12:17:14 +0000 (13:17 +0100)
This avoids running simple_dce_from_worklist on partially not up-to-date
SSA form (in unreachable code regions) by scheduling CFG cleanup
manually as is done anyway when tail-merging runs.

2022-01-04  Richard Biener  <rguenther@suse.de>

PR tree-optimization/103690
* tree-pass.h (tail_merge_optimize): Adjust.
* tree-ssa-tail-merge.c (tail_merge_optimize): Pass in whether
to re-split critical edges, move CFG cleanup ...
* tree-ssa-pre.c (pass_pre::execute): ... here, before
simple_dce_from_worklist and delay freeing inserted_exprs from
...
(fini_pre): .. here.

gcc/tree-pass.h
gcc/tree-ssa-pre.c
gcc/tree-ssa-tail-merge.c

index eef1f3e2400fc073176df7693a86044ae9df6eab..36097cf2736e958f4cef52433e10b0e0e7f2b041 100644 (file)
@@ -412,7 +412,7 @@ extern gimple_opt_pass *make_pass_early_thread_jumps (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_split_crit_edges (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_laddress (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_pre (gcc::context *ctxt);
-extern unsigned int tail_merge_optimize (unsigned int);
+extern unsigned int tail_merge_optimize (unsigned int, bool);
 extern gimple_opt_pass *make_pass_profile (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_strip_predict_hints (gcc::context *ctxt);
 extern gimple_opt_pass *make_pass_lower_complex_O0 (gcc::context *ctxt);
index f67bd07667870e8e1676202c526d6c0458b7a420..ab24fa98a1f6e122592374ef82298a114242d3c1 100644 (file)
@@ -4306,7 +4306,6 @@ fini_pre ()
   value_expressions.release ();
   constant_value_expressions.release ();
   expressions.release ();
-  BITMAP_FREE (inserted_exprs);
   bitmap_obstack_release (&grand_bitmap_obstack);
   bitmap_set_pool.release ();
   pre_expr_pool.release ();
@@ -4431,16 +4430,28 @@ pass_pre::execute (function *fun)
 
   vn_valueize = NULL;
 
+  fini_pre ();
+
+  scev_finalize ();
+  loop_optimizer_finalize ();
+
+  /* Perform a CFG cleanup before we run simple_dce_from_worklist since
+     unreachable code regions will have not up-to-date SSA form which
+     confuses it.  */
+  bool need_crit_edge_split = false;
+  if (todo & TODO_cleanup_cfg)
+    {
+      cleanup_tree_cfg ();
+      todo &= ~TODO_cleanup_cfg;
+      need_crit_edge_split = true;
+    }
+
   /* Because we don't follow exactly the standard PRE algorithm, and decide not
      to insert PHI nodes sometimes, and because value numbering of casts isn't
      perfect, we sometimes end up inserting dead code.   This simple DCE-like
      pass removes any insertions we made that weren't actually used.  */
   simple_dce_from_worklist (inserted_exprs);
-
-  fini_pre ();
-
-  scev_finalize ();
-  loop_optimizer_finalize ();
+  BITMAP_FREE (inserted_exprs);
 
   /* TODO: tail_merge_optimize may merge all predecessors of a block, in which
      case we can merge the block with the remaining predecessor of the block.
@@ -4449,7 +4460,7 @@ pass_pre::execute (function *fun)
      - call merge_blocks after all tail merge iterations
      - mark TODO_cleanup_cfg when necessary
      - share the cfg cleanup with fini_pre.  */
-  todo |= tail_merge_optimize (todo);
+  todo |= tail_merge_optimize (todo, need_crit_edge_split);
 
   free_rpo_vn ();
 
index f717bb2b4add81da5f5a0d981116ce44c5c5b4cc..fd333800f0f171315bbf1293e949b0230bdd5472 100644 (file)
@@ -1724,7 +1724,7 @@ update_debug_stmts (void)
 /* Runs tail merge optimization.  */
 
 unsigned int
-tail_merge_optimize (unsigned int todo)
+tail_merge_optimize (unsigned int todo, bool need_crit_edge_split)
 {
   int nr_bbs_removed_total = 0;
   int nr_bbs_removed;
@@ -1738,15 +1738,9 @@ tail_merge_optimize (unsigned int todo)
 
   timevar_push (TV_TREE_TAIL_MERGE);
 
-  /* We enter from PRE which has critical edges split.  Elimination
-     does not process trivially dead code so cleanup the CFG if we
-     are told so.  And re-split critical edges then.  */
-  if (todo & TODO_cleanup_cfg)
-    {
-      cleanup_tree_cfg ();
-      todo &= ~TODO_cleanup_cfg;
-      split_edges_for_insertion ();
-    }
+  /* Re-split critical edges when PRE did a CFG cleanup.  */
+  if (need_crit_edge_split)
+    split_edges_for_insertion ();
 
   if (!dom_info_available_p (CDI_DOMINATORS))
     {