Fix bug: Analysis/LoopInfo/2003-05-15-NestingProblem.ll
authorChris Lattner <sabre@nondot.org>
Thu, 15 May 2003 18:03:51 +0000 (18:03 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 15 May 2003 18:03:51 +0000 (18:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6230 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LoopInfo.cpp

index 7a1daa089e28361ebe3cc7ada275b876f6a64d5a..251714cb00291cc624a9cc2b68d6771e04d2a86a 100644 (file)
@@ -122,6 +122,12 @@ void LoopInfo::print(std::ostream &OS) const {
 #endif
 }
 
+static bool isNotAlreadyContainedIn(Loop *SubLoop, Loop *ParentLoop) {
+  if (SubLoop == 0) return true;
+  if (SubLoop == ParentLoop) return false;
+  return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop);
+}
+
 Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
   if (BBMap.find(BB) != BBMap.end()) return 0;   // Haven't processed this node?
 
@@ -150,7 +156,7 @@ Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
       // this child loop gets added to a part of the current loop, making it a
       // sibling to the current loop.  We have to reparent this loop.
       if (Loop *SubLoop = const_cast<Loop*>(getLoopFor(X)))
-        if (SubLoop->getHeader() == X && X != BB) {
+        if (SubLoop->getHeader() == X && isNotAlreadyContainedIn(SubLoop, L)) {
           // Remove the subloop from it's current parent...
           assert(SubLoop->ParentLoop && SubLoop->ParentLoop != L);
           Loop *SLP = SubLoop->ParentLoop;  // SubLoopParent