[LLVMdev] Idempotent intrinsics

John McCall rjmccall at apple.com
Sat Oct 29 10:13:55 PDT 2011

On Oct 28, 2011, at 9:59 AM, Bin Zeng wrote:
> Just a quick question about the idempotence of an intrinsic function. Is 
> there a way to specify that an intrinsic function is idempotent? I am 
> trying to give as much information about the intrinsic function I added 
> to LLVM so that LLVM can do optimizations otherwise disabled. Thanks a 
> lot in advance.

Is this the mathematical definition of idempotence (f(f(x)) == f(x)) or
the programming definition of idempotence (the initial call to f() may
have side-effects, but repeat calls do not, and all calls return the
same value)?  Neither is directly modeled by IR.  The first is easy
to do with a custom optimization pass.  The second can be modeled
by readonly or readnone if you're willing to say that you don't care
whether any side-effects actually occur if the value isn't used;
otherwise it's more complicated.


More information about the llvm-dev mailing list