[LoopPredication] Use the builder's insertion point everywhere [NFC]

llvm-svn: 357330
This commit is contained in:
Philip Reames 2019-03-29 23:06:57 +00:00
parent 388e19ff1f
commit 3d4e108237
1 changed files with 11 additions and 11 deletions

View File

@ -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<Value *> 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<Value *> 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<Value *> LoopPredication::widenICmpRangeCheckDecrementingLoop(
// guardStart u< guardLimit &&
// latchLimit <pred> 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<Value *> &Checks,
}
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Condition)) {
if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander, Builder)) {
if (auto NewRangeCheck = widenICmpRangeCheck(ICI, Expander,
Builder)) {
Checks.push_back(NewRangeCheck.getValue());
NumWidened++;
continue;