From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Remove recursive post-dominator traversal in sinking
Date: Thu, 27 Jul 2023 09:31:49 +0000 (UTC) [thread overview]
Message-ID: <20230727093149.2ygevJ7IH48Zbdy74DTq5U16Q3dh8WmFfXtMAOgp9Oo@z> (raw)
The following turns the recursive post-dominator traversal in GIMPLE
code sinking to a worklist.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
* tree-ssa-sink.cc (sink_code_in_bb): Remove recursion, instead
use a worklist ...
(pass_sink_code::execute): ... in the caller.
---
gcc/tree-ssa-sink.cc | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/gcc/tree-ssa-sink.cc b/gcc/tree-ssa-sink.cc
index 74dae0fa3c0..ab1cbffb32a 100644
--- a/gcc/tree-ssa-sink.cc
+++ b/gcc/tree-ssa-sink.cc
@@ -673,7 +673,6 @@ sink_common_stores_to_bb (basic_block bb)
static unsigned
sink_code_in_bb (basic_block bb)
{
- basic_block son;
gimple_stmt_iterator gsi;
edge_iterator ei;
edge e;
@@ -686,12 +685,12 @@ sink_code_in_bb (basic_block bb)
/* If this block doesn't dominate anything, there can't be any place to sink
the statements to. */
if (first_dom_son (CDI_DOMINATORS, bb) == NULL)
- goto earlyout;
+ return todo;
/* We can't move things across abnormal edges, so don't try. */
FOR_EACH_EDGE (e, ei, bb->succs)
if (e->flags & EDGE_ABNORMAL)
- goto earlyout;
+ return todo;
for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
{
@@ -765,13 +764,6 @@ sink_code_in_bb (basic_block bb)
gsi_prev (&gsi);
}
- earlyout:
- for (son = first_dom_son (CDI_POST_DOMINATORS, bb);
- son;
- son = next_dom_son (CDI_POST_DOMINATORS, son))
- {
- todo |= sink_code_in_bb (son);
- }
return todo;
}
@@ -861,7 +853,20 @@ pass_sink_code::execute (function *fun)
memset (&sink_stats, 0, sizeof (sink_stats));
calculate_dominance_info (CDI_DOMINATORS);
calculate_dominance_info (CDI_POST_DOMINATORS);
- todo |= sink_code_in_bb (EXIT_BLOCK_PTR_FOR_FN (fun));
+
+ auto_vec<basic_block, 64> worklist;
+ worklist.quick_push (EXIT_BLOCK_PTR_FOR_FN (fun));
+ do
+ {
+ basic_block bb = worklist.pop ();
+ todo |= sink_code_in_bb (bb);
+ for (basic_block son = first_dom_son (CDI_POST_DOMINATORS, bb);
+ son;
+ son = next_dom_son (CDI_POST_DOMINATORS, son))
+ worklist.safe_push (son);
+ }
+ while (!worklist.is_empty ());
+
statistics_counter_event (fun, "Sunk statements", sink_stats.sunk);
statistics_counter_event (fun, "Commoned stores", sink_stats.commoned);
free_dominance_info (CDI_POST_DOMINATORS);
--
2.35.3
reply other threads:[~2023-07-27 9:31 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=20230727093149.2ygevJ7IH48Zbdy74DTq5U16Q3dh8WmFfXtMAOgp9Oo@z \
--to=rguenther@suse.de \
--cc=gcc-patches@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).