Selecting gcc optimisation flags equivalent to -O1

前端 未结 2 1899
陌清茗
陌清茗 2021-01-23 10:35

I have small program that performs much better when compiled with -O1 as opposed to no optimisation. I am interested in knowing what optimisation(s) done by the com

相关标签:
2条回答
  • 2021-01-23 11:26

    How about using -S option to check the produced assembler?

    From two experiments using also "my_program.c" it seems, that -O0 option disables all optimizations regardless of the long list of suggested algorithms.

    0 讨论(0)
  • 2021-01-23 11:36

    This is expected, not a bug: https://gcc.gnu.org/wiki/FAQ#optimization-options

    Is there something else that -O1 does that isn't included in the list of optimisation flags associated with -O1 in the manual?

    Yes, it turns on optimization. Specifying individual -fxxx flags doesn't do that.

    If you don't use one of the -O1, -O2, -O3, -Ofast, or -Og optimization options (and not -O0) then no optimization happens at all, so adjusting which optimization passes are active doesn't do anything.

    To find which optimization pass makes the difference you can turn on -O1 and then disable individual optimization passes until you find the one that makes a difference.

    i.e. instead of:

    gcc -fxxx -fyyy -fzzz ...
    

    Use:

    gcc -O1 -fno-xxx -fno-yyy -fno-zzz ...
    
    0 讨论(0)
提交回复
热议问题