When compiling the code below with gcc -o3 it takes around 50% longer time than without the "-o3". What can be the reason for that?
const int stepsize = 2;
for (j = 0; j < NOOFITERATIONS; j++) {
for(i=0; i < ROUND_DOWN(SOMEBIGSIZE, stepsize); i+=stepsize) {
c[i] = a[i] + b[i];
c[i+1] = a[i+1] + b[i+1];
}
for(; i < SOMEBIGSIZE; i++)
c[i] = a[i] + b[i];
}
Taken from the GCC docs (all emphasis mine):
Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program. [...]
Optimizing compilation takes somewhat more time , and a lot more memory for a large function.
With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time .
This is completely expected behavior. Basically, your compiler needs to do more work for you, which increases the compilation time.
From the Optimize Options -
Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-loop-vectorize, -ftree-slp-vectorize, -fvect-cost-model, -ftree-partial-pre and -fipa-cp-clone options.
My assumption is those are expensive optimizations with your loops... especially the loop vectorize optimization.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.