[Vm-dev] [commit][3753] Do not use -O3 optimization, -O2 is safer and works well.

Andres Valloud avalloud at smalltalk.comcastbiz.net
Sat Dec 24 10:54:17 UTC 2016


I'm going to spend some time on Google to see if I can find what I 
remember reading.  In the mean time, consider this statement from the 
GCC manual:

"Not all optimizations are controlled directly by a flag. Only 
optimizations that have a flag are listed in this section."

Ok so, just like the errno case with IBM's XL C compiler, does that mean 
e.g. -O3 enables optimizations that are not behavior preserving that 
also do not have a flag, thus are unlisted, and thus -O3 doesn't have to 
say it's not behavior preserving?

On 12/23/16 13:52 , Holger Freyther wrote:
>
>> On 23 Dec 2016, at 22:30, Andres Valloud <avalloud at smalltalk.comcastbiz.net> wrote:
>>
>> Compiler manuals usually state -O3 and higher do not preserve language semantics.  It's going to be hard to prove "bug" in the non-default presence of a switch known to potentially produce undefined behavior.
>
> Where did you get that from? I tried reading it up but don't see anything.
>
>
> Clang:
>
> -O3 Like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster).
>
> => so longer compilation time, bigger binary
>
>
>
> gcc:
>
> -O3
> Optimize yet more.  -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-loop-vectorize, -ftree-loop-distribute-patterns, -fsplit-paths -ftree-slp-vectorize, -fvect-cost-model, -ftree-partial-pre, -fpeel-loops and -fipa-cp-clone options.
>
> => None says that the language standard is broken
>
>
>
> Intel ICC
>
> -O3
>
> Performs O2 optimizations and enables more aggressive loop transformations such as Fusion, Block-Unroll-and-Jam, and collapsing IF statements. The O3 optimizations may not cause higher performance unless loop and memory access transformations take place. The optimizations may slow down code in some cases compared to O2 optimizations. The O3 option is recommended for applications that have loops that heavily use floating-point calculations and process large data sets.
>
>
>
> So both Intel ICC an GCC start doing more auto vectorization with -O3. Nothing of that is breaking the language semantic. So in most cases if -O3 breaks things.. the code has undefined behavior...
>
>
> holger
>
>
>


More information about the Vm-dev mailing list