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: Disable all optimization options in GCC


On 10/22/2015 07:11 AM, Lars Nielsen wrote:


On 22 Oct 2015, at 14:47, Mohamed Boussaa <mohamedboussaa3@gmail.com> wrote:

The default optimization level for compiling C programs using GCC is
-O0. which turns off all optimizations according to GCC documentation.
for example:

    gcc -O0 test.c

However, to check if -O0 is really turning off all optimizations. I
executed this command:

    gcc -Q -O0 --help=optimizers
	
RTFM https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html
âhelp=optimizers:
	âoptimizersâ
	Display all of the optimization options supported by the compiler
It does not show what is activate it shows what is supported.

Reading beyond the first mention of the options, one sees:

  If the -Q option appears on the command line before the --help=
  option, then the descriptive text displayed by --help= is changed.
  Instead of describing the displayed options, an indication is given
  as to whether the option is enabled, disabled or set to a specific
  value

  The output is sensitive to the effects of previous command-line
  options, so for example it is possible to find out which
  optimizations are enabled at -O2 by using:

          -Q -O2 --help=optimizers

  ...

What's not obvious is that even when many of these fine-grained
optimization options are enabled (either implicitly in the source
code of the compiler or explicitly by the user on the command line
or via a pragma) the corresponding optimizations don't necessarily
run unless other optimizations are also enabled.

For example, the first option that shows up as enabled in the
output, -faggressive-loop-optimizations, is specified as enabled
by default, but only comes into play at -O2 and higher, during
optimizations like dead code elimination, loop unrolling, value
range propagation, etc.

So the output of the -Q --help=optimizers option isn't quite as
meaningful as one might hope.

Martin


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