This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] tree-cfg.c: Speed up tree_forwarder_block_p.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: law at redhat dot com
- Date: Mon, 10 Jan 2005 23:58:05 -0500 (EST)
- Subject: [patch] tree-cfg.c: Speed up tree_forwarder_block_p.
Hi,
Attached is a patch to speed up tree_forwarder_block_p by scanning
through the statements backwards (as suggested by Jeff).
One of the requirements of a forwarder block is that a basic block
have statements except local labels. Without this patch,
tree_forwarder_block_p scans the statements forward, so the first
statement that we encounter is almost always a label, which does not
quite tell if a given basic block is a forwarder block or not. With
this patch, it scans the statements backward, so if there is any
non-label statement, we can find that out in the first iteration.
With this patch, cleanup_forwarder_blocks fairly consistently takes
21ms instead of 24ms without the patch while compiling fold-const.c.
So this is a micro optimization, but its effect is certainly
measurable.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2005-01-10 Kazu Hirata <kazu@cs.umass.edu>
* tree-cfg.c (tree_forwarder_block_p): Speed up by walking
through the statements backward.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.137
diff -u -d -p -r2.137 tree-cfg.c
--- tree-cfg.c 1 Jan 2005 16:15:10 -0000 2.137
+++ tree-cfg.c 10 Jan 2005 19:45:18 -0000
@@ -3911,9 +3911,9 @@ tree_forwarder_block_p (basic_block bb)
gcc_assert (bb != ENTRY_BLOCK_PTR);
#endif
- /* Now walk through the statements. We can ignore labels, anything else
- means this is not a forwarder block. */
- for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+ /* Now walk through the statements backward. We can ignore labels,
+ anything else means this is not a forwarder block. */
+ for (bsi = bsi_last (bb); !bsi_end_p (bsi); bsi_next (&bsi))
{
tree stmt = bsi_stmt (bsi);