g++ optimizer and numerical computations

Jason Merrill jason@cygnus.com
Mon Feb 16 14:21:00 GMT 1998


>>>>> Marc Espie <Marc.Espie@liafa.jussieu.fr> writes:

> - the refcnt test occurs inside the loop. It has not been moved outside
> the loop by the compiler.
> - the exceptional case (refcnt != 1) is inside the loop, and the normal
> case (refcnt == 1) is coded as a forward conditional branch, predicted
> to fall through (alpha architecture handbook).  

Both of these are very difficult optimizations for a compiler to perform;
for the first one, the compiler needs to determine that nothing in the loop
could modify refcnt, so it only needs to be checked once.  That requires
data flow analysis on memory, which gcc does not perform, especially in the
presence of calls.

The second optimization would require the compiler to know what the normal
case is.  Try reversing the sense of the if, and see if that gives you
better code, i.e.

		if (value->cnt == 1)
 		  return value->data[i];

That also avoids writing over refcnt in this case.

Jason



More information about the Gcc mailing list