Selecting gcc optimisation flags equivalent to -O1

前端 未结 2 1900
陌清茗
陌清茗 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: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 ...
    

提交回复
热议问题