[PATCH] D18738: Add new !unconditionally_dereferenceable load instruction metadata

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 09:29:57 PDT 2017


sanjoy added a comment.

Hi Piotr,

This can show in the course of "normal" optimization as well.  Consider a function like:

  void f(void* ptr, bool is_virt) {
    if (is_virt) {
      auto* vb = (VirtBaseClass*)ptr;
      vb->v_func_call();
    }
  }
  
  void main() {
    long x;
    f(&x, false);
  }

After inlining, this will be:

  void f(void* ptr, bool is_virt) {
    if (is_virt) {
      auto* vb = (VirtBaseClass*)ptr;
      vb->v_func_call();
    }
  }
  
  void main() {
    long x;
    if (false) {
      auto* vb = (VirtBaseClass*)&x;
      vb->v_func_call();
    }
  }

The VPTR load due to the virtual call will be hoistable because it is loading from an alloca of size 8 (which is known dereferenceable).  If you had a global `!dereferenceable` on the virtual table load then the hoisted vtable load will still have the `!dereferenceable`, meaning the dependent function pointer load will also be hoisted.  But that would likely introduce a fault since you just loaded from `undef`.

I hope I made sense.


Repository:
  rL LLVM

https://reviews.llvm.org/D18738





More information about the llvm-commits mailing list