[llvm] r230619 - IRCE: only touch loops that have been shown to have a high

Sanjoy Das sanjoy at playingwithpointers.com
Thu Feb 26 00:56:04 PST 2015


Author: sanjoy
Date: Thu Feb 26 02:56:04 2015
New Revision: 230619

URL: http://llvm.org/viewvc/llvm-project?rev=230619&view=rev
Log:
IRCE: only touch loops that have been shown to have a high
backedge-taken count in profiliing data.


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=230619&r1=230618&r2=230619&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp Thu Feb 26 02:56:04 2015
@@ -82,6 +82,9 @@ static cl::opt<unsigned> LoopSizeCutoff(
 static cl::opt<bool> PrintChangedLoops("irce-print-changed-loops", cl::Hidden,
                                        cl::init(false));
 
+static cl::opt<int> 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<LoopStructure> parseLoopStructure(ScalarEvolution &, Loop &,
+  static Optional<LoopStructure> parseLoopStructure(ScalarEvolution &,
+                                                    BranchProbabilityInfo &BPI,
+                                                    Loop &,
                                                     const char *&);
 };
 
@@ -615,8 +620,8 @@ static bool CanBeSMin(ScalarEvolution &S
 }
 
 Optional<LoopStructure>
-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(Scalar
 
   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<ICmpInst>(LatchBr->getCondition());
   if (!ICI || !isa<IntegerType>(ICI->getOperand(0)->getType())) {
     FailureReason = "latch terminator branch not conditional on integral icmp";
@@ -1340,7 +1353,7 @@ bool InductiveRangeCheckElimination::run
 
   const char *FailureReason = nullptr;
   Optional<LoopStructure> 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";);





More information about the llvm-commits mailing list