[PATCH] D52118: [Loopinfo] Remove one latch case in getLoopID. NFC.

Michael Kruse via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 14 12:56:44 PDT 2018


Meinersbur created this revision.
Meinersbur added reviewers: hfinkel, jdoerfert.

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 a single latch. We can save an iteration over the loop's basic blocks (which is what getLoopLatch does) by handling both cases with the same code.


Repository:
  rC Clang

https://reviews.llvm.org/D52118

Files:
  lib/Analysis/LoopInfo.cpp


Index: lib/Analysis/LoopInfo.cpp
===================================================================
--- lib/Analysis/LoopInfo.cpp
+++ lib/Analysis/LoopInfo.cpp
@@ -213,26 +213,21 @@
 
 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;
-
-      if (!LoopID)
-        LoopID = MD;
-      else if (MD != LoopID)
-        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 (!MD)
+      return nullptr;
+
+    if (!LoopID)
+      LoopID = MD;
+    else if (MD != LoopID)
+      return nullptr;
   }
   if (!LoopID || LoopID->getNumOperands() == 0 ||
       LoopID->getOperand(0) != LoopID)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52118.165567.patch
Type: text/x-patch
Size: 1474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180914/7a58cc36/attachment.bin>


More information about the cfe-commits mailing list