summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-08-14 21:38:05 +0000
committerChris Lattner <sabre@nondot.org>2006-08-14 21:38:05 +0000
commit6441cf93c92745f1b82a9ecef8705889eaf1c432 (patch)
treed7deb1471e8cbb492b440f50b54539111e2c775c /llvm/lib/Transforms
parentc5bbda70e3e4ee389eaca6048ef7090ecb1e19cc (diff)
downloadbcm5719-llvm-6441cf93c92745f1b82a9ecef8705889eaf1c432.tar.gz
bcm5719-llvm-6441cf93c92745f1b82a9ecef8705889eaf1c432.zip
Handle single-entry PHI nodes correctly. This fixes PR877 and
Transforms/CondProp/2006-08-14-SingleEntryPhiCrash.ll llvm-svn: 29673
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/CondPropagate.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/CondPropagate.cpp b/llvm/lib/Transforms/Scalar/CondPropagate.cpp
index 101acef6dcb..49c87fd02f0 100644
--- a/llvm/lib/Transforms/Scalar/CondPropagate.cpp
+++ b/llvm/lib/Transforms/Scalar/CondPropagate.cpp
@@ -87,8 +87,18 @@ void CondProp::SimplifyBlock(BasicBlock *BB) {
// If this block ends with an unconditional branch and the only successor has
// only this block as a predecessor, merge the two blocks together.
if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator()))
- if (BI->isUnconditional() && BI->getSuccessor(0)->getSinglePredecessor()) {
+ if (BI->isUnconditional() && BI->getSuccessor(0)->getSinglePredecessor() &&
+ BB != BI->getSuccessor(0)) {
BasicBlock *Succ = BI->getSuccessor(0);
+
+ // If Succ has any PHI nodes, they are all single-entry PHI's.
+ while (PHINode *PN = dyn_cast<PHINode>(Succ->begin())) {
+ assert(PN->getNumIncomingValues() == 1 &&
+ "PHI doesn't match parent block");
+ PN->replaceAllUsesWith(PN->getIncomingValue(0));
+ PN->eraseFromParent();
+ }
+
// Remove BI.
BI->eraseFromParent();
OpenPOWER on IntegriCloud