本文介绍了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 之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 08:58