[llvm] r342406 - [Loopinfo] Remove one latch-case in getLoopID. NFC.

Michael Kruse via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 17 11:40:29 PDT 2018


Author: meinersbur
Date: Mon Sep 17 11:40:29 2018
New Revision: 342406

URL: http://llvm.org/viewvc/llvm-project?rev=342406&view=rev
Log:
[Loopinfo] Remove one latch-case in getLoopID. NFC.

getLoopID has different control flow for two cases: If there is a
single loop latch and for any other number of loop latches (0 and more
than one). The latter case should return the same result if there is
only a single latch. We can save the preceding redundant search for a
latch by handling both cases with the same code.

Differential Revision: https://reviews.llvm.org/D52118

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=342406&r1=342405&r2=342406&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopInfo.cpp Mon Sep 17 11:40:29 2018
@@ -213,26 +213,21 @@ bool Loop::isSafeToClone() const {
 
 MDNode *Loop::getLoopID() const {
   MDNode *LoopID = nullptr;
-  if (BasicBlock *Latch = getLoopLatch()) {
-    LoopID = Latch->getTerminator()->getMetadata(LLVMContext::MD_loop);
-  } else {
-    assert(!getLoopLatch() &&
-           "The loop should have no single latch at this point");
-    // Go through the latch blocks and check the terminator for the metadata.
-    SmallVector<BasicBlock *, 4> LatchesBlocks;
-    getLoopLatches(LatchesBlocks);
-    for (BasicBlock *BB : LatchesBlocks) {
-      TerminatorInst *TI = BB->getTerminator();
-      MDNode *MD = TI->getMetadata(LLVMContext::MD_loop);
 
-      if (!MD)
-        return nullptr;
+  // Go through the latch blocks and check the terminator for the metadata.
+  SmallVector<BasicBlock *, 4> LatchesBlocks;
+  getLoopLatches(LatchesBlocks);
+  for (BasicBlock *BB : LatchesBlocks) {
+    TerminatorInst *TI = BB->getTerminator();
+    MDNode *MD = TI->getMetadata(LLVMContext::MD_loop);
 
-      if (!LoopID)
-        LoopID = MD;
-      else if (MD != LoopID)
-        return nullptr;
-    }
+    if (!MD)
+      return nullptr;
+
+    if (!LoopID)
+      LoopID = MD;
+    else if (MD != LoopID)
+      return nullptr;
   }
   if (!LoopID || LoopID->getNumOperands() == 0 ||
       LoopID->getOperand(0) != LoopID)




More information about the llvm-commits mailing list