From f1478ffeae8f4a508e686f963a5ff078366dbc93 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Thu, 26 Feb 2015 08:56:04 +0000 Subject: [PATCH] IRCE: only touch loops that have been shown to have a high backedge-taken count in profiliing data. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230619 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InductiveRangeCheckElimination.cpp | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp index da4e0fe0fa5..8559e638ac3 100644 --- a/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ b/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -82,6 +82,9 @@ static cl::opt LoopSizeCutoff("irce-loop-size-cutoff", cl::Hidden, static cl::opt PrintChangedLoops("irce-print-changed-loops", cl::Hidden, cl::init(false)); +static cl::opt MaxExitProbReciprocal("irce-max-exit-prob-reciprocal", + cl::Hidden, cl::init(10)); + #define DEBUG_TYPE "irce" namespace { @@ -441,7 +444,9 @@ struct LoopStructure { return Result; } - static Optional parseLoopStructure(ScalarEvolution &, Loop &, + static Optional parseLoopStructure(ScalarEvolution &, + BranchProbabilityInfo &BPI, + Loop &, const char *&); }; @@ -615,8 +620,8 @@ static bool CanBeSMin(ScalarEvolution &SE, const SCEV *S) { } Optional -LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, - const char *&FailureReason) { +LoopStructure::parseLoopStructure(ScalarEvolution &SE, BranchProbabilityInfo &BPI, + Loop &L, const char *&FailureReason) { assert(L.isLoopSimplifyForm() && "should follow from addRequired<>"); BasicBlock *Latch = L.getLoopLatch(); @@ -640,6 +645,14 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, unsigned LatchBrExitIdx = LatchBr->getSuccessor(0) == Header ? 1 : 0; + BranchProbability ExitProbability = + BPI.getEdgeProbability(LatchBr->getParent(), LatchBrExitIdx); + + if (ExitProbability > BranchProbability(1, MaxExitProbReciprocal)) { + FailureReason = "short running loop, not profitable"; + return None; + } + ICmpInst *ICI = dyn_cast(LatchBr->getCondition()); if (!ICI || !isa(ICI->getOperand(0)->getType())) { FailureReason = "latch terminator branch not conditional on integral icmp"; @@ -1340,7 +1353,7 @@ bool InductiveRangeCheckElimination::runOnLoop(Loop *L, LPPassManager &LPM) { const char *FailureReason = nullptr; Optional MaybeLoopStructure = - LoopStructure::parseLoopStructure(SE, *L, FailureReason); + LoopStructure::parseLoopStructure(SE, BPI, *L, FailureReason); if (!MaybeLoopStructure.hasValue()) { DEBUG(dbgs() << "irce: could not parse loop structure: " << FailureReason << "\n";); -- 2.34.1