Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
[Loopinfo] Remove one latch-case in getLoopID. NFC.
Browse files Browse the repository at this point in the history
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342406 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Meinersbur committed Sep 17, 2018
1 parent 13f029c commit f702426
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions lib/Analysis/LoopInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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)
Expand Down

0 comments on commit f702426

Please sign in to comment.