GCC 多个优化标志
我有一些使用 -02 和 -03 集进行编译的遗留代码。从 GCC man 文件我得到保证:
-O3 打开 -O2 指定的所有优化,还打开 -finline-functions、-funswitch-loops、-fpredictive-commoning、-fgcse-after-reload 和 -ftree-vectorize 选项。
因此,乍一看,打开这两个标志似乎与 -O3 相同。然而,这让我想到,在这种情况下应该做正确的事情,因为 -O2 可能是“更安全”的选项。显然,用所有排列编译一些代码并看看每种情况下会发生什么是一件简单的事情,但我想知道是否有人知道 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 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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 手册页:
From the man page:
对于像我这样过度关心的用户,这里有一个请求优化的代码:
并且这里有四种编译场景:
一旦我查找常量
0xface
,我发现它存在于非优化版本中:并且在优化版本中进行了优化:
整个 foo 调用消失了:
For over-concerned users like my self, here is a code begging for optimization:
And Here are four compilation scenarios:
Once I look for the constant
0xface
, I see it exists in the non optimized versions:and optimized out in the optimized versions:
The whole foo call is gone: