GCC多个优化标志 [英] GCC multiple optimization flags
问题描述
我有一些遗留代码,可以同时使用-02和-03进行编译.从GCC手册文件中,我可以保证:
I have some legacy code that compiles with both -02 and -03 set. From the GCC man file I get the guarantee that:
-O3打开-O2指定的所有优化,还打开-finline-functions,-funswitch-loops,-fpredictive-commoning,-fgcse-after-reload和-ftree-vectorize 选项.
-O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload and -ftree-vectorize options.
因此,乍看之下,将这两个标志都打开似乎与-O3相同.但是,使我想到的是,在这种情况下,正确的做法是-O2可能是更安全"的选择.显然,用所有排列编译一些代码并查看在每种情况下会发生什么是一件简单的事情,但是我想知道是否有人知道GCC在指定多个优化级别方面是否有特定的政策,如果有的话背后的原因是什么?
So, at first glance it would seem likely that turning both of these flags on would be the same as just -O3. However, that got me thinking is that the right thing to do in that case as -O2 is probably the "safer" option. Obviously, it is a simple matter compile some code with all of the permutations and see what happens in each case, but I was wondering if anyone knows if there is a specific policy that GCC has in regard to specifying multiple optimizations levels and if so what is the reasoning behind it?
推荐答案
在手册页中:>
如果您使用多个-O选项(带或不带级别号),则最后一个这样的选项才是有效的.
If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.
这篇关于GCC多个优化标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!