From: Philip Reames Date: Fri, 29 Mar 2019 23:06:57 +0000 (+0000) Subject: [LoopPredication] Use the builder's insertion point everywhere [NFC] X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0871289fd9ecb47bf35d231cfd7e5ef22a9561f6;p=llvm [LoopPredication] Use the builder's insertion point everywhere [NFC] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357330 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/LoopPredication.cpp b/lib/Transforms/Scalar/LoopPredication.cpp index eef048ec36b..250f6e259af 100644 --- a/lib/Transforms/Scalar/LoopPredication.cpp +++ b/lib/Transforms/Scalar/LoopPredication.cpp @@ -265,8 +265,8 @@ class LoopPredication { bool CanExpand(const SCEV* S); Value *expandCheck(SCEVExpander &Expander, IRBuilder<> &Builder, - ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, - Instruction *InsertAt); + ICmpInst::Predicate Pred, const SCEV *LHS, + const SCEV *RHS); Optional widenICmpRangeCheck(ICmpInst *ICI, SCEVExpander &Expander, IRBuilder<> &Builder); @@ -389,7 +389,7 @@ LoopPredication::parseLoopICmp(ICmpInst::Predicate Pred, Value *LHS, Value *LoopPredication::expandCheck(SCEVExpander &Expander, IRBuilder<> &Builder, ICmpInst::Predicate Pred, const SCEV *LHS, - const SCEV *RHS, Instruction *InsertAt) { + const SCEV *RHS) { // TODO: we can check isLoopEntryGuardedByCond before emitting the check Type *Ty = LHS->getType(); @@ -398,6 +398,7 @@ Value *LoopPredication::expandCheck(SCEVExpander &Expander, if (SE->isLoopEntryGuardedByCond(L, Pred, LHS, RHS)) return Builder.getTrue(); + Instruction *InsertAt = &*Builder.GetInsertPoint(); Value *LHSV = Expander.expandCodeFor(LHS, Ty, InsertAt); Value *RHSV = Expander.expandCodeFor(RHS, Ty, InsertAt); return Builder.CreateICmp(Pred, LHSV, RHSV); @@ -469,12 +470,11 @@ Optional LoopPredication::widenICmpRangeCheckIncrementingLoop( LLVM_DEBUG(dbgs() << "LHS: " << *LatchLimit << "\n"); LLVM_DEBUG(dbgs() << "RHS: " << *RHS << "\n"); LLVM_DEBUG(dbgs() << "Pred: " << LimitCheckPred << "\n"); - - Instruction *InsertAt = Preheader->getTerminator(); + auto *LimitCheck = - expandCheck(Expander, Builder, LimitCheckPred, LatchLimit, RHS, InsertAt); + expandCheck(Expander, Builder, LimitCheckPred, LatchLimit, RHS); auto *FirstIterationCheck = expandCheck(Expander, Builder, RangeCheck.Pred, - GuardStart, GuardLimit, InsertAt); + GuardStart, GuardLimit); return Builder.CreateAnd(FirstIterationCheck, LimitCheck); } @@ -504,13 +504,12 @@ Optional LoopPredication::widenICmpRangeCheckDecrementingLoop( // guardStart u< guardLimit && // latchLimit 1. // See the header comment for reasoning of the checks. - Instruction *InsertAt = Preheader->getTerminator(); auto LimitCheckPred = ICmpInst::getFlippedStrictnessPredicate(LatchCheck.Pred); auto *FirstIterationCheck = expandCheck(Expander, Builder, ICmpInst::ICMP_ULT, - GuardStart, GuardLimit, InsertAt); + GuardStart, GuardLimit); auto *LimitCheck = expandCheck(Expander, Builder, LimitCheckPred, LatchLimit, - SE->getOne(Ty), InsertAt); + SE->getOne(Ty)); return Builder.CreateAnd(FirstIterationCheck, LimitCheck); } @@ -607,7 +606,8 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl &Checks, } if (ICmpInst *ICI = dyn_cast(Condition)) { - if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander, Builder)) { + if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander, + Builder)) { Checks.push_back(NewRangeCheck.getValue()); NumWidened++; continue;