[llvm-dev] invariant.load metadata semantics

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 30 16:53:18 PDT 2016


Hi Geoff,

Geoff Berry wrote:
 > I believe the following is a reasonable attempt at boiling down this
 > discussion. It does allow stores of the same value. It avoids the dead
 > invariant.load issue Sanjoy brought up. It does not allow final stores
 > of a different value, the issue Hal most recently brought up in this
 > thread:
 >
 > If a load instruction tagged with the ``!invariant.load`` metadata is
 > executed, the optimizer may assume the memory location referenced by the
 > load contains the same value at all points in the program where the
 > memory location is known to be dereferenceable.

This seems fine, but it does disallow introduction of dead stores.
That is, given:

void f() {
   %x = calloc()
   call void @g(nocapture %x)
}

we cannot transform it to

void f() {
   %x = calloc()
   *(%x) = 100
   *(%x) = 0
   call void @g(nocapture %x)
}

(after proving that %x is not visible to other threads), since @g
could have invariant loads from %x.

I don't have a good way of avoiding this issue, but given that the
transform above does not seem very useful I'm inclined to say the
definition above is okay for now.

-- Sanjoy


More information about the llvm-dev mailing list