<div dir="ltr">Can someone clarify on this please?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 28 Nov 2019 at 21:58, Venkataramanan Kumar <<a href="mailto:venkataramanan.kumar.llvm@gmail.com">venkataramanan.kumar.llvm@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">TBAA Question. <br><br>Please consider the following test case.<br><br>---Snip--<br>struct B {<br>  int b1;<br>  int b2;<br>};<br><br>struct C {<br> int b1;<br>};<br><br>struct A {<br> int a1;<br> struct C SC;<br> int a2;<br>};<br><br>int foo1(struct A * Aptr, struct B* Bptr)<br>{<br>   int *a = &Aptr->SC.b1;<br>   *a=10;<br>   Bptr->b1 = 11;<br>   return *a;<br>}<br><br>int foo2(struct A * Aptr, struct B* Bptr)<br>{<br>   Aptr->SC.b1=10;<br>   Bptr->b1 = 11;<br>   return Aptr->SC.b1;<br>}<br>---Snip--<br><br>The structure pointers "Aptr" and "Bptr" will not alias each other in both the functions.<br>TBAA is able to figure that out in the case of "foo2". Hence it could propagate the  value "10" directly for return in "foo2".<br><br>--IR snippet ---<br><br>; Function Attrs: nounwind uwtable<br>define dso_local i32 @foo1(%struct.A* %Aptr, %struct.B* %Bptr) local_unnamed_addr #0 {<br>entry:<br>  %b1 = getelementptr inbounds %struct.A, %struct.A* %Aptr, i64 0, i32 1, i32 0<br>  store i32 10, i32* %b1, align 4, !tbaa !2<br>  %b11 = getelementptr inbounds %struct.B, %struct.B* %Bptr, i64 0, i32 0<br>  store i32 11, i32* %b11, align 4, !tbaa !6<br>  %0 = load i32, i32* %b1, align 4, !tbaa !2 <== reloads from memory.<br>  ret i32 %0<br>}<br><br>; Function Attrs: nounwind uwtable<br>define dso_local i32 @foo2(%struct.A* %Aptr, %struct.B* %Bptr) local_unnamed_addr #0 {<br>entry:<br>  %b1 = getelementptr inbounds %struct.A, %struct.A* %Aptr, i64 0, i32 1, i32 0<br>  store i32 10, i32* %b1, align 4, !tbaa !8<br>  %b11 = getelementptr inbounds %struct.B, %struct.B* %Bptr, i64 0, i32 0<br>  store i32 11, i32* %b11, align 4, !tbaa !6<br>  ret i32 10 <== returns 10 <br>}<br>---IR snippet ---<br><br>I assume for both cases there is no possibility of memory aliasing. is my assumption wrong?<br>Why we are not optimizing the return for function "foo1"?  is that because TBAA is not formed in that case?<br><br>Please clarify.<br><br>regards,<br>Venkat.<br></div>
</blockquote></div>