diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-09-26 22:20:53 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-10-14 20:23:50 +0200 |
commit | 5f05ff081f391fd482e3a5c3ea9f191c6961c42e (patch) | |
tree | ef0d973914d5ad98438eee3e1bf3fe0e6d04f98c /llvm/lib/Analysis/BasicAliasAnalysis.cpp | |
parent | 0a869ef3a844b3fcb64c5a1d9c7a5d4988b00c07 (diff) | |
download | llvm-5f05ff081f391fd482e3a5c3ea9f191c6961c42e.zip llvm-5f05ff081f391fd482e3a5c3ea9f191c6961c42e.tar.gz llvm-5f05ff081f391fd482e3a5c3ea9f191c6961c42e.tar.bz2 |
[BasicAA] Improve scalable vector handling
Currently, DecomposeGEP() bails out on the whole decomposition if
it encounters a scalable GEP type anywhere. However, it is fine to
still analyze other GEPs that we look through before hitting the
scalable GEP. This does mean that the decomposed GEP base is no
longer required to be the same as the underlying object. However,
I don't believe this property is necessary for correctness anymore.
This allows us to compute slightly more precise aliasing results
for GEP chains containing scalable vectors, though my primary
interest here is simplifying the code.
Differential Revision: https://reviews.llvm.org/D110511
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 69f5cf0..7d782cb 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -83,8 +83,7 @@ STATISTIC(SearchTimes, "Number of times a GEP is decomposed"); const unsigned MaxNumPhiBBsValueReachabilityCheck = 20; // The max limit of the search depth in DecomposeGEPExpression() and -// getUnderlyingObject(), both functions need to use the same search -// depth otherwise the algorithm in aliasGEP will assert. +// getUnderlyingObject(). static const unsigned MaxLookupSearchDepth = 6; bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA, @@ -494,8 +493,6 @@ struct BasicAAResult::DecomposedGEP { APInt Offset; // Scaled variable (non-constant) indices. SmallVector<VariableGEPIndex, 4> VarIndices; - // Is GEP index scale compile-time constant. - bool HasCompileTimeConstantScale; // Are all operations inbounds GEPs or non-indexing operations? // (None iff expression doesn't involve any geps) Optional<bool> InBounds; @@ -513,8 +510,7 @@ struct BasicAAResult::DecomposedGEP { OS << ", "; VarIndices[i].print(OS); } - OS << "], HasCompileTimeConstantScale=" << HasCompileTimeConstantScale - << ")"; + OS << "])"; } }; @@ -526,11 +522,6 @@ struct BasicAAResult::DecomposedGEP { /// in the VarIndices vector) are Value*'s that are known to be scaled by the /// specified amount, but which may have other unrepresented high bits. As /// such, the gep cannot necessarily be reconstructed from its decomposed form. -/// -/// This function is capable of analyzing everything that getUnderlyingObject -/// can look through. To be able to do that getUnderlyingObject and -/// DecomposeGEPExpression must use the same search depth -/// (MaxLookupSearchDepth). BasicAAResult::DecomposedGEP BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, AssumptionCache *AC, DominatorTree *DT) { @@ -542,7 +533,6 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, unsigned MaxPointerSize = DL.getMaxPointerSizeInBits(); DecomposedGEP Decomposed; Decomposed.Offset = APInt(MaxPointerSize, 0); - Decomposed.HasCompileTimeConstantScale = true; do { // See if this is a bitcast or GEP. const Operator *Op = dyn_cast<Operator>(V); @@ -605,7 +595,6 @@ BasicAAResult::DecomposeGEPExpression(const Value *V, const DataLayout &DL, // constant. if (isa<ScalableVectorType>(GEPOp->getSourceElementType())) { Decomposed.Base = V; - Decomposed.HasCompileTimeConstantScale = false; return Decomposed; } @@ -1145,16 +1134,10 @@ AliasResult BasicAAResult::aliasGEP( DecomposedGEP DecompGEP1 = DecomposeGEPExpression(GEP1, DL, &AC, DT); DecomposedGEP DecompGEP2 = DecomposeGEPExpression(V2, DL, &AC, DT); - // Don't attempt to analyze the decomposed GEP if index scale is not a - // compile-time constant. - if (!DecompGEP1.HasCompileTimeConstantScale || - !DecompGEP2.HasCompileTimeConstantScale) + // Bail if we were not able to decompose anything. + if (DecompGEP1.Base == GEP1 && DecompGEP2.Base == V2) return AliasResult::MayAlias; - assert(DecompGEP1.Base == UnderlyingV1 && DecompGEP2.Base == UnderlyingV2 && - "DecomposeGEPExpression returned a result different from " - "getUnderlyingObject"); - // Subtract the GEP2 pointer from the GEP1 pointer to find out their // symbolic difference. subtractDecomposedGEPs(DecompGEP1, DecompGEP2); |