1

Given that the gcc documentation (https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc.pdf) specifies that -O1 is -O0 plus a specific list of options, why is it when I time compiling my code with -O1 it takes 2 times longer to compile than using -O0 + all the options listed as being enabled when -O1 is turned on? Are there other options that are being enabled that are not specified in the documentation (my suspicion), or is there something else, more sinister, happening in the background?

If the documentation is just out of date, that would be something I'd be interested in knowing about, if only to better understand the optimization options available for GCC and my code.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • What a detail-oriented question; I love it. – David Duncan Nov 22 '15 at 00:12
  • 1
    Can't you make GCC print out a list of all its enabled options and compare? – Kerrek SB Nov 22 '15 at 00:22
  • 2
    *"... or is there something else, more sinister, happening in the background ..."* - Please tell us more! (I love a good conspiracy theory :-) ) – Stephen C Nov 22 '15 at 00:25
  • Almost same question as [GCC standard optimizations behavior](http://stackoverflow.com/questions/33832997/gcc-standard-optimizations-behavior) ? – MicroVirus Nov 22 '15 at 00:30
  • Apart from time, is also the output different in these two cases? Can you try generating asm file (easier to compare)? E.g. for -O1 it would be something like `gcc -S -O1 file.c -o file_O1.s` – nnn Nov 22 '15 at 01:11
  • 1
    Like the possible duplicate pointed out by @MicroVirus the document clearly says `Not all optimizations are controlled directly by a flag. Only optimizations that have a flag are listed in this section.` . – Shafik Yaghmour Nov 22 '15 at 01:13
  • 1
    "specifies that -O1 is -O0 plus a specific list of options" could you include an exact quote in your post? I am pretty sure it never says that, you just interpreted. – Marc Glisse Nov 22 '15 at 07:45

1 Answers1

0

If the documentation is just out of date ...

It is a fair assumption that the documentation is inaccurate. Stuff like that happens.

Another possibility is that you have misread the documentation. My reading of the document you linked to (page 111) is that -O and -O1 are supposed to mean the same thing. If that is correct, then what you are apparently trying to do doesn't make much sense.

I suggest that you look at the GCC source code to figure out exactly how -O1 is implemented. That should tell you whether the behavior you are seeing can be explained by inaccurate documentation1, or whether there is something else going on here.


1 - If the problem is inaccurate documentation, you can help the GCC folks and ultimately other GCC users by submitting a bug report with corrections.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216