[llvm-dev] Attribute for a invariant function ?

Joerg Sonnenberger via llvm-dev llvm-dev at lists.llvm.org
Sat Jan 9 07:12:54 PST 2016


On Sat, Jan 09, 2016 at 03:00:33PM -0000, Martin J. O'Riordan via llvm-dev wrote:
> I use '__attribute__((pure))' for fast math functions and some other
> intrinsic function I have added such as getting the current core ID.  This
> tells the compiler that calling the same function with the same arguments
> will always return the same value.  A function declared with this attribute
> is not supposed to have any side-effects such as altering global variables.

I am considering a similar use case, which strictly speaking is not a
valid use of pure. Consider the xlocale interface:

l = newlocale(...);

if (isalpha_l(c, l))
   ....
foo();

if (isalpha_l(c, l))
   ....

freelocale(l);

The call to isalpha_l is redundant, but the value depends on l within
the life time -- strictly speaking with pure, the compiler could
remember the value of l and use a cached value accordingly.

Joerg


More information about the llvm-dev mailing list