From d0950d05a61a116b30f45448e879924504f03b3d Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Mon, 10 Apr 2023 13:57:51 +0700 Subject: [PATCH] [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. --- .../Transforms/Scalar/InductiveRangeCheckElimination.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp index 463ea1d..4629a82 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 different 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::calculateSubRanges(bool IsSignedPredicate) const { - IntegerType *Ty = cast(LatchTakenCount->getType()); + const IntegerType *Ty = ExitCountTy; auto *RTy = cast(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(LatchTakenCount) && Preheader != nullptr && "preconditions!"); + ExitCountTy = cast(LatchTakenCount->getType()); OriginalPreheader = Preheader; MainLoopPreheader = Preheader; -- 2.7.4