This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/19804] New: Missed jump threading opportunity on "else" arm of COND_EXPR
- From: "kazu at cs dot umass dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Feb 2005 03:25:49 -0000
- Subject: [Bug tree-optimization/19804] New: Missed jump threading opportunity on "else" arm of COND_EXPR
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Consider:
int
foo (int a, int b)
{
if (a == 0)
if (b != 2)
return 10;
if (b == 1)
return 10;
return 20;
}
Here is t21.dom1:
foo (a, b)
{
int D.1120;
<bb 0>:
if (a_2 == 0) goto <L0>; else goto <L2>;
<L0>:;
if (b_4 != 2) goto <L1>; else goto <L2>;
<L1>:;
D.1120_7 = 10;
goto <bb 6> (<L6>);
<L2>:;
if (b_4 == 1) goto <L4>; else goto <L5>;
<L4>:;
D.1120_6 = 10;
goto <bb 6> (<L6>);
<L5>:;
D.1120_5 = 20;
# D.1120_1 = PHI <10(2), 10(4), 20(5)>;
<L6>:;
return D.1120_1;
}
Note that edge from <L0> to <L2> can be threaded through L2.
This seems to be due to an artificial restriction in
tree-ssa-dom.c:dom_opt_finalize_block.
/* If we have a simple NAME = VALUE equivalency record it.
Until the jump threading selection code improves, only
do this if both the name and value are SSA_NAMEs with
the same underlying variable to avoid missing threading
opportunities. */
if (lhs
&& TREE_CODE (COND_EXPR_COND (last)) == SSA_NAME)
record_const_or_copy (lhs, rhs);
This "if" should just say "if (lhs)".
But be careful though. Making the above change seems to miss other jump
threading opportunities as far as I can tell from my coverage test.
I have yet to find a test case that would be less optimized with the above
change.
By the way, the comment above the "if" statement is just a cut-n-paste from
the "then" case. It does not reflect what the "if" statement does though.
--
Summary: Missed jump threading opportunity on "else" arm of
COND_EXPR
Product: gcc
Version: unknown
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kazu at cs dot umass dot edu
CC: gcc-bugs at gcc dot gnu dot org,law at redhat dot com
OtherBugsDependingO 19794
nThis:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19804