From: Chris Lattner Date: Sun, 14 Jan 2007 18:33:35 +0000 (+0000) Subject: Fix PR1110 and Analysis/Dominators/2007-01-14-BreakCritEdges.ll by being X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9fa58b5f66202e06f25446f0aeb60cb716ffa6d4;p=oota-llvm.git Fix PR1110 and Analysis/Dominators/2007-01-14-BreakCritEdges.ll by being more careful about unreachable code when updating dominator info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33204 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp index e06a746ed38..e8cc027180c 100644 --- a/lib/Transforms/Utils/BreakCriticalEdges.cpp +++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -182,49 +182,54 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P, // Should we update DominatorSet information? if (DominatorSet *DS = P->getAnalysisToUpdate()) { - // The blocks that dominate the new one are the blocks that dominate TIBB - // plus the new block itself. - DominatorSet::DomSetType DomSet = DS->getDominators(TIBB); - DomSet.insert(NewBB); // A block always dominates itself. - DS->addBasicBlock(NewBB, DomSet); - - // If NewBBDominatesDestBB hasn't been computed yet, do so with DS. - if (!OtherPreds.empty()) { - while (!OtherPreds.empty() && NewBBDominatesDestBB) { - NewBBDominatesDestBB = DS->dominates(DestBB, OtherPreds.back()); - OtherPreds.pop_back(); + DominatorSet::iterator DSI = DS->find(TIBB); + if (DSI != DS->end()) { // TIBB is reachable? + // The blocks that dominate the new one are the blocks that dominate TIBB + // plus the new block itself. + DominatorSet::DomSetType DomSet = DSI->second; // Copy domset. + DomSet.insert(NewBB); // A block always dominates itself. + DS->addBasicBlock(NewBB, DomSet); + + // If NewBBDominatesDestBB hasn't been computed yet, do so with DS. + if (!OtherPreds.empty()) { + while (!OtherPreds.empty() && NewBBDominatesDestBB) { + NewBBDominatesDestBB = DS->dominates(DestBB, OtherPreds.back()); + OtherPreds.pop_back(); + } + OtherPreds.clear(); + } + + // If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it + // doesn't dominate anything. If NewBB does dominates DestBB, then it + // dominates everything that DestBB dominates. + if (NewBBDominatesDestBB) { + for (DominatorSet::iterator I = DS->begin(), E = DS->end(); I != E; ++I) + if (I->second.count(DestBB)) + I->second.insert(NewBB); } - OtherPreds.clear(); - } - - // If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it - // doesn't dominate anything. If NewBB does dominates DestBB, then it - // dominates everything that DestBB dominates. - if (NewBBDominatesDestBB) { - for (DominatorSet::iterator I = DS->begin(), E = DS->end(); I != E; ++I) - if (I->second.count(DestBB)) - I->second.insert(NewBB); } } // Should we update ImmediateDominator information? if (ImmediateDominators *ID = P->getAnalysisToUpdate()) { - // TIBB is the new immediate dominator for NewBB. - ID->addNewBlock(NewBB, TIBB); - - // If NewBBDominatesDestBB hasn't been computed yet, do so with ID. - if (!OtherPreds.empty()) { - while (!OtherPreds.empty() && NewBBDominatesDestBB) { - NewBBDominatesDestBB = ID->dominates(DestBB, OtherPreds.back()); - OtherPreds.pop_back(); + if (ID->get(TIBB)) { // Only do this if TIBB is reachable. + // TIBB is the new immediate dominator for NewBB. + ID->addNewBlock(NewBB, TIBB); + + // If NewBBDominatesDestBB hasn't been computed yet, do so with ID. + if (!OtherPreds.empty()) { + while (!OtherPreds.empty() && NewBBDominatesDestBB) { + NewBBDominatesDestBB = ID->dominates(DestBB, OtherPreds.back()); + OtherPreds.pop_back(); + } + OtherPreds.clear(); } - OtherPreds.clear(); + + // If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it + // doesn't dominate anything. + if (NewBBDominatesDestBB) + ID->setImmediateDominator(DestBB, NewBB); } - - // If NewBBDominatesDestBB, then NewBB dominates DestBB, otherwise it - // doesn't dominate anything. - if (NewBBDominatesDestBB) - ID->setImmediateDominator(DestBB, NewBB); } // Update the forest?