<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jun 12, 2016 at 9:31 PM, Yichao Yu <span dir="ltr"><<a href="mailto:yyc1992@gmail.com" target="_blank">yyc1992@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Mon, Jun 13, 2016 at 12:18 AM, Daniel Berlin <<a href="mailto:dberlin@dberlin.org">dberlin@dberlin.org</a>> wrote:<br>
><br>
><br>
> On Sun, Jun 12, 2016 at 9:04 PM, Yichao Yu <<a href="mailto:yyc1992@gmail.com">yyc1992@gmail.com</a>> wrote:<br>
>><br>
>> On Sun, Jun 12, 2016 at 11:48 PM, Daniel Berlin <<a href="mailto:dberlin@dberlin.org">dberlin@dberlin.org</a>><br>
>> wrote:<br>
>> ><br>
>> ><br>
>> > On Sun, Jun 12, 2016 at 8:03 PM, Yichao Yu via llvm-commits<br>
>> > <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>> >><br>
>> >> yuyichao added a comment.<br>
>> >><br>
>> >> In another word, IMHO,<br>
>> >><br>
>> >>   %v1 = load i64, i64 *%p1, !tbaa !0<br>
>> >>   %v2 = load i64, i64 *%p1, !tbaa !1<br>
>> >><br>
>> >> should be invalid IR (and the optimizer should not be allowed to create<br>
>> >> this) if `!1` and `!2` are non-aliasing tbaa node.<br>
>> ><br>
>> > Why?<br>
>> > It's entirely possible to create a language where this is a valid and<br>
>> > useful<br>
>> > lowering.<br>
>> > TBAA applies *to the load*, not to the *pointer*, and the langref says<br>
>> > nothing about it requiring it to assign consistent TBAA nodes to<br>
>> > different<br>
>> > loads of the same pointer.<br>
>> ><br>
>><br>
>> My understanding is that the tbaa metadata is used for alias analysis.<br>
><br>
> Yes<br>
><br>
>> What should be the result of the alias analysis on the two loads in<br>
>> this case?<br>
><br>
><br>
> It is valid to say no alias or must-alias.<br>
><br>
>><br>
>> Won't<br>
>> tbaa return no aliasing while some other returns always aliasing for<br>
>> this case?<br>
><br>
><br>
> Yes.<br>
> This is pretty typical.<br>
><br>
><br>
> IE in C,<br>
><br>
> int * foo;<br>
> float *bar;<br>
><br>
> *bar;<br>
> foo = (int *)bar;<br>
> *foo;<br>
><br>
> You have two loads, TBAA will say they do not alias, anything else will say<br>
> they are must-alias.<br>
<br>
</div></div>Isn't this UB with TBAA on in C?<br>
<span class=""><br></span></blockquote><div><br></div><div>Yes, it's just an example.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
><br>
><br>
> In any sane situation, aliasing must be treated as a lattice, and you take<br>
> the "best" answer.<br>
<br>
</span>But what's the "best" one?<br></blockquote><div><br></div><div>NoAlias</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
><br>
> Alias analysis results should not be confused with value equivalence (though<br>
> it is common).  MustAlias or NoAlias implies nothing about the actual<br>
> pointer value, only the abstract memory location it represents.<br>
<br>
</span>I can understand they are not equivalent but shouldn't not being the<br>
same pointer value be a necessary condition for NoAlias?</blockquote><div><br></div><div>No.  It is a safety condition most pointer analyses use when they know nothing of the language.</div><div>There are both languages and pointer analyses that know enough to say when the same pointers really do not alias.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> In another<br>
word, are the following valid?<br>
<br>
```<br>
define i64 @f1(i64 *%p0, i64 *%p1) {<br>
  store i64 0, i64 *%p0, !tbaa !0<br>
<span class="">  %v2 = load i64, i64 *%p1, !tbaa !1<br>
</span>  ret %v2<br>
}<br>
<br>
define i64 @f2(i64 *%p1) {<br>
  store i64 0, i64 *%p1, !tbaa !0<br>
<span class="">  %v2 = load i64, i64 *%p1, !tbaa !1<br>
</span>  ret %v2<br>
}<br>
<br>
%. = call i64 @f(i64 *%p, i64 *%p)<br>
```<br></blockquote><div><br></div><div>Yes, this is valid.</div><div><br></div><div>Assuming !0 and !1 are in different TBAA branches (remember, tbaa is a tree), it will give noalias.</div><div><br></div><div>This means, among other things: Absent any other ordering constraints, you are free to reorder the load and store relative to each other.</div><div><br></div><div>Depending on your interpretation of the langref, it also means you can eliminate them (because metadata is not supposed to affect semantics).</div></div></div></div>