7
votes

Here I compile an input program with -O2 optimization level (with gcc 4.8.4) and measure the execution time:

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

and when I replace -O2 flag with the list of options that are turned on as defined in GCC manuel in the level -O2 https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Optimize-Options.html#Optimize-Options like that:

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

My question is why the execution time is different even so, I applied the same optimizations ?

UPDATE

if (according to GCC documentation):

Not all optimizations are controlled directly by a flag.

So how can researchers use to reproduce optimization sequences even faster than standard optimization sequences (using evolutionary algorithms they use to generate thousands of optimization sequences and gather those with highest impact in term of execution time)

as an example "Acovea" http://hg.ahs3.net/acovea/debian/html/acoveaga.html

and "Cole" http://users.elis.ugent.be/~leeckhou/papers/cgo08.pdf

1
There may be a more satisfying explanation, but on preemptive multitasking systems (e.g., all desktop, mobile, and server), there's always just the chance that something else was going on. Generally, people tend to run many timing tests and average them out to get more useful numbers that aren't at the mercy of your backup software :). - Linuxios
The document says Depending on the target and how GCC was configured, a slightly different set of optimizations may be enabled at each -O level than those listed here. You can invoke GCC with -Q --help=optimizers to find out the exact set of optimizations that are enabled at each level. ... have you tried -Q --help=optimizers - Shafik Yaghmour
@user2357112 -fdelayed-branch for Fortran. I don't need it. I eliminated only this option - staticx
@staticx: Fortran? I don't think there's anything language-specific about branch delay. Architecture-specific, sure - I don't think delayed branches are a thing on x86 - but maybe it's affecting something anyway. - user2357112 supports Monica
As the code is the same, your question seems pointless. Your measuring methodology is apparently wrong. Provide a minimal reproducible example - too honest for this site

1 Answers

-3
votes

There is 2 good optimization that should be know:

  • -O2: Optimize space and time (caution: does not initialize variable)
  • -Os: Optimize space and time (caution: does not initialize variable)