[PATCH] D68484: [PATCH 01/27] [noalias] LangRef: noalias intrinsics and ptr_provenance documentation.

Nuno Lopes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 31 03:25:52 PST 2022


nlopes added a comment.

In D68484#3283485 <https://reviews.llvm.org/D68484#3283485>, @jeroen.dobbelaere wrote:

>>> - the need to implement the 'based on' relationship, also in a a way that clang is producing code, where this dependency is not easily seen. The same restrict pointer usage can appear in different blocks at different places.
>>
>> You need to elaborate this a bit more, otherwise I don't understand what you mean.
>
> How would you map (before _any_ optimizations; aka, what kind of code should clang produce):
>
>   // int *p, *q,  *s,  *t;
>   {
>      int *restrict rp = p;
>      int *restrict rq = q;
>      int *restrict rs = s;
>   
>      int * based_on_rp1 = rp + index1;
>   
>      use(rp); 
>      use(based_on_rp1); // aliases with rp
>      use(rq); // only aliases with rq
>      use(rs);
>      int * based_on_something;
>      if (some_input) {
>        based_on_something = based_on_rp1;
>      } else {
>        based_on_something = rs;
>      }
>      use(based_on_something); // might alias with rs, or rp
>      int * based_on_rp2 = rp + index2;
>      use(based_on_rp2);  // aliases with rp
>      use(rp);
>      use(t); // will not alias with anything above
>    }
>    use(t+index3); // might alias with everything above

Thank you for the example. I don't see any complication because what I've proposed can handle these implicitly and leverage the LLVM's AA reasoning as-is.
So your example would be compiled to:

  %rp = call @llvm.noalias(%p)
  %rq = call @llvm.noalias(%q)
  %rs = call @llvm.noalias(%s)
  
  %based_on_rp1 = gep %rp, %index1
  
  use(%rp)
  use(%based_on_rp1)
  use(%rq)  ; only aliases with rq; LLVM gets it automatically
  use(%rs)
  
  if (some_input) {
    %based_on_something0 = %based_on_rp1
  } else {
    %based_on_something1 = %rs
  }
  %based_on_something = phi(based_on_something0, based_on_something1)
  use(based_on_something)  ; may-alias with rs, or rp
  
  %based_on_rp2 = gep %rp, index2
  use(%based_on_rp2)  ;aliases with rp
  use(%rp)
  use(%t)  ; will not alias with anything above; LLVM knows that for free
  
  call llvm.alias.end(%p, %rp)
  call llvm.alias.end(%q, %rq)
  call llvm.alias.end(%s, %rs)

The translation is pretty straightforward AFAICT. And the aliasing properties you want to establish are given for free by the current AA.

I'm sorry I'm late to the party, which I'm sure is frustrating for you, but only recently someone called my attention to this proposal and asked me to review it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68484/new/

https://reviews.llvm.org/D68484



More information about the llvm-commits mailing list