This is the mail archive of the
mailing list for the GCC project.
Re: How safe is gcc -O3 ?
- From: Ian Lance Taylor <iant at google dot com>
- To: "Dr. David Kirkby" <david dot kirkby at onetel dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 20 Jul 2010 01:12:07 -0700
- Subject: Re: How safe is gcc -O3 ?
- References: <4C44F318.firstname.lastname@example.org>
"Dr. David Kirkby" <email@example.com> 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
> 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.