[PATCH] D20665: Claim NoAlias if two GEPs index different fields of the same struct

Taewook Oh via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 09:25:51 PDT 2016

twoh added inline comments.

Comment at: lib/Analysis/BasicAliasAnalysis.cpp:841
@@ +840,3 @@
+  // If both GEP1 and GEP2 have the inbounds keyword but index different fields
+  // of the same struct, they do not alias
+  if (GEP1->isInBounds() && GEP2->isInBounds()) {
dberlin wrote:
> mcrosier wrote:
> > Please add a period.
> This loop never verifies they are the same struct, just A struct.
> They have to be the same struct, otherwise it is entirely possible for them to be different structs, and be at (offset,size) that conflict.
> In general, your entire calculation is essentially trying to figure out (offset, size)  of the entire set of accesses.
> It happens that, for the same struct, you can guarantee that if they go to different (offset, size) they can't alias (because you can't really overlay the structs in a different way).
> But this is not, in general, true because you don't know where they are really starting from unless you see the allocation site (IE this could be a gep of a gep of a gep of a ...)
@dberlin Thank you for your comment. This loop is invoked only when the pointer operand of GEP1 and GEP2 are same (there is an assertion above). Doesn't this guarantee that they are starting from the same point regardless of their allocation site? The logic is that if two GEPs sharing the same base pointer access through the same index until index 'i-1' but have a different value at index 'i', and if the index typed at index 'i-1' is a struct, then at index 'i' they access two different fields of the same struct (I assumed 'same struct' because two GEPs share the same pointer operand and same index until 'i-1'). 


More information about the llvm-commits mailing list