[PATCH] D31539: Hoisting invariant.group in LICM

Piotr Padlewski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 2 14:03:21 PDT 2017


Prazek added a comment.

In https://reviews.llvm.org/D31539#716345, @sanjoy wrote:

> Hi Piotr,
>
> Won't this patch allow a situation like this:
>
>   for (;;) {
>     vtable = load ptr0, !invariant.group
>     use(vtable)
>     store new vtable to ptr0
>     ptr1 = barrier(ptr0)
>     // ptr1 is not used, say
>   }
>
>
> to
>
>   for (;;) {
>     store new vtable to ptr0
>     ptr1 = barrier(ptr0)
>     // ptr1 is not used, say
>   }
>   vtable = load ptr0, !invariant.group
>   use(vtable)
>
>
> ?
>
> After this, the load of `vtable` will return the newer vtable, which seems problematic.


It would, but that would mean that either the !invariant.group metadata is invalid there, or the store is storing the same value as it is loaded (so it would probably have !invariant.group
there, but it doesn't matter).
If I would unroll this loop:

  vtable.pre = load ptr0, !invariant.group
  use(vtable.pre)
  store new vtable to ptr0
  ptr1 = barrier(ptr0)
  for (;;) {
    vtable = load ptr0, !invariant.group
    use(vtable)
    store new vtable to ptr0
    ptr2 = barrier(ptr0)
    // ptr1 is not used, say
  }

Then you can clearly see that vtable.pre dominates vtable and it has the same pointer operand, so it means it has to load the same value.
Or maybe you are refering to the fact that invariant.group metadata would be preserved? If this is a case, then see my post on mailing list :)


https://reviews.llvm.org/D31539





More information about the llvm-commits mailing list