[Bug tree-optimization/43402] [4.5 Regression] dom1 miscompiles binary search
rguenth at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Wed Mar 17 16:43:00 GMT 2010
------- Comment #8 from rguenth at gcc dot gnu dot org 2010-03-17 16:42 -------
(In reply to comment #7)
> Hmm, I wonder how that could cause the bug. Probably because we can't rely
> on SSA form being uptodate during cfgcleanup, and hence looking up PHI
> arguments is wrong, at least for those SSA names that are registered for
> updating.
But you can't have SSA names around when you rename its symbol. And only
with SSA names the lookup is performed.
After DOM (but before cfgcleanup completes) we have
<bb 4>:
# start_1 = PHI <start_16(3)>
# limit_2 = PHI <limit_19(3)>
# lastMid_3 = PHI <mid_10(3)>
D.1978_9 = start_1 + limit_2;
mid_10 = D.1978_9 >> 1;
if (lastMid_3 == mid_10)
goto <bb 8>;
else
goto <bb 5>;
which is then simplified.
Hm. It seems we have a SSA name replacement table, thus probably the
cfgcleanup lookup code has to honor this.
The following seems to fix it:
Index: tree-cfgcleanup.c
===================================================================
*** tree-cfgcleanup.c (revision 157512)
--- tree-cfgcleanup.c (working copy)
*************** cleanup_control_expr_graph (basic_block
*** 100,123 ****
{
tree lhs = gimple_cond_lhs (stmt);
tree rhs = gimple_cond_rhs (stmt);
! /* For conditions try harder and lookup single-argument
! PHI nodes. Only do so from the same basic-block though
! as other basic-blocks may be dead already. */
! if (TREE_CODE (lhs) == SSA_NAME)
{
! gimple def_stmt = SSA_NAME_DEF_STMT (lhs);
! if (gimple_code (def_stmt) == GIMPLE_PHI
! && gimple_phi_num_args (def_stmt) == 1
! && gimple_bb (def_stmt) == gimple_bb (stmt))
! lhs = PHI_ARG_DEF (def_stmt, 0);
! }
! if (TREE_CODE (rhs) == SSA_NAME)
! {
! gimple def_stmt = SSA_NAME_DEF_STMT (rhs);
! if (gimple_code (def_stmt) == GIMPLE_PHI
! && gimple_phi_num_args (def_stmt) == 1
! && gimple_bb (def_stmt) == gimple_bb (stmt))
! rhs = PHI_ARG_DEF (def_stmt, 0);
}
val = fold_binary_loc (loc, gimple_cond_code (stmt),
boolean_type_node, lhs, rhs);
--- 100,126 ----
{
tree lhs = gimple_cond_lhs (stmt);
tree rhs = gimple_cond_rhs (stmt);
! if (!name_mappings_registered_p ())
{
! /* For conditions try harder and lookup single-argument
! PHI nodes. Only do so from the same basic-block though
! as other basic-blocks may be dead already. */
! if (TREE_CODE (lhs) == SSA_NAME)
! {
! gimple def_stmt = SSA_NAME_DEF_STMT (lhs);
! if (gimple_code (def_stmt) == GIMPLE_PHI
! && gimple_phi_num_args (def_stmt) == 1
! && gimple_bb (def_stmt) == gimple_bb (stmt))
! lhs = PHI_ARG_DEF (def_stmt, 0);
! }
! if (TREE_CODE (rhs) == SSA_NAME)
! {
! gimple def_stmt = SSA_NAME_DEF_STMT (rhs);
! if (gimple_code (def_stmt) == GIMPLE_PHI
! && gimple_phi_num_args (def_stmt) == 1
! && gimple_bb (def_stmt) == gimple_bb (stmt))
! rhs = PHI_ARG_DEF (def_stmt, 0);
! }
}
val = fold_binary_loc (loc, gimple_cond_code (stmt),
boolean_type_node, lhs, rhs);
though the essence of r157093 was to capture single-valued PHI nodes
with constant operands, so we could restrict the lookup to consider
constants only.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |rguenth at gcc dot gnu dot
|dot org |org
Status|NEW |ASSIGNED
Last reconfirmed|2010-03-17 15:21:02 |2010-03-17 16:42:29
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43402
More information about the Gcc-bugs
mailing list