This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Re: Latent bug in tree-ssa-loop-manip.c:split_loop_exit_edge
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sun, 12 Sep 2004 21:51:04 +0200
- Subject: [patch] Re: Latent bug in tree-ssa-loop-manip.c:split_loop_exit_edge
- References: <1094912191.4828.183.camel@localhost.localdomain>
Hello,
> With some local changes, I am running into a latent bug in
> split_loop_exit_edge.
>
> ...
> for (phi = phi_nodes (dest); phi; phi = TREE_CHAIN (phi))
> {
> op_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, bb->succ);
>
> new_name = duplicate_ssa_name (USE_FROM_PTR (op_p), NULL);
> ...
>
> Not all PHI arguments are guaranteed to be SSA_NAMEs. What should this
> function do when OP_P is a constant?
this patch fixes the function -- we do not need to do anything when
operand is a constant, since moving it out of the loop cannot violate
loop closed ssa form.
Bootstrapped & regtested on i686.
Zdenek
* tree-ssa-loop-manip.c (split_loop_exit_edge): Handle non-ssaname
arguments of the phi nodes correctly.
Index: tree-ssa-loop-manip.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-manip.c,v
retrieving revision 2.5
diff -c -3 -p -r2.5 tree-ssa-loop-manip.c
*** tree-ssa-loop-manip.c 9 Sep 2004 07:54:12 -0000 2.5
--- tree-ssa-loop-manip.c 11 Sep 2004 14:26:17 -0000
*************** split_loop_exit_edge (edge exit)
*** 395,411 ****
{
basic_block dest = exit->dest;
basic_block bb = loop_split_edge_with (exit, NULL);
! tree phi, new_phi, new_name;
use_operand_p op_p;
for (phi = phi_nodes (dest); phi; phi = TREE_CHAIN (phi))
{
op_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, bb->succ);
! new_name = duplicate_ssa_name (USE_FROM_PTR (op_p), NULL);
new_phi = create_phi_node (new_name, bb);
SSA_NAME_DEF_STMT (new_name) = new_phi;
! add_phi_arg (&new_phi, USE_FROM_PTR (op_p), exit);
SET_USE (op_p, new_name);
}
}
--- 395,420 ----
{
basic_block dest = exit->dest;
basic_block bb = loop_split_edge_with (exit, NULL);
! tree phi, new_phi, new_name, name;
use_operand_p op_p;
for (phi = phi_nodes (dest); phi; phi = TREE_CHAIN (phi))
{
op_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, bb->succ);
! name = USE_FROM_PTR (op_p);
!
! /* If the argument of the phi node is a constant, we do not need
! to keep it inside loop. */
! if (TREE_CODE (name) != SSA_NAME)
! continue;
!
! /* Otherwise create an auxiliary phi node that will copy the value
! of the ssa name out of the loop. */
! new_name = duplicate_ssa_name (name, NULL);
new_phi = create_phi_node (new_name, bb);
SSA_NAME_DEF_STMT (new_name) = new_phi;
! add_phi_arg (&new_phi, name, exit);
SET_USE (op_p, new_name);
}
}