From: Philip Reames Date: Sun, 2 Jan 2022 17:49:45 +0000 (-0800) Subject: [SCEV] Split computeExitLimitFromICmp into two versions [NFC] X-Git-Tag: upstream/15.0.7~21878 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f19a95bbed1605f3b7575063054eb9fa1d13b125;p=platform%2Fupstream%2Fllvm.git [SCEV] Split computeExitLimitFromICmp into two versions [NFC] This is in advance of a following change which needs to the non-icmp API. --- diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index df50611..ac7e3a4 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1713,6 +1713,17 @@ private: bool IsSubExpr, bool AllowPredicates = false); + /// Variant of previous which takes the components representing an ICmp + /// as opposed to the ICmpInst itself. Note that the prior version can + /// return more precise results in some cases and is preferred when caller + /// has a materialized ICmp. + ExitLimit computeExitLimitFromICmp(const Loop *L, ICmpInst::Predicate Pred, + const SCEV *LHS, const SCEV *RHS, + bool ExitIfTrue, + bool IsSubExpr, + bool AllowPredicates = false); + + /// Compute the number of times the backedge of the specified loop will /// execute if its exit condition were a switch with a single exiting case /// to ExitingBB. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 0c3f322..d80505a 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8203,6 +8203,28 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L, const SCEV *LHS = getSCEV(ExitCond->getOperand(0)); const SCEV *RHS = getSCEV(ExitCond->getOperand(1)); + ExitLimit EL = computeExitLimitFromICmp(L, Pred, LHS, RHS, ExitIfTrue, + ControlsExit, AllowPredicates); + if (EL.hasAnyInfo()) return EL; + + auto *ExhaustiveCount = + computeExitCountExhaustively(L, ExitCond, ExitIfTrue); + + if (!isa(ExhaustiveCount)) + return ExhaustiveCount; + + return computeShiftCompareExitLimit(ExitCond->getOperand(0), + ExitCond->getOperand(1), L, OriginalPred); +} +ScalarEvolution::ExitLimit +ScalarEvolution::computeExitLimitFromICmp(const Loop *L, + ICmpInst::Predicate Pred, + const SCEV *LHS, const SCEV *RHS, + bool ExitIfTrue, + bool ControlsExit, + bool AllowPredicates) { + + // Try to evaluate any dependencies out of the loop. LHS = getSCEVAtScope(LHS, L); RHS = getSCEVAtScope(RHS, L); @@ -8312,14 +8334,7 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L, break; } - auto *ExhaustiveCount = - computeExitCountExhaustively(L, ExitCond, ExitIfTrue); - - if (!isa(ExhaustiveCount)) - return ExhaustiveCount; - - return computeShiftCompareExitLimit(ExitCond->getOperand(0), - ExitCond->getOperand(1), L, OriginalPred); + return getCouldNotCompute(); } ScalarEvolution::ExitLimit