Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22039

How to impose predictive commoning on gcc to perform a computation reusing

$
0
0

According to an old slide about predictive commoning, one can say that

test1.cpp

for(int i=0; i < n; i++)
    f[i]= a[i]*exp(i+1)+a[i+1]*exp(i+2);

is equivalent to

test2.cpp

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?


Viewing all articles
Browse latest Browse all 22039

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>