On Apr 28, 2008, at 12:04 PM, Diego Novillo wrote:
[ Apologies if this comes out twice. I posted this message last week,
but I think it was rejected because of a .pdf attachment. ]
We have been bouncing ideas for a new mechanism to describe the
behavior
of function calls so that optimizers can be more aggressive at call
sites. Currently, GCC supports the notion of pure/impure,
const/non-const, but that is not enough for various cases.
The main application for this would be stable library code like libc,
that the compiler generally doesn't get to process.
This is very interesting. One issue to consider: how do you plan to
handle errno? There are a variety of compiler transformations that
can be done on libm functions, even in the presence of errno. For an
example (which occurs in spec2k), it is safe to transform:
for (i = 0 .. 100)
Val += i*sqrt(loopinvariant)
into:
tmp = sqrt(loopinvariant)
for (i = 0 .. 100)
Val += i*tmp
This is safe because errno will still be set and the value that errno
is set to is a function of the input value. Also, the value of errno
is not otherwise changed in the body of the loop. Note that sqrt is
not pure or const here because it sets errno.
The wrinkle is "detecting that the loop body doesn't set errno". On
many platforms, errno is a #define for something like
"*__errno_func()". How do you plan to model this?
-Chris