GCC编译器优化选项

Jor*_*orj 1 c gcc

我试图用gcc优化C代码.如果我使用-O1选项将有更好的运行时间,但如果我使用等效

  -fauto-inc-dec 
  -fcompare-elim 
  -fcprop-registers 
  -fdce 
  -fdefer-pop 
  -fdelayed-branch 
  -fdse 
  -fguess-branch-probability 
  -fif-conversion2 
  -fif-conversion 
  -fipa-pure-const 
  -fipa-profile 
  -fipa-reference 
  -fmerge-constants
  -fsplit-wide-types 
  -ftree-bit-ccp 
  -ftree-builtin-call-dce 
  -ftree-ccp 
  -ftree-ch 
  -ftree-copyrename 
  -ftree-dce 
  -ftree-dominator-opts 
  -ftree-dse 
  -ftree-forwprop 
  -ftree-fre 
  -ftree-phiprop 
  -ftree-slsr 
  -ftree-sra 
  -ftree-pta 
  -ftree-ter 
  -funit-at-a-time
Run Code Online (Sandbox Code Playgroud)

它就像我没有使用任何选项标志.GCC版本是4.8.2.拜托,谁能解释一下为什么?我刚刚发现这些标志的顺序很重要,但我没有找到-O1中的顺序.

Dav*_*ave 8

根据文件,

仅当在命令行上设置-O级别时,才会启用大多数优化.否则,即使指定了单独的优化标志,它们也会被禁用.

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html(强调我的)


当它继续列出您可以设置的特定标志时,它会注意到:

在需要执行"优化"优化的极少数情况下,可以使用以下标志.

这很清楚,他们不希望您制作一套完全自定义的优化选项,而是选择最适合您的方案的一般级别(这取决于您当前是否正在调试,运送等) ,然后微调你的代码受益于打开或关闭的任何标志.