[PATCH] D24509: [LCSSA] Cache LoopExits to avoid wasted work

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 19 16:39:05 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL281949: [LCSSA] Cache LoopExits to avoid wasted work (authored by reames).

Changed prior to commit:
  https://reviews.llvm.org/D24509?vs=71165&id=71890#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24509

Files:
  llvm/trunk/lib/Transforms/Utils/LCSSA.cpp

Index: llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
+++ llvm/trunk/lib/Transforms/Utils/LCSSA.cpp
@@ -63,19 +63,25 @@
 bool llvm::formLCSSAForInstructions(SmallVectorImpl<Instruction *> &Worklist,
                                     DominatorTree &DT, LoopInfo &LI) {
   SmallVector<Use *, 16> UsesToRewrite;
-  SmallVector<BasicBlock *, 8> ExitBlocks;
   SmallSetVector<PHINode *, 16> PHIsToRemove;
   PredIteratorCache PredCache;
   bool Changed = false;
 
+  // Cache the Loop ExitBlocks across this loop.  We expect to get a lot of
+  // instructions within the same loops, computing the exit blocks is
+  // expensive, and we're not mutating the loop structure.
+  SmallDenseMap<Loop*, SmallVector<BasicBlock *,1>> LoopExitBlocks;
+
   while (!Worklist.empty()) {
     UsesToRewrite.clear();
-    ExitBlocks.clear();
 
     Instruction *I = Worklist.pop_back_val();
     BasicBlock *InstBB = I->getParent();
     Loop *L = LI.getLoopFor(InstBB);
-    L->getExitBlocks(ExitBlocks);
+    if (!LoopExitBlocks.count(L))   
+      L->getExitBlocks(LoopExitBlocks[L]);
+    assert(LoopExitBlocks.count(L));
+    const SmallVectorImpl<BasicBlock *> &ExitBlocks = LoopExitBlocks[L];
 
     if (ExitBlocks.empty())
       continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24509.71890.patch
Type: text/x-patch
Size: 1340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160919/f54b28d1/attachment.bin>


More information about the llvm-commits mailing list