GCC标准优化行为

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

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

当我用-O2 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Optimize-Options等级中的GCC manuel中定义的选项列表替换-O2标志时。 html #Oftimize-这样的选项 :

 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 

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

UPDATE

如果(根据GCC文件):

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

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

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

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

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

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