This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] cfgrtl.c: Speed up cfg_layout_redirect_edge_and_branch.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 27 Nov 2004 19:20:36 -0500 (EST)
- Subject: [patch] cfgrtl.c: Speed up cfg_layout_redirect_edge_and_branch.
Hi,
Attached is a patch to speed up cfg_layout_redirect_edge_and_branch.
At the point of change, we know that EDGE_COUNT (src->succs) == 2.
Furthermore, we know that E is one of the outgoing edges from SRC. In
fact, SRC is computed as E->src, so we can "unroll" and simplify the
following loop
FOR_EACH_EDGE (tmp, ei, src->succs)
if (e == tmp)
{
found = true;
ix = ei.index;
break;
}
like so
ix = EDGE_SUCC (src, 0) != e;
Now, consider the "if" statement that immediately follows:
if (EDGE_COUNT (src->succs) > (ix + 1))
s = EDGE_SUCC (src, ix + 1);
else
s = EDGE_SUCC (src, 0);
Since we know that EDGE_COUNT (src->succs) == 2, and that IX takes
either 0 or 1, we can simplify the "if" statement to
s = EDGE_SUCC (src, !ix);
Plugging in the definition of IX into the use of IX, we get
s = EDGE_SUCC (src, EDGE_SUCC (src, 0) == e);
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2004-11-28 Kazu Hirata <kazu@cs.umass.edu>
* cfgrtl.c (cfg_layout_redirect_edge_and_branch): Speed up by
simplifying edge manipulation.
Index: cfgrtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgrtl.c,v
retrieving revision 1.152
diff -c -d -p -r1.152 cfgrtl.c
*** cfgrtl.c 26 Nov 2004 06:54:13 -0000 1.152
--- cfgrtl.c 27 Nov 2004 17:42:24 -0000
*************** cfg_layout_redirect_edge_and_branch (edg
*** 2587,2611 ****
of conditional jump, remove it. */
if (EDGE_COUNT (src->succs) == 2)
{
! bool found = false;
! unsigned ix = 0;
! edge tmp, s;
! edge_iterator ei;
!
! FOR_EACH_EDGE (tmp, ei, src->succs)
! if (e == tmp)
! {
! found = true;
! ix = ei.index;
! break;
! }
!
! gcc_assert (found);
!
! if (EDGE_COUNT (src->succs) > (ix + 1))
! s = EDGE_SUCC (src, ix + 1);
! else
! s = EDGE_SUCC (src, 0);
if (s->dest == dest
&& any_condjump_p (BB_END (src))
--- 2587,2594 ----
of conditional jump, remove it. */
if (EDGE_COUNT (src->succs) == 2)
{
! /* Find the edge that is different from E. */
! edge s = EDGE_SUCC (src, EDGE_SUCC (src, 0) == e);
if (s->dest == dest
&& any_condjump_p (BB_END (src))