[PATCH] D46460: [LoopInfo] Don't bail out early in getLoopID
Keno Fischer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 4 13:49:07 PDT 2018
loladiro created this revision.
loladiro added reviewers: sanjoy, hfinkel.
As far as I understand getLoopID needs to look at the intersection of
1. BasicBlocks in the loop and
2. Predecessors of the loop header
and check each of those terminators for a !loop metadata node. However,
what getLoopID is currently doing is iterate through the basic blocks
and require that every one of them have an edge back to the loop header
with the appropriate metadata. This seems incorrect and causes situations
in which a LoopID set with setLoopID cannot be subsequently retrieved with
getLoopID.
Repository:
rL LLVM
https://reviews.llvm.org/D46460
Files:
lib/Analysis/LoopInfo.cpp
Index: lib/Analysis/LoopInfo.cpp
===================================================================
--- lib/Analysis/LoopInfo.cpp
+++ lib/Analysis/LoopInfo.cpp
@@ -223,15 +223,14 @@
BasicBlock *H = getHeader();
for (BasicBlock *BB : this->blocks()) {
TerminatorInst *TI = BB->getTerminator();
- MDNode *MD = nullptr;
// Check if this terminator branches to the loop header.
- for (BasicBlock *Successor : TI->successors()) {
- if (Successor == H) {
- MD = TI->getMetadata(LLVMContext::MD_loop);
- break;
- }
- }
+ bool IsPredecessor = any_of(TI->successors(),
+ [=](BasicBlock *Successor) { return Successor == H; });
+ if (!IsPredecessor)
+ continue;
+
+ MDNode *MD = TI->getMetadata(LLVMContext::MD_loop);
if (!MD)
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46460.145277.patch
Type: text/x-patch
Size: 854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180504/2c2d0e7c/attachment.bin>
More information about the llvm-commits
mailing list