https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67607
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2015-09-17 CC| |rguenth at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- so this is ((unsigned long)((unsigned int) length_4(D) - 1U) + 1) you can't optimize this to (unsigned long) length_4(D) as for length_4 == 0 the result is 0x100000000. So what's the missed constant folding? Ah, so the above is guarded with if (length_4(D) > 0) which means we fail to optimize this to (unsigned long)length_4(D) because we don't consider this transform might be valid when taking into account range-info. # RANGE [1, 2147483647] NONZERO 2147483647 _19 = (unsigned int) length_4(D); # RANGE [0, 2147483646] NONZERO 2147483647 _18 = _19 + 4294967295; # RANGE [0, 2147483646] NONZERO 2147483647 _21 = (sizetype) _18; # RANGE [1, 2147483647] NONZERO 2147483647 _22 = _21 + 1; so here VRP could for example have promoted _19 and _18 to sizetype. Or it could handle the arithmetic simplification itself. We'd like to handle (T)(X +- CST1) +- CST1 generally here (both widening/shortening casts).