This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Enable expand_simple_operations look through single-argument phi nodes
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 8 May 2006 13:29:53 +0200
- Subject: [patch] Enable expand_simple_operations look through single-argument phi nodes
Hello,
this is another small problem I noticed in the testcase for PR26304:
phi nodes with a single argument sometimes appear in the code. These
are usually eliminated in the next copy propagation pass, but in the
meantime they may manage to confuse # of iterations analysis -- in the
testcase for this pr, the loop
for (i = 0; i < 6; i++)
becomes
i' = phi(0)
for (i = i'; i < 6; i++)
and # of iterations analysis is no longer able to determine that the
number of iterations of this loop is 6.
This patch fixes the problem by making expand_simple_operations handle
such phi nodes. Bootstrapped & regtested on i686 and ppc.
Zdenek
* tree-ssa-loop-niter.c (expand_simple_operations): Go through
phi nodes with just a single argument.
Index: tree-ssa-loop-niter.c
===================================================================
*** tree-ssa-loop-niter.c (revision 113549)
--- tree-ssa-loop-niter.c (working copy)
*************** expand_simple_operations (tree expr)
*** 744,753 ****
return expr;
stmt = SSA_NAME_DEF_STMT (expr);
! if (TREE_CODE (stmt) != MODIFY_EXPR)
return expr;
- e = TREE_OPERAND (stmt, 1);
if (/* Casts are simple. */
TREE_CODE (e) != NOP_EXPR
&& TREE_CODE (e) != CONVERT_EXPR
--- 744,770 ----
return expr;
stmt = SSA_NAME_DEF_STMT (expr);
! if (TREE_CODE (stmt) == MODIFY_EXPR)
! e = TREE_OPERAND (stmt, 1);
! else if (TREE_CODE (stmt) == PHI_NODE
! && PHI_NUM_ARGS (stmt) == 1)
! {
! e = PHI_ARG_DEF (stmt, 0);
!
! /* Do not pass through loop exit phi nodes. */
! if (current_loops && TREE_CODE (e) == SSA_NAME)
! {
! basic_block def_bb = bb_for_stmt (SSA_NAME_DEF_STMT (e));
! basic_block phi_bb = bb_for_stmt (stmt);
!
! if (def_bb
! && flow_loop_nested_p (phi_bb->loop_father, def_bb->loop_father))
! return expr;
! }
! }
! else
return expr;
if (/* Casts are simple. */
TREE_CODE (e) != NOP_EXPR
&& TREE_CODE (e) != CONVERT_EXPR