<br><br><div class="gmail_quote">On Thu, Oct 25, 2012 at 3:15 PM, Pranav Bhandarkar <span dir="ltr"><<a href="mailto:pranavb@codeaurora.org" target="_blank">pranavb@codeaurora.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I have the following IR code<br>
<br>
</snippet><br>
%prev = getelementptr inbounds %struct.myStruct* %node, i32 0, i32 1<br>
%1 = load %struct.myStruct** %prev, align 4, !tbaa !0<br>
%next1 = getelementptr inbounds %struct.myStruct* %1, i32 0, i32 0<br>
store %struct.myStruct* %0, %struct.myStruct** %next1, align 4, !tbaa !0<br>
%2 = load %struct.myStruct** %prev, align 4, !tbaa !<br>
</snippet><br>
<br>
myStruct is defined as<br>
<br>
struct myStruct {<br>
   struct myStruct *next;<br>
   struct myStruct *prev;<br>
};<br>
<br>
In the snippet above, %1 can be reused instead of the load for %2. The<br>
problem is that according to BasicAliasAnalysis, %prev "mayAlias"es with<br>
%next1 and so the store to %next1 clobbers %1.<br>
<br>
The point is that %next1 is (struct mysStruct * + 0) while %prev is (struct<br>
myStruct * + 4) so they should not alias. The problem is that they do not<br>
have the same base (%node and %1) but the type of the base is the same.<br>
BasicAliasAnalysis is able to distinguish between them if they  have the<br>
same base, but not the same type.  Is it wrong to get BasicAliasAnalysis to<br>
look at the type of the base pointer and take a more aggressive approach if<br>
the base pointer type is the same ? I got this impression on reading<br>
<a href="http://llvm.org/docs/LangRef.html#pointeraliasing" target="_blank">http://llvm.org/docs/LangRef.html#pointeraliasing</a> as it seems to suggest<br>
that types are not associated with memory.<br>
<br>
Can this situation be helped ?<br></blockquote><div><br></div><div>First, yes, it is wrong for AliasAnalysis implementations to trust LLVM IR types, for the most part. There's nothing in LLVM IR which would prevent you from having two myStruct instances which overlap here, sharing 4 bytes. Because of that, next really could be equal to &prev.</div>
<div><br></div><div>In theory, you could help this situation by using TBAA; you could give next and prev fields different TBAA tags to say that a store to a next field never stores to a prev field.</div><div><br></div><div>
Dan</div><div><br></div></div>