[llvm] r312215 - [IRCE][NFC] Rename IndVarNext to IndVarBase

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 22:58:15 PDT 2017


Author: mkazantsev
Date: Wed Aug 30 22:58:15 2017
New Revision: 312215

URL: http://llvm.org/viewvc/llvm-project?rev=312215&view=rev
Log:
[IRCE][NFC] Rename IndVarNext to IndVarBase

Renaming as a preparation step to generalizing IRCE for comparison not only against
the next value of an indvar, but also against the current.

Differential Revision: https://reviews.llvm.org/D36509

Modified:
    llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp?rev=312215&r1=312214&r2=312215&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp Wed Aug 30 22:58:15 2017
@@ -452,10 +452,10 @@ struct LoopStructure {
   // intN_ty inc = IndVarIncreasing ? 1 : -1;
   // pred_ty predicate = IndVarIncreasing ? ICMP_SLT : ICMP_SGT;
   //
-  // for (intN_ty iv = IndVarStart; predicate(iv, LoopExitAt); iv = IndVarNext)
+  // for (intN_ty iv = IndVarStart; predicate(iv, LoopExitAt); iv = IndVarBase)
   //   ... body ...
 
-  Value *IndVarNext;
+  Value *IndVarBase;
   Value *IndVarStart;
   Value *IndVarStep;
   Value *LoopExitAt;
@@ -464,7 +464,7 @@ struct LoopStructure {
 
   LoopStructure()
       : Tag(""), Header(nullptr), Latch(nullptr), LatchBr(nullptr),
-        LatchExit(nullptr), LatchBrExitIdx(-1), IndVarNext(nullptr),
+        LatchExit(nullptr), LatchBrExitIdx(-1), IndVarBase(nullptr),
         IndVarStart(nullptr), IndVarStep(nullptr), LoopExitAt(nullptr),
         IndVarIncreasing(false), IsSignedPredicate(true) {}
 
@@ -476,7 +476,7 @@ struct LoopStructure {
     Result.LatchBr = cast<BranchInst>(Map(LatchBr));
     Result.LatchExit = cast<BasicBlock>(Map(LatchExit));
     Result.LatchBrExitIdx = LatchBrExitIdx;
-    Result.IndVarNext = Map(IndVarNext);
+    Result.IndVarBase = Map(IndVarBase);
     Result.IndVarStart = Map(IndVarStart);
     Result.IndVarStep = Map(IndVarStep);
     Result.LoopExitAt = Map(LoopExitAt);
@@ -832,17 +832,17 @@ LoopStructure::parseLoopStructure(Scalar
   // `ICI` is interpreted as taking the backedge if the *next* value of the
   // induction variable satisfies some constraint.
 
-  const SCEVAddRecExpr *IndVarNext = cast<SCEVAddRecExpr>(LeftSCEV);
+  const SCEVAddRecExpr *IndVarBase = cast<SCEVAddRecExpr>(LeftSCEV);
   bool IsIncreasing = false;
   bool IsSignedPredicate = true;
   ConstantInt *StepCI;
-  if (!IsInductionVar(IndVarNext, IsIncreasing, StepCI)) {
+  if (!IsInductionVar(IndVarBase, IsIncreasing, StepCI)) {
     FailureReason = "LHS in icmp not induction variable";
     return None;
   }
 
-  const SCEV *StartNext = IndVarNext->getStart();
-  const SCEV *Addend = SE.getNegativeSCEV(IndVarNext->getStepRecurrence(SE));
+  const SCEV *StartNext = IndVarBase->getStart();
+  const SCEV *Addend = SE.getNegativeSCEV(IndVarBase->getStepRecurrence(SE));
   const SCEV *IndVarStart = SE.getAddExpr(StartNext, Addend);
   const SCEV *Step = SE.getSCEV(StepCI);
 
@@ -1023,7 +1023,7 @@ LoopStructure::parseLoopStructure(Scalar
   Result.LatchBrExitIdx = LatchBrExitIdx;
   Result.IndVarStart = IndVarStartV;
   Result.IndVarStep = StepCI;
-  Result.IndVarNext = LeftValue;
+  Result.IndVarBase = LeftValue;
   Result.IndVarIncreasing = IsIncreasing;
   Result.LoopExitAt = RightValue;
   Result.IsSignedPredicate = IsSignedPredicate;
@@ -1273,12 +1273,12 @@ LoopConstrainer::RewrittenRangeInfo Loop
   Value *TakeBackedgeLoopCond = nullptr;
   if (Increasing)
     TakeBackedgeLoopCond = IsSignedPredicate
-                        ? B.CreateICmpSLT(LS.IndVarNext, ExitSubloopAt)
-                        : B.CreateICmpULT(LS.IndVarNext, ExitSubloopAt);
+                        ? B.CreateICmpSLT(LS.IndVarBase, ExitSubloopAt)
+                        : B.CreateICmpULT(LS.IndVarBase, ExitSubloopAt);
   else
     TakeBackedgeLoopCond = IsSignedPredicate
-                        ? B.CreateICmpSGT(LS.IndVarNext, ExitSubloopAt)
-                        : B.CreateICmpUGT(LS.IndVarNext, ExitSubloopAt);
+                        ? B.CreateICmpSGT(LS.IndVarBase, ExitSubloopAt)
+                        : B.CreateICmpUGT(LS.IndVarBase, ExitSubloopAt);
   Value *CondForBranch = LS.LatchBrExitIdx == 1
                              ? TakeBackedgeLoopCond
                              : B.CreateNot(TakeBackedgeLoopCond);
@@ -1293,12 +1293,12 @@ LoopConstrainer::RewrittenRangeInfo Loop
   Value *IterationsLeft = nullptr;
   if (Increasing)
     IterationsLeft = IsSignedPredicate
-                         ? B.CreateICmpSLT(LS.IndVarNext, LS.LoopExitAt)
-                         : B.CreateICmpULT(LS.IndVarNext, LS.LoopExitAt);
+                         ? B.CreateICmpSLT(LS.IndVarBase, LS.LoopExitAt)
+                         : B.CreateICmpULT(LS.IndVarBase, LS.LoopExitAt);
   else
     IterationsLeft = IsSignedPredicate
-                         ? B.CreateICmpSGT(LS.IndVarNext, LS.LoopExitAt)
-                         : B.CreateICmpUGT(LS.IndVarNext, LS.LoopExitAt);
+                         ? B.CreateICmpSGT(LS.IndVarBase, LS.LoopExitAt)
+                         : B.CreateICmpUGT(LS.IndVarBase, LS.LoopExitAt);
   B.CreateCondBr(IterationsLeft, RRI.PseudoExit, LS.LatchExit);
 
   BranchInst *BranchToContinuation =
@@ -1321,10 +1321,10 @@ LoopConstrainer::RewrittenRangeInfo Loop
     RRI.PHIValuesAtPseudoExit.push_back(NewPHI);
   }
 
-  RRI.IndVarEnd = PHINode::Create(LS.IndVarNext->getType(), 2, "indvar.end",
+  RRI.IndVarEnd = PHINode::Create(LS.IndVarBase->getType(), 2, "indvar.end",
                                   BranchToContinuation);
   RRI.IndVarEnd->addIncoming(LS.IndVarStart, Preheader);
-  RRI.IndVarEnd->addIncoming(LS.IndVarNext, RRI.ExitSelector);
+  RRI.IndVarEnd->addIncoming(LS.IndVarBase, RRI.ExitSelector);
 
   // The latch exit now has a branch from `RRI.ExitSelector' instead of
   // `LS.Latch'.  The PHI nodes need to be updated to reflect that.
@@ -1425,7 +1425,7 @@ bool LoopConstrainer::run() {
   SubRanges SR = MaybeSR.getValue();
   bool Increasing = MainLoopStructure.IndVarIncreasing;
   IntegerType *IVTy =
-      cast<IntegerType>(MainLoopStructure.IndVarNext->getType());
+      cast<IntegerType>(MainLoopStructure.IndVarBase->getType());
 
   SCEVExpander Expander(SE, F.getParent()->getDataLayout(), "irce");
   Instruction *InsertPt = OriginalPreheader->getTerminator();
@@ -1700,7 +1700,7 @@ bool InductiveRangeCheckElimination::run
   }
   LoopStructure LS = MaybeLoopStructure.getValue();
   const SCEVAddRecExpr *IndVar =
-      cast<SCEVAddRecExpr>(SE.getMinusSCEV(SE.getSCEV(LS.IndVarNext), SE.getSCEV(LS.IndVarStep)));
+      cast<SCEVAddRecExpr>(SE.getMinusSCEV(SE.getSCEV(LS.IndVarBase), SE.getSCEV(LS.IndVarStep)));
 
   Optional<InductiveRangeCheck::Range> SafeIterRange;
   Instruction *ExprInsertPt = Preheader->getTerminator();




More information about the llvm-commits mailing list