[llvm] d0950d0 - [NFC][IRCE] Do not store latch exit count

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 00:00:23 PDT 2023


Author: Max Kazantsev
Date: 2023-04-10T14:00:14+07:00
New Revision: d0950d05a61a116b30f45448e879924504f03b3d

URL: https://github.com/llvm/llvm-project/commit/d0950d05a61a116b30f45448e879924504f03b3d
DIFF: https://github.com/llvm/llvm-project/commit/d0950d05a61a116b30f45448e879924504f03b3d.diff

LOG: [NFC][IRCE] Do not store latch exit count

It is not actually used for any computations. Its only purpose is to
check that the loop is finite and find out the type of computed exit
count. Refactor code so that we only store this type.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index 463ea1d4e3197..4629a82ba227b 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -622,7 +622,7 @@ class LoopConstrainer {
   // Information about the original loop we started out with.
   Loop &OriginalLoop;
 
-  const SCEV *LatchTakenCount = nullptr;
+  const IntegerType *ExitCountTy = nullptr;
   BasicBlock *OriginalPreheader = nullptr;
 
   // The preheader of the main loop.  This may or may not be 
diff erent from
@@ -791,6 +791,9 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L,
     FailureReason = "could not compute latch count";
     return std::nullopt;
   }
+  assert(SE.getLoopDisposition(LatchCount, &L) ==
+             ScalarEvolution::LoopInvariant &&
+         "loop variant exit count doesn't make sense!");
 
   ICmpInst::Predicate Pred = ICI->getPredicate();
   Value *LeftValue = ICI->getOperand(0);
@@ -1015,10 +1018,6 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L,
   }
   BasicBlock *LatchExit = LatchBr->getSuccessor(LatchBrExitIdx);
 
-  assert(SE.getLoopDisposition(LatchCount, &L) ==
-             ScalarEvolution::LoopInvariant &&
-         "loop variant exit count doesn't make sense!");
-
   assert(!L.contains(LatchExit) && "expected an exit block!");
   const DataLayout &DL = Preheader->getModule()->getDataLayout();
   SCEVExpander Expander(SE, DL, "irce");
@@ -1060,7 +1059,7 @@ static const SCEV *NoopOrExtend(const SCEV *S, Type *Ty, ScalarEvolution &SE,
 
 std::optional<LoopConstrainer::SubRanges>
 LoopConstrainer::calculateSubRanges(bool IsSignedPredicate) const {
-  IntegerType *Ty = cast<IntegerType>(LatchTakenCount->getType());
+  const IntegerType *Ty = ExitCountTy;
 
   auto *RTy = cast<IntegerType>(Range.getType());
 
@@ -1401,10 +1400,12 @@ Loop *LoopConstrainer::createClonedLoopStructure(Loop *Original, Loop *Parent,
 
 bool LoopConstrainer::run() {
   BasicBlock *Preheader = nullptr;
-  LatchTakenCount = SE.getExitCount(&OriginalLoop, MainLoopStructure.Latch);
+  const SCEV *LatchTakenCount =
+      SE.getExitCount(&OriginalLoop, MainLoopStructure.Latch);
   Preheader = OriginalLoop.getLoopPreheader();
   assert(!isa<SCEVCouldNotCompute>(LatchTakenCount) && Preheader != nullptr &&
          "preconditions!");
+  ExitCountTy = cast<IntegerType>(LatchTakenCount->getType());
 
   OriginalPreheader = Preheader;
   MainLoopPreheader = Preheader;


        


More information about the llvm-commits mailing list