diff options
author | Florian Hahn <flo@fhahn.com> | 2024-06-04 12:12:29 +0100 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2024-06-04 12:12:29 +0100 |
commit | fc5254c8ac02d29e7daab4ecce42cb5a82c8b3a2 (patch) | |
tree | 6986a28a329077e06a6f9c6e44a6f100ce0105e9 /llvm | |
parent | 9372e1a7f12ab1bce4bf6303657e193fc0283a6e (diff) | |
download | llvm-fc5254c8ac02d29e7daab4ecce42cb5a82c8b3a2.zip llvm-fc5254c8ac02d29e7daab4ecce42cb5a82c8b3a2.tar.gz llvm-fc5254c8ac02d29e7daab4ecce42cb5a82c8b3a2.tar.bz2 |
[LoopUtils] Simplify code for runtime check generation a bit (NFCI).
Store getSE result in variable to re-use and use structured bindings
when looping over bounds.
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index cc883a7..de3eb4a 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1743,16 +1743,16 @@ static PointerBounds expandBounds(const RuntimeCheckingPtrGroup *CG, auto *HighAR = cast<SCEVAddRecExpr>(High); auto *LowAR = cast<SCEVAddRecExpr>(Low); const Loop *OuterLoop = TheLoop->getParentLoop(); - const SCEV *Recur = LowAR->getStepRecurrence(*Exp.getSE()); - if (Recur == HighAR->getStepRecurrence(*Exp.getSE()) && + ScalarEvolution &SE = *Exp.getSE(); + const SCEV *Recur = LowAR->getStepRecurrence(SE); + if (Recur == HighAR->getStepRecurrence(SE) && HighAR->getLoop() == OuterLoop && LowAR->getLoop() == OuterLoop) { BasicBlock *OuterLoopLatch = OuterLoop->getLoopLatch(); - const SCEV *OuterExitCount = - Exp.getSE()->getExitCount(OuterLoop, OuterLoopLatch); + const SCEV *OuterExitCount = SE.getExitCount(OuterLoop, OuterLoopLatch); if (!isa<SCEVCouldNotCompute>(OuterExitCount) && OuterExitCount->getType()->isIntegerTy()) { - const SCEV *NewHigh = cast<SCEVAddRecExpr>(High)->evaluateAtIteration( - OuterExitCount, *Exp.getSE()); + const SCEV *NewHigh = + cast<SCEVAddRecExpr>(High)->evaluateAtIteration(OuterExitCount, SE); if (!isa<SCEVCouldNotCompute>(NewHigh)) { LLVM_DEBUG(dbgs() << "LAA: Expanded RT check for range to include " "outer loop in order to permit hoisting\n"); @@ -1760,7 +1760,7 @@ static PointerBounds expandBounds(const RuntimeCheckingPtrGroup *CG, Low = cast<SCEVAddRecExpr>(Low)->getStart(); // If there is a possibility that the stride is negative then we have // to generate extra checks to ensure the stride is positive. - if (!Exp.getSE()->isKnownNonNegative(Recur)) { + if (!SE.isKnownNonNegative(Recur)) { Stride = Recur; LLVM_DEBUG(dbgs() << "LAA: ... but need to check stride is " "positive: " @@ -1821,8 +1821,7 @@ Value *llvm::addRuntimeChecks( // Our instructions might fold to a constant. Value *MemoryRuntimeCheck = nullptr; - for (const auto &Check : ExpandedChecks) { - const PointerBounds &A = Check.first, &B = Check.second; + for (const auto &[A, B] : ExpandedChecks) { // Check if two pointers (A and B) conflict where conflict is computed as: // start(A) <= end(B) && start(B) <= end(A) @@ -1880,14 +1879,14 @@ Value *llvm::addDiffRuntimeChecks( // Map to keep track of created compares, The key is the pair of operands for // the compare, to allow detecting and re-using redundant compares. DenseMap<std::pair<Value *, Value *>, Value *> SeenCompares; - for (const auto &C : Checks) { - Type *Ty = C.SinkStart->getType(); + for (const auto &[SrcStart, SinkStart, AccessSize, NeedsFreeze] : Checks) { + Type *Ty = SinkStart->getType(); // Compute VF * IC * AccessSize. auto *VFTimesUFTimesSize = ChkBuilder.CreateMul(GetVF(ChkBuilder, Ty->getScalarSizeInBits()), - ConstantInt::get(Ty, IC * C.AccessSize)); - Value *Diff = Expander.expandCodeFor( - SE.getMinusSCEV(C.SinkStart, C.SrcStart), Ty, Loc); + ConstantInt::get(Ty, IC * AccessSize)); + Value *Diff = + Expander.expandCodeFor(SE.getMinusSCEV(SinkStart, SrcStart), Ty, Loc); // Check if the same compare has already been created earlier. In that case, // there is no need to check it again. @@ -1898,7 +1897,7 @@ Value *llvm::addDiffRuntimeChecks( IsConflict = ChkBuilder.CreateICmpULT(Diff, VFTimesUFTimesSize, "diff.check"); SeenCompares.insert({{Diff, VFTimesUFTimesSize}, IsConflict}); - if (C.NeedsFreeze) + if (NeedsFreeze) IsConflict = ChkBuilder.CreateFreeze(IsConflict, IsConflict->getName() + ".fr"); if (MemoryRuntimeCheck) { |