This test case is not fully optimized on mainline: ------------------------------------ typedef int (*objc_typed_write_func) (void *, const char *, int); typedef struct objc_typed_stream { void *physical; objc_typed_write_func write; } TypedStream; int foo (struct objc_typed_stream *stream, unsigned int val) { unsigned char buf[sizeof (unsigned int) + 1]; int len; if ((val & 0x1fU) == val) { buf[0] = val | 0x20U; len = 1; } else { int c, b; buf[0] = 0x40U; for (c = sizeof (int); c != 0; c -= 1) if (((val >> (8 * (c - 1))) % 0x100) != 0) break; buf[0] |= c; for (b = 1; c != 0; c--, b++) { buf[b] = (val >> (8 * (c - 1))) % 0x100; } len = b; } return (*stream->write) (stream->physical, buf, len); } ------------------------------------ ---> (in the .optimized dump): # BLOCK 3 # PRED: 2 [95.0%] (false,exec) <L3>:; cD.1575_38 = cD.1575_46 - 1; ivtmp.25D.1650_58 = ivtmp.25D.1650_18 - 8; if (cD.1575_38 != 0) goto <L2>; else goto <L24>; # SUCC: 2 [89.0%] (dfs_back,true,exec) 9 [11.0%] (loop_exit,false,exec) (...) # BLOCK 9 # PRED: 3 [11.0%] (loop_exit,false,exec) Invalid sum of outgoing probabilities 0.0% Invalid sum of incoming frequencies 1045, should be 0 # cD.1575_13 = PHI <cD.1575_38(3)>; <L24>:; D.1592_60 = (signed charD.9) cD.1575_13; D.1593_61 = D.1592_60 | 64; D.1594_62 = (unsigned charD.10) D.1593_61; # bufD.1573_63 = V_MAY_DEF <bufD.1573_15>; bufD.1573[0] = D.1594_62; goto <bb 8> (<L9>); # SUCC: 8 (fallthru,exec) cD.1575_13 is equal to 0 on entry of basic block 9. We don't propagate this constant until GCSE CPROP1. Maybe the new pass order from the tree-cleanup-branch will fix this, which is why I've added Diego to the CC list.
-- Summary: Missed constant propagation Product: gcc Version: 4.1.0 Status: UNCONFIRMED Keywords: missed-optimization, TREE Severity: normal Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: steven at gcc dot gnu dot org CC: dnovillo at redhat dot com,gcc-bugs at gcc dot gnu dot org,kazu at cs dot umass dot edu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21451