[LoopUtils] Updated deleteDeadLoop() to handle loop nest.

Reviewer: kariddi, sanjoy, reames, Meinersbur, bmahjour, etiotto,
kbarton
Reviewed By: Meinersbur
Subscribers: mgorny, hiraditya, llvm-commits
Tag: LLVM
Differential Revision: https://reviews.llvm.org/D70939
This commit is contained in:
Whitney Tsang 2019-12-17 00:03:04 +00:00
parent d6777207b4
commit c066ff11d8
2 changed files with 13 additions and 1 deletions

View File

@ -673,7 +673,18 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT = nullptr,
LI->removeBlock(BB);
// The last step is to update LoopInfo now that we've eliminated this loop.
LI->erase(L);
// Note: LoopInfo::erase remove the given loop and relink its subloops with
// its parent. While removeLoop/removeChildLoop remove the given loop but
// not relink its subloops, which is what we want.
if (Loop *ParentLoop = L->getParentLoop()) {
Loop::iterator I = find(ParentLoop->begin(), ParentLoop->end(), L);
assert(I != ParentLoop->end() && "Couldn't find loop");
ParentLoop->removeChildLoop(I);
} else {
Loop::iterator I = find(LI->begin(), LI->end(), L);
assert(I != LI->end() && "Couldn't find loop");
LI->removeLoop(I);
}
}
}

View File

@ -15,6 +15,7 @@ add_llvm_unittest(UtilsTests
FunctionComparatorTest.cpp
IntegerDivisionTest.cpp
LocalTest.cpp
LoopUtilsTest.cpp
SizeOptsTest.cpp
SSAUpdaterBulkTest.cpp
UnrollLoopTest.cpp