From 0017d480cc79eb43950a913acec85ba1207f9424 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 17 Feb 2006 06:39:56 +0000 Subject: [PATCH] Fix loops where the header has an exit, fixing a loop-unswitch crash on crafty git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26258 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopUnswitch.cpp | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 9f493b5912c..6d29090ccb7 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -136,20 +136,22 @@ static bool LoopValuesUsedOutsideLoop(Loop *L) { static bool isTrivialLoopExitBlockHelper(Loop *L, BasicBlock *BB, BasicBlock *&ExitBB, std::set &Visited) { - BasicBlock *Header = L->getHeader(); + if (!Visited.insert(BB).second) { + // Already visited and Ok, end of recursion. + return true; + } else if (!L->contains(BB)) { + // Otherwise, this is a loop exit, this is fine so long as this is the + // first exit. + if (ExitBB != 0) return false; + ExitBB = BB; + return true; + } + + // Otherwise, this is an unvisited intra-loop node. Check all successors. for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI) { - if (!Visited.insert(*SI).second) { - // Already visited and Ok, end of recursion. - } else if (L->contains(*SI)) { - // Check to see if the successor is a trivial loop exit. - if (!isTrivialLoopExitBlockHelper(L, *SI, ExitBB, Visited)) - return false; - } else { - // Otherwise, this is a loop exit, this is fine so long as this is the - // first exit. - if (ExitBB != 0) return false; - ExitBB = *SI; - } + // Check to see if the successor is a trivial loop exit. + if (!isTrivialLoopExitBlockHelper(L, *SI, ExitBB, Visited)) + return false; } // Okay, everything after this looks good, check to make sure that this block