[BasicAA] Try to disambiguate GEPs through arrays of structs into
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Sat, 7 Feb 2015 17:04:29 +0000 (17:04 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Sat, 7 Feb 2015 17:04:29 +0000 (17:04 +0000)
commit9c252165a7b49b61a092aa82306bf731bfaccb7e
treeec060e40627fcc3458ffb9195bc9feacd4e856fa
parent0e0271af87f722389f5aee96185c54cb714940a9
[BasicAA] Try to disambiguate GEPs through arrays of structs into
different fields.

We can show that two GEPs off of the same (possibly multidimensional)
array of structs, into different fields, can't alias.  Quoting:

For two GEPOperators GEP1 and GEP2, if we find that:
- both GEPs begin indexing from the exact same pointer;
- the last indices in both GEPs are constants, indexing into a struct;
- said indices are different, hence,the pointed-to fields are different;
- and both GEPs only index through arrays prior to that;

this lets us determine that the struct that GEP1 indexes into and the
struct that GEP2 indexes into must either precisely overlap or be
completely disjoint.  Because they cannot partially overlap, indexing
into different non-overlapping fields of the struct will never alias.

The other BasicAA::aliasGEP rules worked in some cases, but not all
(for example, the i32x3 struct in the testcase).
We can add this simple ad-hoc rule to complement them.

rdar://19717375
Differential Revision: http://reviews.llvm.org/D7453

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228498 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/BasicAliasAnalysis.cpp
test/Analysis/BasicAA/struct-geps.ll [new file with mode: 0644]