[Bug tree-optimization/20580] New: Using ASSERT_EXPR to improve constant propagation of conditional constants
steven at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Mar 21 18:40:00 GMT 2005
This is an enhancement request for constant propagation on the
tree-cleanup-branch. Consider the following small test case:
int foo (int a, int b) {
if (a || b) {
a = 3;
return a + b;
}
return a + b;
}
We currently compile this to the following .optimized dump:
foo (a, b)
{
int D.1465;
int D.1464;
<bb 0>:
if ((a | b) != 0) goto <L0>; else goto <L1>;
<L0>:;
D.1465 = b + 3;
goto <bb 3> (<L2>);
<L1>:;
D.1465 = a + b; /* Ah-ha! But we know both a and b must be 0! */
<L2>:;
return D.1465;
}
Notice the "D.1465 = a + b;". We can know that both a and b are 0 at
this point, or the condition "(a | b)" could not have been false. So
this test case could be optimized to something like this:
foo (a, b)
{
int D.1465;
int D.1464;
<bb 0>:
if ((a | b) != 0) goto <L0>; else goto <L1>;
<L0>:;
D.1465 = b + 3;
goto <bb 3> (<L2>);
<L1>:;
D.1465 = 0;
<L2>:;
return D.1465;
}
In the traditional SSA-CCP algorithm this is actually difficult to do,
but on the tree-cleanup-branch, we can insert ASSERT_EXPRs for a and b
in the false arm of the conditional:
foo (a, b)
{
int D.1465;
int D.1464;
<bb 0>:
D.1464_4 = a_2 | b_3;
if (D.1464_4 != 0) goto <L0>; else goto <L1>;
<L0>:;
D.1465_8 = b_3 + 3;
goto <bb 3> (<L2>);
<L1>:;
a_7 = ASSERT_EXPR <a_2, 0>;
b_8 = ASSERT_EXPR <a_3, 0>
D.1465_6 = a_7 + b_8;
# D.1465_1 = PHI <D.1465_8(1), D.1465_6(2)>;
<L2>:;
return D.1465_1;
}
This should allow us to propagate more constants.
--
Summary: Using ASSERT_EXPR to improve constant propagation of
conditional constants
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Keywords: missed-optimization, TREE
Severity: enhancement
Priority: P2
Component: tree-optimization
AssignedTo: dnovillo at gcc dot gnu dot org
ReportedBy: steven at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20580
More information about the Gcc-bugs
mailing list