This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Is it OK that gcc optimizes away overflow check?



On 25-07-2011 11:43, Andrew Haley wrote:
On 23/07/11 21:13, Agner Fog wrote:
5). I have tested many different C++ compilers, and gcc turned out to be
the one that optimizes best.
Well yes, and one of the reasons for this is that we take advantage of
integer overflow being undefined.  There is an entire class of
optimizations (loop induction variable optimization) that is difficult
of impossible without taking advantage of this.  We don't do this kind
of thing without good reason.
Actually, I think we can have the cake and eat it here. If gcc behaves reasonably safe by default and then makes warnings in case of missed optimization opportunities. The programmer should then have the opportunity to enable the desired optimizations, for example with pragmas at the critical places in the code. If the programmer doesn't need the best optimization then he would not enable those warnings and would be safe without having to care.

We already have the opportunity to allow the optimizer to ignore pointer aliasing at specific places with the 'restrict' keyword. It would be nice to have a similar opportunity to tell the compiler where it can ignore overflow.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]