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

Piotr Padlewski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 11:05:39 PDT 2017


Prazek added a comment.

I think we already have the same type of optimization and it is fine. Consider:

  i8 foo(i8* dereferenceable(8) %p) {
    %v = load i8, i8* %p
    ret i8 %v
  }

Now if you have code like:

  void main(i8* %p) {
  
  }
   

you can argue that you could transform it into:

  void main(i8* %p) {
    if (false) {
       call foo(i8* %p)
    }
  }

resulting in possibility of hoisting the load of %p from foo based on dereferenceable(8) attribute. 
I would argue that this transformation is invalid, because you are introducing new information about the %p that wasn't there.
The same thing applies to the metadata.

Beside the discussion, my comment about the patch would be to instead of adding new metadata, to store that information inside of it.
The problem I see is that I would like to have unconditional !invariant.load, invariant.group and !dereferenceable to mark it on vtable loads and virtual function loads,
which are known to be dereferenceable and invariant.laod (for vfunction loads) unconditionally.

I was imaging it as adding string to metadata like:
!0 = !{i64 8, "Unconditionally"} or "NonLocalProperty" or "GlobalProperty" or whathever.
This way it would scale better for any metadata (someone would also like to mark nonnull and other), and we could just drop only conditional metadata.
You can check out the discussion I started on mailing list  http://lists.llvm.org/pipermail/llvm-dev/2017-April/111684.html


Repository:
  rL LLVM

https://reviews.llvm.org/D18738





More information about the llvm-commits mailing list