diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-12-13 20:27:16 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-12-25 11:35:46 +0100 |
commit | b96a6ea0a94e45ede46f534c6b5319f4ffb9d986 (patch) | |
tree | 824245ba2aa9e1cb4cf0ba93fe6d197d55f3c0e7 /llvm/lib/Analysis/BasicAliasAnalysis.cpp | |
parent | 61422c8b661c506b25b5ac705cdbb2265af120d1 (diff) | |
download | llvm-b96a6ea0a94e45ede46f534c6b5319f4ffb9d986.zip llvm-b96a6ea0a94e45ede46f534c6b5319f4ffb9d986.tar.gz llvm-b96a6ea0a94e45ede46f534c6b5319f4ffb9d986.tar.bz2 |
[BasicAA] Make sure context instruction is symmetric
D71264 started using a context instruction in a computeKnownBits()
call. However, if aliasing between two GEPs is checked, then the
choice of context instruction will be different for alias(GEP1, GEP2)
and alias(GEP2, GEP1), which is not supposed to happen.
Resolve this by remembering which GEP a certain VarIndex belongs to,
and use that as the context instruction. This makes the choice of
context instruction predictable and symmetric.
It should be noted that this choice of context instruction is
non-optimal (just like the previous choice): The AA query result is
only valid at points that are reachable from *both* instructions.
Using either one of them is conservatively correct, but a larger
context may also be valid to use.
Differential Revision: https://reviews.llvm.org/D93183
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index caa0635..4a30e07 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -422,6 +422,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, // Limit recursion depth to limit compile time in crazy cases. unsigned MaxLookup = MaxLookupSearchDepth; SearchTimes++; + const Instruction *CxtI = dyn_cast<Instruction>(V); unsigned MaxPointerSize = getMaxPointerSize(DL); DecomposedGEP Decomposed; @@ -584,7 +585,7 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, Scale = adjustToPointerSize(Scale, PointerSize); if (!!Scale) { - VariableGEPIndex Entry = {Index, ZExtBits, SExtBits, Scale}; + VariableGEPIndex Entry = {Index, ZExtBits, SExtBits, Scale, CxtI}; Decomposed.VarIndices.push_back(Entry); } } @@ -1225,9 +1226,9 @@ AliasResult BasicAAResult::aliasGEP( // the Value this cycle may not hold in the next cycle. We'll just // give up if we can't determine conditions that hold for every cycle: const Value *V = DecompGEP1.VarIndices[i].V; + const Instruction *CxtI = DecompGEP1.VarIndices[i].CxtI; - KnownBits Known = - computeKnownBits(V, DL, 0, &AC, dyn_cast<Instruction>(GEP1), DT); + KnownBits Known = computeKnownBits(V, DL, 0, &AC, CxtI, DT); bool SignKnownZero = Known.isNonNegative(); bool SignKnownOne = Known.isNegative(); @@ -1755,7 +1756,7 @@ void BasicAAResult::GetIndexDifference( // If we didn't consume this entry, add it to the end of the Dest list. if (!!Scale) { - VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale}; + VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale, Src[i].CxtI}; Dest.push_back(Entry); } } |