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

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 11:13:54 PDT 2017


sanjoy added a comment.

In https://reviews.llvm.org/D18738#721295, @Prazek wrote:

> 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)
>     }
>   }


Yes, that needs to be legal.

> resulting in possibility of hoisting the load of %p from foo based on dereferenceable(8) attribute.

How would you justify that?  `%p` is `dereferenceable(8)` //iff// `foo(%p)` is executed.  In the above program `foo(%p)` is not executed, so `%p` is not dereferneceable (outside the `if (false)` block, inside the `if (false)` block anything is "valid" since it is dead code).

> I would argue that this transformation is invalid, because you are introducing new information about the %p that wasn't there.

I don't think you've introduced any new information that is valid outside the `if (false)` block.


Repository:
  rL LLVM

https://reviews.llvm.org/D18738





More information about the llvm-commits mailing list