g++ O1 is not equal to O0 with all related optimization flags

前端 未结 1 924
醉话见心
醉话见心 2021-01-13 12:47

I know the title is a bit confusing. Let me clarify my problem with a little background:

My program behaves strangely when I compile it with -O1 flag vs

相关标签:
1条回答
  • 2021-01-13 13:15

    The optimizations flags applied by -O1 only apply when the optimizer is turned on. You need to specify -On with n > 0 in order for the optimization flags to actually do anything.

    To put it another way, -O0 doesn't turn on the optimizer, so the optimization flags don't do anything.


    You can turn off optimzations flags by using the -fno form of the flag. For instance the

    -fcompare-elim 
    

    flag is turned on by -O1 and you can turn it back off using

    -fno-compare-elim 
    

    Another thing to note, as pointed out by T.C., is that not all optimizations have a flag so there isn't any way to turn those particular optimizations off.

    0 讨论(0)
提交回复
热议问题