GCC标准优化行为

时间:2015-11-20 17:49:05

标签: c performance gcc compiler-optimization execution-time

在这里,我使用-O2优化级别(使用gcc 4.8.4)编译输入程序并测量执行时间:

gcc -O2 -c test.c -o obj.o
TIMEFORMAT='%3R' &&  time(./obj.o)
execution time = 1.825

当我将-O2标志替换为在GCC manuel中定义的选项列表 - 在{02 {} {}}级别中:

gcc -fauto-inc-dec -fcompare-elim -fcprop-registers -fdce -fdefer-pop -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 -fthread-jumps -falign-functions  -falign-jumps -falign-loops  -falign-labels -fcaller-saves -fcrossjumping -fcse-follow-jumps  -fcse-skip-blocks -fdelete-null-pointer-checks -fdevirtualize -fexpensive-optimizations -fgcse  -fgcse-lm  -fhoist-adjacent-loads -finline-small-functions -findirect-inlining -fipa-sra -foptimize-sibling-calls -fpartial-inlining -fpeephole2 -fregmove  -freorder-blocks  -freorder-functions -frerun-cse-after-loop -fsched-interblock  -fsched-spec -fschedule-insns  -fschedule-insns2 -fstrict-aliasing -fstrict-overflow -ftree-switch-conversion -ftree-tail-merge -ftree-pre -ftree-vrp -c test.c -o obj.o
    TIMEFORMAT='%3R' &&  time(./obj.o)
execution time = 2.652

我的问题是为什么即使执行时间不同,我应用了相同的优化?

更新

if(根据GCC文件):

  

并非所有优化都由标志直接控制。

那么研究人员如何使用比标准优化序列更快地再现优化序列(使用它们的进化算法) 用于生成数千个优化序列并收集它们 在执行时间方面影响最大)

作为一个例子" Acovea" https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Optimize-Options.html#Optimize-Options

和" Cole" http://hg.ahs3.net/acovea/debian/html/acoveaga.html

1 个答案:

答案 0 :(得分:-3)

应该知道2个好的优化:

  • -O2:优化空间和时间(警告:不初始化变量)
  • -Os:优化空间和时间(警告:不初始化变量)