@@ -265,8 +265,8 @@ class LoopPredication {
265
265
266
266
bool CanExpand (const SCEV* S);
267
267
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 );
270
270
271
271
Optional<Value *> widenICmpRangeCheck (ICmpInst *ICI, SCEVExpander &Expander,
272
272
IRBuilder<> &Builder);
@@ -389,7 +389,7 @@ LoopPredication::parseLoopICmp(ICmpInst::Predicate Pred, Value *LHS,
389
389
Value *LoopPredication::expandCheck (SCEVExpander &Expander,
390
390
IRBuilder<> &Builder,
391
391
ICmpInst::Predicate Pred, const SCEV *LHS,
392
- const SCEV *RHS, Instruction *InsertAt ) {
392
+ const SCEV *RHS) {
393
393
// TODO: we can check isLoopEntryGuardedByCond before emitting the check
394
394
395
395
Type *Ty = LHS->getType ();
@@ -398,6 +398,7 @@ Value *LoopPredication::expandCheck(SCEVExpander &Expander,
398
398
if (SE->isLoopEntryGuardedByCond (L, Pred, LHS, RHS))
399
399
return Builder.getTrue ();
400
400
401
+ Instruction *InsertAt = &*Builder.GetInsertPoint ();
401
402
Value *LHSV = Expander.expandCodeFor (LHS, Ty, InsertAt);
402
403
Value *RHSV = Expander.expandCodeFor (RHS, Ty, InsertAt);
403
404
return Builder.CreateICmp (Pred, LHSV, RHSV);
@@ -469,12 +470,11 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckIncrementingLoop(
469
470
LLVM_DEBUG (dbgs () << " LHS: " << *LatchLimit << " \n " );
470
471
LLVM_DEBUG (dbgs () << " RHS: " << *RHS << " \n " );
471
472
LLVM_DEBUG (dbgs () << " Pred: " << LimitCheckPred << " \n " );
472
-
473
- Instruction *InsertAt = Preheader->getTerminator ();
473
+
474
474
auto *LimitCheck =
475
- expandCheck (Expander, Builder, LimitCheckPred, LatchLimit, RHS, InsertAt );
475
+ expandCheck (Expander, Builder, LimitCheckPred, LatchLimit, RHS);
476
476
auto *FirstIterationCheck = expandCheck (Expander, Builder, RangeCheck.Pred ,
477
- GuardStart, GuardLimit, InsertAt );
477
+ GuardStart, GuardLimit);
478
478
return Builder.CreateAnd (FirstIterationCheck, LimitCheck);
479
479
}
480
480
@@ -504,13 +504,12 @@ Optional<Value *> LoopPredication::widenICmpRangeCheckDecrementingLoop(
504
504
// guardStart u< guardLimit &&
505
505
// latchLimit <pred> 1.
506
506
// See the header comment for reasoning of the checks.
507
- Instruction *InsertAt = Preheader->getTerminator ();
508
507
auto LimitCheckPred =
509
508
ICmpInst::getFlippedStrictnessPredicate (LatchCheck.Pred );
510
509
auto *FirstIterationCheck = expandCheck (Expander, Builder, ICmpInst::ICMP_ULT,
511
- GuardStart, GuardLimit, InsertAt );
510
+ GuardStart, GuardLimit);
512
511
auto *LimitCheck = expandCheck (Expander, Builder, LimitCheckPred, LatchLimit,
513
- SE->getOne (Ty), InsertAt );
512
+ SE->getOne (Ty));
514
513
return Builder.CreateAnd (FirstIterationCheck, LimitCheck);
515
514
}
516
515
@@ -607,7 +606,8 @@ unsigned LoopPredication::collectChecks(SmallVectorImpl<Value *> &Checks,
607
606
}
608
607
609
608
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Condition)) {
610
- if (auto NewRangeCheck = widenICmpRangeCheck (ICI, Expander, Builder)) {
609
+ if (auto NewRangeCheck = widenICmpRangeCheck (ICI, Expander,
610
+ Builder)) {
611
611
Checks.push_back (NewRangeCheck.getValue ());
612
612
NumWidened++;
613
613
continue ;
0 commit comments