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

Piotr Padlewski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 14:25:38 PDT 2017


Prazek added a comment.

In https://reviews.llvm.org/D18738#728216, @sanjoy wrote:

> 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.


Yep, this is a very good example. I will think about some solutions


Repository:
  rL LLVM

https://reviews.llvm.org/D18738





More information about the llvm-commits mailing list