]> granicus.if.org Git - llvm/commitdiff
[LoopPredication] Use the builder's insertion point everywhere [NFC]
authorPhilip Reames <listmail@philipreames.com>
Fri, 29 Mar 2019 23:06:57 +0000 (23:06 +0000)
committerPhilip Reames <listmail@philipreames.com>
Fri, 29 Mar 2019 23:06:57 +0000 (23:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357330 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopPredication.cpp

index eef048ec36b9e6ff2b606f7a6b0a84a7c9f95a66..250f6e259af529414942984ef927d63fb02aad46 100644 (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;