[BasicAA] Handle two unknown sizes for GEPs
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 1 Dec 2020 17:06:37 +0000 (18:06 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 11 Dec 2020 17:45:53 +0000 (18:45 +0100)
commit8b1c4e310c2f9686cad925ad81d8e2be10a1ef3c
treea4e0840ba41758c69639daebc790d2f879abc675
parenta5f5612263ca650ae0aa433539278c2d5f567cf8
[BasicAA] Handle two unknown sizes for GEPs

If we have two unknown sizes and one GEP operand and one non-GEP
operand, then we currently simply return MayAlias. The comment says
we can't do anything useful ... but we can! We can still check that
the underlying objects are different (and do so for the GEP-GEP case).

To reduce the compile-time impact, this a) checks this early, before
doing the relatively expensive GEP decomposition that will not be
used and b) doesn't do the check if the other operand is a phi or
select. In that case, the phi/select will already recurse, so this
would just do two slightly different recursive walks that arrive at
the same roots.

Compile-time is still a bit of a mixed bag: https://llvm-compile-time-tracker.com/compare.php?from=624af932a808b363a888139beca49f57313d9a3b&to=845356e14adbe651a553ed11318ddb5e79a24bcd&stat=instructions
On average this is a small improvement, but sqlite with ThinLTO has
a 0.5% regression (lencod has a 1% improvement).

The BasicAA test case checks this by using two memsets with unknown
size. However, the more interesting case where this is useful is
the LoopVectorize test case, as analysis of accesses in loops tends
to always us unknown sizes.

Differential Revision: https://reviews.llvm.org/D92401
llvm/lib/Analysis/BasicAliasAnalysis.cpp
llvm/test/Analysis/BasicAA/phi-aa.ll
llvm/test/Analysis/BasicAA/recphi.ll
llvm/test/Transforms/LoopVectorize/ARM/pointer_iv.ll
llvm/test/Transforms/LoopVersioning/exit-block-dominates-rt-check-block.ll