本文介绍了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-passes 的输出,它将列出哪些 pass 是 ON 或 OFF 到 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的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-20 22:19