Missed optimization in gcc 3.4?
Martin Reinecke
martin@MPA-Garching.MPG.DE
Tue Dec 9 12:05:00 GMT 2003
Hi,
the piece of code below shows a case where the loop optimizer and/or inliner
of gcc 3.4 does a suboptimal job.
------- snip
class RNG
{
private:
unsigned int x,y,z,w;
public:
/*! initializes the generator with 1 to 4 seed values. */
RNG (unsigned int x1=123456789, unsigned int y1=362436069,
unsigned int z1=521288629, unsigned int w1=88675123)
: x(x1), y(y1), z(z1), w(w1) {}
unsigned int int_rand_uni()
{
unsigned int t = x^(x<<11);
x = y;
y = z;
z = w;
return w=(w^(w>>19))^(t^(t>>8));
}
void skip()
{
for (int m=0; m<100000000; ++m)
int_rand_uni();
}
};
int main()
{
RNG rng;
#ifdef OUTER_LOOP
for (int m=0; m<100000000; ++m)
rng.int_rand_uni();
#else
rng.skip();
#endif
return rng.int_rand_uni()%255;
}
------- snip
When compiling with -O3, the runtime of the resulting executable
is about three times as long when OUTER_LOOP is defined
than when it is undefined, despite the fact that int_rand_uni()
is inlined in both cases. Is there a way to generate the same,
efficient code in both cases, or is this an inherent limitation of
gcc's optimizer?
Thanks,
Martin
More information about the Gcc
mailing list