GCC标准优化行为

sta*_*icx 7 c performance gcc execution-time compiler-optimization

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

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

当我将-O2标志替换为在-O2 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Optimize-Options级别中GCC manuel中定义的选项列表. html#Optimize-Options就像这样:

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
Run Code Online (Sandbox Code Playgroud)

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

UPDATE

如果(根据GCC文件):

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

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

例如"Acovea" http://hg.ahs3.net/acovea/debian/html/acoveaga.html

和"科尔" http://users.elis.ugent.be/~leeckhou/papers/cgo08.pdf

Gro*_*mph -3

有两个好的优化应该知道:

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