Optimization flags not working (GCC 4.2.4)

Robert William Fuller hydrologiccycle@gmail.com
Sat Apr 4 00:58:00 GMT 2009


slnc wrote:
> David Daney wrote:
>> slnc wrote:
>>> Hi John,
>>>
>>> Thank you but -O0 makes no difference.
>>>
>>
>> That's what he just said.  If you use -O0 (the implied default) none
>> of the optimizations are done.  Use -O1 (or -O2 or -O3) if you want
>> optimizations done.
> 
> Oh, I misunderstood him, sorry. It also doesn't work if I omit
> -O<anything>. So to sum it up, there is no way to compile a program in
> gcc enabling only one specific optimization flag. The only option is to
> use the "pre-packaged" sets of flags (-O1, -O2 or -O3) right?
> 
> I have tried disabling all -O1 flags just to check if I could select
> only one by disabling all the others but:
> 
> gcc -c -O1 -fno-defer-pop -fno-delayed-branch
> -fno-guess-branch-probability -fno-cprop-registers -fno-if-conversion
> -fno-if-conversion2 -fno-tree-ccp -fno-tree-dce -fno-tree-dominator-opts
> -fno-tree-dse -fno-tree-ter -fno-tree-lrs -fno-tree-sra
> -fno-tree-copyrename -fno-tree-fre -fno-tree-ch -fno-unit-at-a-time
> -fno-merge-constants main.c
> objdump -d dce.o
> 
> generates an optimized version. So why are the flags there if they
> cannot be selected individually? (I feel like I am missing something
> completely obvious..)
> 
> Thank you,

The conceptual model is that the flags allow you to tweak the
optimizations selected by various optimization regimes (aka optimization
levels.) First, you specify an optimization regime such as -O1, -O2, or
-O3. Then, if you do not like a specific optimization, such as
-fomit-frame-pointer, which often makes it more difficult to debug
programs, then you can remove it with -fno-omit-frame-pointer.
Conversely, if you want a more aggressive optimization, without
increasing the optimization regime to a more aggressive regime, you can
add that specific optimization. So, if I wanted an optimization from
-O2, but did not want to increase my optimization regime to -O2 from
-O1, I can specify just that optimization. However, you cannot tweak the
optimizations selected by an optimization regime if you do not tell the
compiler to optimize!



More information about the Gcc-help mailing list