aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorPhilip Reames <listmail@philipreames.com>2020-12-05 14:05:48 -0800
committerPhilip Reames <listmail@philipreames.com>2020-12-05 14:10:21 -0800
commitbfda69416c6d0a76b40644b1b0cbc1cbca254a61 (patch)
tree51e8185c76bc6ae0de625626ab488ef1680a769d /llvm/lib/Analysis/BasicAliasAnalysis.cpp
parent13ee00d0c95a4eede96ba9520146a01930af2a0a (diff)
downloadllvm-bfda69416c6d0a76b40644b1b0cbc1cbca254a61.zip
llvm-bfda69416c6d0a76b40644b1b0cbc1cbca254a61.tar.gz
llvm-bfda69416c6d0a76b40644b1b0cbc1cbca254a61.tar.bz2
[BasicAA] Fix a bug with relational reasoning across iterations
Due to the recursion through phis basicaa does, the code needs to be extremely careful not to reason about equality between values which might represent distinct iterations. I'm generally skeptical of the correctness of the whole scheme, but this particular patch fixes one particular instance which is demonstrateable incorrect. Interestingly, this appears to be the second attempted fix for the same issue. The former fix is incomplete and doesn't address the actual issue. Differential Revision: https://reviews.llvm.org/D92694
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/BasicAliasAnalysis.cpp30
1 files changed, 9 insertions, 21 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 2fb353e..5e611a9 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1032,11 +1032,11 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call1,
/// Provide ad-hoc rules to disambiguate accesses through two GEP operators,
/// both having the exact same pointer operand.
-static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1,
- LocationSize MaybeV1Size,
- const GEPOperator *GEP2,
- LocationSize MaybeV2Size,
- const DataLayout &DL) {
+AliasResult BasicAAResult::aliasSameBasePointerGEPs(const GEPOperator *GEP1,
+ LocationSize MaybeV1Size,
+ const GEPOperator *GEP2,
+ LocationSize MaybeV2Size,
+ const DataLayout &DL) {
assert(GEP1->getPointerOperand()->stripPointerCastsAndInvariantGroups() ==
GEP2->getPointerOperand()->stripPointerCastsAndInvariantGroups() &&
GEP1->getPointerOperandType() == GEP2->getPointerOperandType() &&
@@ -1126,24 +1126,12 @@ static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1,
if (C1 && C2)
return NoAlias;
{
+ // If we're not potentially reasoning about values from different
+ // iterations, see if we can prove them inequal.
Value *GEP1LastIdx = GEP1->getOperand(GEP1->getNumOperands() - 1);
Value *GEP2LastIdx = GEP2->getOperand(GEP2->getNumOperands() - 1);
- if (isa<PHINode>(GEP1LastIdx) || isa<PHINode>(GEP2LastIdx)) {
- // If one of the indices is a PHI node, be safe and only use
- // computeKnownBits so we don't make any assumptions about the
- // relationships between the two indices. This is important if we're
- // asking about values from different loop iterations. See PR32314.
- // TODO: We may be able to change the check so we only do this when
- // we definitely looked through a PHINode.
- if (GEP1LastIdx != GEP2LastIdx &&
- GEP1LastIdx->getType() == GEP2LastIdx->getType()) {
- KnownBits Known1 = computeKnownBits(GEP1LastIdx, DL);
- KnownBits Known2 = computeKnownBits(GEP2LastIdx, DL);
- if (Known1.Zero.intersects(Known2.One) ||
- Known1.One.intersects(Known2.Zero))
- return NoAlias;
- }
- } else if (isKnownNonEqual(GEP1LastIdx, GEP2LastIdx, DL))
+ if (VisitedPhiBBs.empty() &&
+ isKnownNonEqual(GEP1LastIdx, GEP2LastIdx, DL))
return NoAlias;
}
}