This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] tree-ssa-sink.c: Simplify/improve code sinking.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: dberlin at dberlin dot org
- Date: Wed, 06 Apr 2005 11:10:43 -0400 (EDT)
- Subject: [patch] tree-ssa-sink.c: Simplify/improve code sinking.
Hi,
Attached is a patch to simplify/improve code sinking.
Given a statement, the code sinking in tree-ssa-sink.c computes a
location to sink a statement into by finding the nearest common
dominator of all uses of the statement's result. To do so, it goes
through immediate uses of the statement's result.
It turns out that nearest_common_dominator_of_uses are going through
things more than immediate uses. Specifically, it was going through
all PHI arguments of a PHI node where at least one use occurs. Since
uses of operands in PHI arguments are considered to occur in
predecessors of edges going into a PHI node, we are computing the
nearest common dominator of a larger set of basic blocks, which
obviously makes the result of nearest_common_dominator_of_uses
unnecessarily higher in the dominator tree.
The patch fixes this problem by visiting a PHI argument where a use
actually occurs. Fortunately, Andrew MacLeod introduced a new gadget
PHI_ARG_INDEX_FROM_USE, so we don't have to use a "for" loop to find a
PHI argument where a use occurs.
This patch is compile-time neutral, even when I use bootstrapped
compilers. After all, the "for" loop in question isn't a hot place.
Without patch, this pass sinks 2079 statements while compiling cc1-i
files. With this patch, it sinks 2179 statements. A few statements
are sunk deeper with this patch.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2005-04-06 Kazu Hirata <kazu@cs.umass.edu>
* tree-ssa-sink.c (nearest_common_dominator_of_uses): Look at
a PHI argument where a use occurs instead of all PHI arguments.
Index: tree-ssa-sink.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-sink.c,v
retrieving revision 1.3
diff -c -d -p -r1.3 tree-ssa-sink.c
*** tree-ssa-sink.c 5 Apr 2005 19:05:14 -0000 1.3
--- tree-ssa-sink.c 6 Apr 2005 02:35:08 -0000
*************** nearest_common_dominator_of_uses (tree s
*** 240,249 ****
basic_block useblock;
if (TREE_CODE (usestmt) == PHI_NODE)
{
! int j;
! for (j = 0; j < PHI_NUM_ARGS (usestmt); j++)
{
! useblock = PHI_ARG_EDGE (usestmt, j)->src;
/* Short circuit. Nothing dominates the entry block. */
if (useblock == ENTRY_BLOCK_PTR)
{
--- 240,249 ----
basic_block useblock;
if (TREE_CODE (usestmt) == PHI_NODE)
{
! int idx = PHI_ARG_INDEX_FROM_USE (use_p);
! if (PHI_ARG_DEF (usestmt, idx) == var)
{
! useblock = PHI_ARG_EDGE (usestmt, idx)->src;
/* Short circuit. Nothing dominates the entry block. */
if (useblock == ENTRY_BLOCK_PTR)
{