According to an old slide about predictive commoning
, one can say that
for(int i=0; i < n; i++)
f[i]= a[i]*exp(i+1)+a[i+1]*exp(i+2);
is equivalent to
double p0=a[0]*exp(1);
int i;
for (i=0; i < n-n%2; i+=2)
{
double p1=a[i+1]*exp(i+2);
f[i] = p0+p1;
p0=a[i+2]*exp(i+3);
f[i+1] = p1+p0;
}
for (; i < n; i++)
f[i] = a[i]*exp(i+1)+a[i+1]*exp(i+2);
except for the second code is more optimized (Benchmark).
I have tested gcc
with the highest optimization level -O3
and yet I cannot see gcc
performing such optimization.
(Even worse these two example A and B)
How can I force gcc
to perform such an optimization?