GCC中-O0和-O1之间的差异 [英] Differences between -O0 and -O1 in GCC

查看:535
本文介绍了GCC中-O0和-O1之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编译一些代码时,我注意到-O0和-O1之间创建的汇编程序存在很大差异.我想遍历启用/禁用优化,直到找出导致汇编程序发生某些更改的原因.

While compiling some code I noticed big differences in the assembler created between -O0 and -O1. I wanted to run through enabling/disabling optimisations until I found out what was causing a certain change in the assembler.

如果我使用-fverbose-asm来准确找出O1与O0相比启用了哪些标志,然后手动将其禁用,那么为什么生成的汇编器仍然如此巨大?即使我用O0运行gcc并手动添加fverbose-asm所说的所有已启用O1的标志,我也不会得到仅使用O1就能得到的同一汇编程序.

If I use -fverbose-asm to find out exactly which flags O1 is enabling compared to O0, and then disable them manually, why is the assembler produced still so massively different? Even if I run gcc with O0 and manually add all the flags that fverbose-asm said were enabled with O1, I don't get the same assembler that I would have got just by using O1.

除了'-f ...'和'-m ...'之外,是否还有其他可以更改的内容?

Is there anything apart from '-f...' and '-m...' that can be changed?

或者仅仅是'O1'与无法关闭的'O0'相比具有一些魔力.

Or is is just that 'O1' has some magic compared with 'O0' that cannot be turned off.

很抱歉,它与有关,在此期间减少了堆栈的使用使用GCC + ARM进行递归,但是提到它使这个问题有点难以理解.

Sorry for the crypticness - this was related to Reducing stack usage during recursion with GCC + ARM however the mention of it was making the question a bit hard to understand.

推荐答案

如果只想查看O1启用了哪些通行证,而O0则未启用通行证,则可以运行以下命令:

If all you want is to see which passes are enabled at O1 which are not enabled at O0 you could run something like:

gcc -O0 test.c -fdump-tree-all -da
ls > O0
rm -f test.c.*
gcc -O1 test.c -fdump-tree-all -da
ls > O1
diff O0 O1

使用您发现的一组标志的类似过程,将使您看到GCC在O1进行哪些不受标志控制的额外魔术传递.

A similar process, using the set of flags which you discovered, will let you see what extra magic passes not controlled by flags are undertaken by GCC at O1.

一种比较简单的方法是比较-fdump-passs的输出,该输出将列出对stderr启用或禁用的通行证.

A less messy way might be to compare the output of -fdump-passes, which will list which passes are ON or OFF to stderr.

类似这样:

gcc -O0 test.c -fdump-passes |& grep ON > O0
gcc -O1 test.c -fdump-passes |& grep ON > O1
diff O0 O1

这篇关于GCC中-O0和-O1之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆