FW: [casting; overflow detection]
schmorp at schmorp.de
Sun Jan 16 06:37:55 UTC 2011
On Sat, Jan 15, 2011 at 04:28:17PM +0700, Robert Elz <kre at munnari.OZ.AU> wrote:
> In practice the optimisation is useless - the code it makes go away wouldn't
> have been written in the first place if it wasn't important, so when it
> happens it just makes us programmers work harder to prevent the compiler
> from taking useless advantage.
Putting my gcc head on, I have to say it is far from useless :) These kind of
things often happen during macro expansion. It's like saying, optimising away
this is useless, because nobody would write such code:
0 < 0 ? ...
but it might be part of an abs macro or just something more complicated
where some arguments are constants.
also, taking advantage of the undefined nature of (signed) integer overflow
makes it possible to calculate the number of loop rounds in a lot more cases
(because gcc doesn't have to handle the case where it wraps around and you
suddenly have a lot more iterations), and the gains from loop optimisations
can be substantial.
here is an article by ian lance taylor with some examples:
note that this behaviour is with us for a long time already, and gcc does
provide a switch to go into non-iso mode.
one can disagree with this and ask for a default mode that inhibits
optimisations that compilers of the good old 90ies didn't do, but one
cannot say they are useless :)
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
More information about the tz