[llvm] c066ff1 - [LoopUtils] Updated deleteDeadLoop() to handle loop nest.
Whitney Tsang via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 16 17:06:30 PST 2019
Author: Whitney Tsang
Date: 2019-12-17T01:06:14Z
New Revision: c066ff11d84a7797503ad5a44c4129136926dc85
URL: https://github.com/llvm/llvm-project/commit/c066ff11d84a7797503ad5a44c4129136926dc85
DIFF: https://github.com/llvm/llvm-project/commit/c066ff11d84a7797503ad5a44c4129136926dc85.diff
LOG: [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
Added:
Modified:
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/unittests/Transforms/Utils/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 68ef0fe40714..2340e8c72e10 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -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);
+ }
}
}
diff --git a/llvm/unittests/Transforms/Utils/CMakeLists.txt b/llvm/unittests/Transforms/Utils/CMakeLists.txt
index 5a8204cb86ac..424f09025ea2 100644
--- a/llvm/unittests/Transforms/Utils/CMakeLists.txt
+++ b/llvm/unittests/Transforms/Utils/CMakeLists.txt
@@ -15,6 +15,7 @@ add_llvm_unittest(UtilsTests
FunctionComparatorTest.cpp
IntegerDivisionTest.cpp
LocalTest.cpp
+ LoopUtilsTest.cpp
SizeOptsTest.cpp
SSAUpdaterBulkTest.cpp
UnrollLoopTest.cpp
More information about the llvm-commits
mailing list