------- Comment #10 from christoph dot mallon at gmx dot de 2007-02-20 06:02 ------- (In reply to comment #9) > Note SSA CCP usually (this is how it is done in the papers and almost always > done in all comericial compilers too) does PHI<1, UNDEFINED> as just being 1. > > This is still a dup because the loop in that bug is exactly that case. > > *** This bug has been marked as a duplicate of 22456 ***
I checked the dumps of Bug #22456 and this one. There is one major difference: In 22456 CCP does exactly nothing (which is not astonishing, because the phi there does not has any constants as arguments). Just the user perceivable result is the same: A missing warning. Which commercial compilers are you referring to? Sun HotSpot comes to mind, but they certainly don't do this optimisation, because undefined values are not allowed in Java and should cause an abort of the compilation. Another popular compiler would be ICC, but its EDG frontend faithfully generates the warning, of course, so there is no problem there. Here is the relevant dump of the test case in 22456, i.e. 033t.ccp (produced by GCC 4.2): foo () { int i; <bb 2>: goto <bb 4> (<L1>); <L0>:; i_3 = i_1 + 1; # i_1 = PHI <i_2(2), i_3(3)>; <L1>:; if (i_1 != 0) goto <L0>; else goto <L2>; <L2>:; return; } As you can see, the phi with one undefined argument (i_2) is still used in the following if. To get the warning about the use of the uninitialised variable it is sufficient to use -fno-tree-dce. This way a part of the loop survives long enough so the warning gets generated (Which seems to happen somewhere before 092t.cddce where the rest of the loop gets eliminated). This does _not_ work with the test case provided here. To get this valuable warning you have to use -fno-tree-ccp (This obviously does not work with the case provided in #22456, because CCP does nothing there). So as a workaround for this common case i suggest compiling with -fno-tree-ccp. IMO the long term fix for this problem is to generate the warning about uninitialised variables much earlier. Most probably this point would be just after (or during) 029t.ssa where the SSA form gets built. Thanks to the explicit def-use-chains of SSA determining if a undefined value gets used on some code path is easy as pie. Until then i strongly recommend to use -fno-tree-ccp, otherwise the warning behaviour is erratic (as stated earlier) and you miss valuable information. (I leave this as closed because I don't want to cause an edit war, but I like to see this reopened as separate bug from 22456 because it has a different cause - it just maybe have the same fix) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30856