Exactly my point. It is not easy to imagine a case where this is a _desirable_ optimization.
It is either a bug, which should be warned, or it is deliberate. Either way the compiler
should not remove the code!
I imagine however that the general assumption "int + positive_value is always greater than
int" may be useful for complex loop optimizations and the like. It probably allows to
completely ignore integer overflow in cases like this "for (int i = 0; i < x; ++i ) {...}".
Posted Apr 18, 2008 22:29 UTC (Fri) by nix (subscriber, #2304)
[Link]
That's equally useful for pointer arithmetic. Think arrays, strings,
pointer walks, even things like Floyd's algorithm (smart optimizers can
even spot the relationship between the tortoise and the hare: allowing for
the hare to wrap around would ruin that).