public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6208] tree-optimization/103690 - not up-to-date SSA and PRE DCE
Date: Tue,  4 Jan 2022 12:17:23 +0000 (GMT)	[thread overview]
Message-ID: <20220104121723.4367F385842E@sourceware.org> (raw)

https://gcc.gnu.org/g:ebc853deb7cc0487de9ef6e891a007ba853d1933

commit r12-6208-gebc853deb7cc0487de9ef6e891a007ba853d1933
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jan 4 11:59:35 2022 +0100

    tree-optimization/103690 - not up-to-date SSA and PRE DCE
    
    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.

Diff:
---
 gcc/tree-pass.h           |  2 +-
 gcc/tree-ssa-pre.c        | 25 ++++++++++++++++++-------
 gcc/tree-ssa-tail-merge.c | 14 ++++----------
 3 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
index eef1f3e2400..36097cf2736 100644
--- a/gcc/tree-pass.h
+++ b/gcc/tree-pass.h
@@ -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);
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index f67bd076678..ab24fa98a1f 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -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 ();
 
diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c
index f717bb2b4ad..fd333800f0f 100644
--- a/gcc/tree-ssa-tail-merge.c
+++ b/gcc/tree-ssa-tail-merge.c
@@ -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))
     {


                 reply	other threads:[~2022-01-04 12:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220104121723.4367F385842E@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).