PR 15454: wrong code due to tree constant propagation
Steven Bosscher
stevenb@suse.de
Mon May 17 09:01:00 GMT 2004
Hi,
This is a wrong code bug due to tree ssa CCP. Consider:
void abort ();
int main () {
int foo;
int bar (void)
{
int baz = 0;
if (foo)
baz = foo;
return baz;
}
foo = 1;
if (!bar ())
abort ();
return 0;
}
Before CCP the nested function bar looks like this:
bar ()
{
int baz;
int foo.1;
<bb 0>:
foo.1_4 = CHAIN.3_3->foo;
if (foo.1_4 != 0) goto <L0>; else goto <L1>;
<L0>:;
# baz_1 = PHI <0(0), foo.1_4(1)>;
<L1>:;
return baz_1;
}
The SSA_NAME_DEF_STMT for CHAIN.3_3 is an empty statement, so we
treat it as an uninitialized variable. Now, we apparently assume
ununitialized variables to be UNDEFINED. So the meet of the
CONSTANT 0 and the UNDEFINED foo.1_4 in the PHI:
# baz_1 = PHI <0(0), foo.1_4(1)>;
returns CONSTANT for baz_1, which is overly optimistic in this case.
I believe we should assume that variables without an initializing
statement are VARYING. That's what the attached patch does.
Another solution would be to introduce some concept of a hidden DEF
but the result would be the same and this patch shouldn't hide any
safe optimization opportunities anyway.
Bootstrapped on x86-64-unknown-linux-gnu. OK?
Gr.
Steven
* tree-ssa-ccp.c (get_default_value): Treat SSA names with an
empty SSA_NAME_DEF_STMT as VARYING.
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-ccp.c,v
retrieving revision 2.2
diff -c -3 -p -r2.2 tree-ssa-ccp.c
*** tree-ssa-ccp.c 14 May 2004 02:29:23 -0000 2.2
--- tree-ssa-ccp.c 15 May 2004 11:53:24 -0000
*************** get_default_value (tree var)
*** 2106,2112 ****
enum tree_code code;
tree stmt = SSA_NAME_DEF_STMT (var);
! if (!IS_EMPTY_STMT (stmt))
{
code = TREE_CODE (stmt);
if (code != MODIFY_EXPR && code != PHI_NODE)
--- 2106,2114 ----
enum tree_code code;
tree stmt = SSA_NAME_DEF_STMT (var);
! if (IS_EMPTY_STMT (stmt))
! val.lattice_val = VARYING;
! else
{
code = TREE_CODE (stmt);
if (code != MODIFY_EXPR && code != PHI_NODE)
More information about the Gcc-patches
mailing list