diff options
author | Chris Lattner <sabre@nondot.org> | 2002-07-29 21:26:30 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-07-29 21:26:30 +0000 |
commit | 91b65c0b42b3d5dece246bdb366441d6f5593396 (patch) | |
tree | 2ac2522c6db0e3164c86f6ec7255d7f48e01f215 /lib/Transforms | |
parent | 781e6f5f894175a48e21c7b9d443616a7428f1f7 (diff) | |
download | external_llvm-91b65c0b42b3d5dece246bdb366441d6f5593396.zip external_llvm-91b65c0b42b3d5dece246bdb366441d6f5593396.tar.gz external_llvm-91b65c0b42b3d5dece246bdb366441d6f5593396.tar.bz2 |
Allow folding of basic blocks that have PHI nodes in them, fixing "bug":
test/Regression/Transforms/SimplifyCFG/2002-06-24-PHINode.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3128 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 426d18e..59ea986 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -143,7 +143,7 @@ bool SimplifyCFG(BasicBlock *BB) { // pred, and if there is only one distinct successor of the predecessor, and // if there are no PHI nodes. // - if (!isa<PHINode>(BB->front()) && !BB->hasConstantReferences()) { + if (!BB->hasConstantReferences()) { pred_iterator PI(pred_begin(BB)), PE(pred_end(BB)); BasicBlock *OnlyPred = *PI++; for (; PI != PE; ++PI) // Search all predecessors, see if they are all same @@ -168,6 +168,16 @@ bool SimplifyCFG(BasicBlock *BB) { //cerr << "Merging: " << BB << "into: " << OnlyPred; TerminatorInst *Term = OnlyPred->getTerminator(); + // Resolve any PHI nodes at the start of the block. They are all + // guaranteed to have exactly one entry if they exist. + // + while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) { + assert(PN->getNumIncomingValues() == 1 && "Only one pred!"); + PN->replaceAllUsesWith(PN->getIncomingValue(0)); + BB->getInstList().pop_front(); // Delete the phi node... + } + + // Delete the unconditional branch from the predecessor... OnlyPred->getInstList().pop_back(); |