[llvm] r359684 - [LoopInfo] Faster implementation of setLoopID. NFC.

Keno Fischer via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 07:39:11 PDT 2019


Author: kfischer
Date: Wed May  1 07:39:11 2019
New Revision: 359684

URL: http://llvm.org/viewvc/llvm-project?rev=359684&view=rev
Log:
[LoopInfo] Faster implementation of setLoopID. NFC.

Summary:
This change was part of D46460. However, in the meantime 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`).

Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D61215

Modified:
    llvm/trunk/lib/Analysis/LoopInfo.cpp

Modified: llvm/trunk/lib/Analysis/LoopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=359684&r1=359683&r2=359684&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopInfo.cpp Wed May  1 07:39:11 2019
@@ -254,16 +254,10 @@ void Loop::setLoopID(MDNode *LoopID) con
   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() {




More information about the llvm-commits mailing list