Differences between -O2 and -O3

Liu, Lei lei.liu2@windriver.com
Tue Aug 17 08:05:00 GMT 2010

bernd Kopf wrote:
> Hello,
> Is there a way to know what are exactly the differences between -O2 and -O3?
> According to the manual level 3 is level 2 plus -finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize
> By comparing the outputs of gcc -O2 -c -Q and gcc -O3 -c -Q I found out that -O3 also adds -fipa-cp-clone
> By adding these options to -O2 I don't get the same exe than -O3. Same thing when I add their negative forms to -O3, I don't get the same exe than -O2
> -O2 687 kb
> -O3 937 kb
> -O2 -finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-vectorize -fipa-cp-clone 733 kb
> -O3 -fno-inline-functions -fno-unswitch-loops -fno-predictive-commoning -fno-gcse-after-reload -fno-tree-vectorize -fno-ipa-cp-clone 818 kb
> I checked opts.c but it didn't enlight me. I also try gcc --help=params, but it only reports the list, not values of the params at -O2 or -O3
> Does -O3 change some params? And how to know which ones?
> Or does gcc do some internal optimizations that can't be control by flags?
The differences between -O2 and -O3 is not only the optimization flags 
you saw in man gcc or output of -Q. At least in gcc/opts.c, you can see 
-O3 also set some parameters which affect the accuracy of alias 
analysis. So maybe you need to search the source code to find the exact 
differences between these two optimization levels.


More information about the Gcc-help mailing list