summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-02-17 06:39:56 +0000
committerChris Lattner <sabre@nondot.org>2006-02-17 06:39:56 +0000
commitbaddba41c73cc30c45f0127b40fcd11a002a91ec (patch)
treee6db7ba737598a7cf9d622b30ee4ab123e73187e /llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
parent42c9e4df6f43a91459180bba8c4ddd1b988cc2e8 (diff)
downloadbcm5719-llvm-baddba41c73cc30c45f0127b40fcd11a002a91ec.tar.gz
bcm5719-llvm-baddba41c73cc30c45f0127b40fcd11a002a91ec.zip
Fix loops where the header has an exit, fixing a loop-unswitch crash on crafty
llvm-svn: 26258
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopUnswitch.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopUnswitch.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
index 9f493b5912c..6d29090ccb7 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnswitch.cpp
+++ b/llvm/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<BasicBlock*> &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
OpenPOWER on IntegriCloud