"pure" functions"

Hi,
say I've a LLVM module with a call instruction. The called function is
"pure", that is it has no side-effects at all. How can I communicate this
to LLVM, so that the function call can be removed if the return value is
never used?

Thanks,
Volodya

There isn't a way to do this from the source code yet. However, if this is a standard library function, you can add it to the end of lib/Analysis/BasicAliasAnalysis.cpp. Search of "isspace".

-Chris

That's a bit of a hack. Can we not deduce "pure" functions
conservatively? Basically, anything that doesn't do any load or store
outside of its parameters and no malloc or free? Maybe a few other
constraints. Sounds fairly easy to deduce and might be useful for
optimization.

Reid.

That's a bit of a hack. Can we not deduce "pure" functions
conservatively?

Yes, and we do.

Basically, anything that doesn't do any load or store
outside of its parameters and no malloc or free? Maybe a few other
constraints. Sounds fairly easy to deduce and might be useful for
optimization.

We already do that, but it doesn't help for external functions (e.g. strlen).

-Chris

I see. Just another reason why *everything* should be compiled with
LLVM :slight_smile:

Reid.

Chris Lattner wrote:

Reid Spencer wrote: