Skip to content

Commit 3d4e108

Browse files
committed
[LoopPredication] Use the builder's insertion point everywhere [NFC]
llvm-svn: 357330
1 parent 388e19f commit 3d4e108

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

llvm/lib/Transforms/Scalar/LoopPredication.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ class LoopPredication {
265265

266266
bool CanExpand(const SCEV* S);
267267
Value *expandCheck(SCEVExpander &Expander, IRBuilder<> &Builder,
268-
ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS,
269-
Instruction *InsertAt);
268+
ICmpInst::Predicate Pred, const SCEV *LHS,
269+
const SCEV *RHS);
270270

271271
Optional<Value *> widenICmpRangeCheck(ICmpInst *ICI, SCEVExpander &Expander,
272272
IRBuilder<> &Builder);
@@ -389,7 +389,7 @@ LoopPredication::parseLoopICmp(ICmpInst::Predicate Pred, Value *LHS,
389389
Value *LoopPredication::expandCheck(SCEVExpander &Expander,
390390
IRBuilder<> &Builder,
391391
ICmpInst::Predicate Pred, const SCEV *LHS,
392-
const SCEV *RHS, Instruction *InsertAt) {
392+
const SCEV *RHS) {
393393
// TODO: we can check isLoopEntryGuardedByCond before emitting the check
394394

395395
Type *Ty = LHS->getType();
@@ -398,6 +398,7 @@ Value *LoopPredication::expandCheck(SCEVExpander &Expander,
398398
if (SE->isLoopEntryGuardedByCond(L, Pred, LHS, RHS))
399399
return Builder.getTrue();
400400

401+
Instruction *InsertAt = &*Builder.GetInsertPoint();
401402
Value *LHSV = Expander.expandCodeFor(LHS, Ty, InsertAt);
402403
Value *RHSV = Expander.expandCodeFor(RHS, Ty, InsertAt);
403404
return Builder.CreateICmp(Pred, LHSV, RHSV);
@@ -469,12 +470,11 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckIncrementingLoop(
469470
LLVM_DEBUG(dbgs() << "LHS: " << *LatchLimit << "\n");
470471
LLVM_DEBUG(dbgs() << "RHS: " << *RHS << "\n");
471472
LLVM_DEBUG(dbgs() << "Pred: " << LimitCheckPred << "\n");
472-
473-
Instruction *InsertAt = Preheader->getTerminator();
473+
474474
auto *LimitCheck =
475-
expandCheck(Expander, Builder, LimitCheckPred, LatchLimit, RHS, InsertAt);
475+
expandCheck(Expander, Builder, LimitCheckPred, LatchLimit, RHS);
476476
auto *FirstIterationCheck = expandCheck(Expander, Builder, RangeCheck.Pred,
477-
GuardStart, GuardLimit, InsertAt);
477+
GuardStart, GuardLimit);
478478
return Builder.CreateAnd(FirstIterationCheck, LimitCheck);
479479
}
480480

@@ -504,13 +504,12 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckDecrementingLoop(
504504
// guardStart u< guardLimit &&
505505
// latchLimit <pred> 1.
506506
// See the header comment for reasoning of the checks.
507-
Instruction *InsertAt = Preheader->getTerminator();
508507
auto LimitCheckPred =
509508
ICmpInst::getFlippedStrictnessPredicate(LatchCheck.Pred);
510509
auto *FirstIterationCheck = expandCheck(Expander, Builder, ICmpInst::ICMP_ULT,
511-
GuardStart, GuardLimit, InsertAt);
510+
GuardStart, GuardLimit);
512511
auto *LimitCheck = expandCheck(Expander, Builder, LimitCheckPred, LatchLimit,
513-
SE->getOne(Ty), InsertAt);
512+
SE->getOne(Ty));
514513
return Builder.CreateAnd(FirstIterationCheck, LimitCheck);
515514
}
516515

@@ -607,7 +606,8 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks,
607606
}
608607

609608
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Condition)) {
610-
if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander, Builder)) {
609+
if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander,
610+
Builder)) {
611611
Checks.push_back(NewRangeCheck.getValue());
612612
NumWidened++;
613613
continue;

0 commit comments

Comments
 (0)