[PATCH] D20495: [BasicAA] An inbounds GEP and an alloca can't alias if the base of the GEP would point "below" the alloca

Michael Kuperstein via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 15:04:38 PDT 2016


mkuper created this revision.
mkuper added reviewers: nlewycky, qcolombet, hfinkel.
mkuper added subscribers: llvm-commits, davidxl, wmi, dberlin.

This is another attempt to handle situations similar to http://reviews.llvm.org/D8487 , although it won't work for that particular case (because this doesn't appear to be legal for arguments).

The basic idea is that given this code:

```
define void @struct() {
  %alloca = alloca %struct
  %alloca.i32 = bitcast %struct* %alloca to i32*
  %random = call i32* @random.i32(i32* %alloca.i32)
  %f0 = getelementptr inbounds %struct, %struct* %alloca, i32 0, i32 0
  %p1 = getelementptr inbounds i32, i32* %random, i32 1
  ret void
}
```

%f0 and %p1 can not alias.
If they did alias, then the underlying object of %p1 - and thus, of %random - must be %alloca. But that would make %random out of bounds (since it'd have a negative offset) w.r.t %alloca, and since the GEP is inbounds, we can just assume noalias. The same logic probably holds for a GlobalVariable (which isn't a GlobalAlias), but not for other identified objects, like arguments, since a negative offset from a noalias argument may still be inbounds. I'd rather do this for Alloca first, and add GV in a separate commit.

The interface is pretty ugly, perhaps wrapping the results of DecomposeGEPExpression in a class and passing that around would make it better, but I'm not entirely sure. Thoughts?

http://reviews.llvm.org/D20495

Files:
  include/llvm/Analysis/BasicAliasAnalysis.h
  lib/Analysis/BasicAliasAnalysis.cpp
  test/Analysis/BasicAA/negoffset.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20495.57989.patch
Type: text/x-patch
Size: 14521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160520/5dce5d6c/attachment-0001.bin>


More information about the llvm-commits mailing list