aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LoopAccessAnalysis.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-08-16 12:52:57 +0200
committerGitHub <noreply@github.com>2024-08-16 12:52:57 +0200
commit6a84af704f57defd919a4ec2e34b70a48d548719 (patch)
tree6cecfcf1e2167704d9c1196cb7543e746217f5ce /llvm/lib/Analysis/LoopAccessAnalysis.cpp
parent65390f9d6f0aa5f7bc5125d73337eb658e162d0a (diff)
downloadllvm-6a84af704f57defd919a4ec2e34b70a48d548719.zip
llvm-6a84af704f57defd919a4ec2e34b70a48d548719.tar.gz
llvm-6a84af704f57defd919a4ec2e34b70a48d548719.tar.bz2
[LAA] Use computeConstantDifference() (#103725)
Use computeConstantDifference() instead of casting getMinusSCEV() to SCEVConstant. This can be much faster in some cases, because computeConstantDifference() computes the result without creating new SCEV expressions. This improves LTO/ThinLTO compile-time for lencod by more than 10%. I've verified that computeConstantDifference() does not produce worse results than the previous code for anything in llvm-test-suite. This required raising the iteration cutoff to 6. I ended up increasing it to 8 just to be on the safe side (for code outside llvm-test-suite), and because this doesn't materially affect compile-time anyway (we'll almost always bail out earlier).
Diffstat (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/LoopAccessAnalysis.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index d67fd79..872bc52 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -412,12 +412,10 @@ bool RuntimePointerChecking::needsChecking(
/// Return nullptr in case we couldn't find an answer.
static const SCEV *getMinFromExprs(const SCEV *I, const SCEV *J,
ScalarEvolution *SE) {
- const SCEV *Diff = SE->getMinusSCEV(J, I);
- const SCEVConstant *C = dyn_cast<const SCEVConstant>(Diff);
-
- if (!C)
+ std::optional<APInt> Diff = SE->computeConstantDifference(J, I);
+ if (!Diff)
return nullptr;
- return C->getValue()->isNegative() ? J : I;
+ return Diff->isNegative() ? J : I;
}
bool RuntimeCheckingPtrGroup::addPointer(
@@ -1599,11 +1597,11 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA,
// Otherwise compute the distance with SCEV between the base pointers.
const SCEV *PtrSCEVA = SE.getSCEV(PtrA);
const SCEV *PtrSCEVB = SE.getSCEV(PtrB);
- const auto *Diff =
- dyn_cast<SCEVConstant>(SE.getMinusSCEV(PtrSCEVB, PtrSCEVA));
+ std::optional<APInt> Diff =
+ SE.computeConstantDifference(PtrSCEVB, PtrSCEVA);
if (!Diff)
return std::nullopt;
- Val = Diff->getAPInt().getSExtValue();
+ Val = Diff->getSExtValue();
}
int Size = DL.getTypeStoreSize(ElemTyA);
int Dist = Val / Size;