[PATCH] D61215: [LoopInfo] Faster implementation of setLoopID. NFC.

Keno Fischer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 26 15:43:35 PDT 2019


loladiro created this revision.
loladiro added reviewers: fhahn, jdoerfert, vtjnash.
Herald added a project: LLVM.

This change was part of D46460 <https://reviews.llvm.org/D46460>. However, in the meantime rL341926 <https://reviews.llvm.org/rL341926> fixed the
correctness issue here. What remained was the performance issue in setLoopID
where it would iterate through all blocks in the loop and their successors,
rather than just the predecessor of the header (the later presumably being
much faster). We already have the `getLoopLatches` to compute precisely these
basic blocks in an efficient manner, so just use it (as the original commit
did for `getLoopID`).


Repository:
  rL LLVM

https://reviews.llvm.org/D61215

Files:
  lib/Analysis/LoopInfo.cpp


Index: lib/Analysis/LoopInfo.cpp
===================================================================
--- lib/Analysis/LoopInfo.cpp
+++ lib/Analysis/LoopInfo.cpp
@@ -254,16 +254,10 @@
   assert((!LoopID || LoopID->getOperand(0) == LoopID) &&
          "Loop ID should refer to itself");
 
-  BasicBlock *H = getHeader();
-  for (BasicBlock *BB : this->blocks()) {
-    Instruction *TI = BB->getTerminator();
-    for (BasicBlock *Successor : successors(TI)) {
-      if (Successor == H) {
-        TI->setMetadata(LLVMContext::MD_loop, LoopID);
-        break;
-      }
-    }
-  }
+  SmallVector<BasicBlock *, 4> LoopLatches;
+  getLoopLatches(LoopLatches);
+  for (BasicBlock *BB : LoopLatches)
+      BB->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopID);
 }
 
 void Loop::setLoopAlreadyUnrolled() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61215.196923.patch
Type: text/x-patch
Size: 811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190426/635c18db/attachment.bin>


More information about the llvm-commits mailing list