I have generated C++ code which contains ~200K lines of code, and I'm trying to compile it under CentOS 5.11 with gcc 4.8.5. When I specified the -O1 flag, compilation took 1 min 33 seconds. I found all optimization flags from this and this pages that -O1 enables and here they are:
- -fcombine-stack-adjustments
- -fcompare-elim
- -fcprop-registers
- -fdefer-pop
- -fforward-propagate
- -fguess-branch-probability
- -fif-conversion
- -fif-conversion2
- -finline-functions-called-once
- -fipa-profile
- -fipa-pure-const
- -fipa-reference
- -fmerge-constants
- -fshrink-wrap
- -fsplit-wide-types
- -ftree-bit-ccp
- -ftree-ccp
- -ftree-ch
- -ftree-copy-prop
- -ftree-copyrename
- -ftree-dce
- -ftree-dominator-opts
- -ftree-dse
- -ftree-fre
- -ftree-sink
- -ftree-slsr
- -ftree-sra
- -ftree-ter
But when I replaced -O1 with these flags compilation time decreased to 34 seconds. Same with -O2 and -O3.
So, here's the question: what exactly do -O flag? If there is nothing more than another flags adding, then the compilation time should not change, but in my case there is a huge difference.