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: How safe is gcc -O3 ?


"Dr. David Kirkby" <david.kirkby@onetel.net> writes:

> How safe is it to distribute code for others to build, where you have
> selected -O3 for them? I'm a bit concerned that might be a bit
> aggressive to use as a default, given it will potentially be compiled
> by different gcc versions on different platforms.

The -O3 optoin should be safe for correct code.  An important difference
between -O2/-O3 and -O1 is that -O2 and -O3 enable strict aliasing and
strict overflow.  Those options provide better optimization for correct
code, but are far more likely to cause unexpected code generation for
incorrect code.  See the -fstrict-aliasing and -fstrict-overflow
options.

> I believe -O2 might be a more sensible default, but would welcome the
> opinions of others on the matter.

The main difference between -O3 and -O2 is that -O3 enables more
speculative optimizations.  These should not miscompile your code, but
they may cause your program to run more slowly.

Ian


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