summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-12-09 23:12:55 +0000
committerChris Lattner <sabre@nondot.org>2003-12-09 23:12:55 +0000
commit6c237bcdf246ecf63e819a5ac084cf252e7fae78 (patch)
tree15632f10f4b6a1a6cb94cfb848df8ef33a9a1218 /llvm/lib/Transforms/Scalar
parentddc088a9e452bde431d443b61fe800174a600ed3 (diff)
downloadbcm5719-llvm-6c237bcdf246ecf63e819a5ac084cf252e7fae78.tar.gz
bcm5719-llvm-6c237bcdf246ecf63e819a5ac084cf252e7fae78.zip
Do not insert one entry PHI nodes in split exit blocks!
llvm-svn: 10348
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopSimplify.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplify.cpp b/llvm/lib/Transforms/Scalar/LoopSimplify.cpp
index 60e35d5ca92..2618b73409d 100644
--- a/llvm/lib/Transforms/Scalar/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopSimplify.cpp
@@ -162,21 +162,31 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
// incoming edges in BB into new PHI nodes in NewBB.
//
if (!Preds.empty()) { // Is the loop not obviously dead?
- for (BasicBlock::iterator I = BB->begin();
- PHINode *PN = dyn_cast<PHINode>(I); ++I) {
-
- // Create the new PHI node, insert it into NewBB at the end of the block
- PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI);
+ if (Preds.size() == 1) {
+ // No need to insert one operand PHI nodes! Instead, just update the
+ // incoming block ID's.
+ for (BasicBlock::iterator I = BB->begin();
+ PHINode *PN = dyn_cast<PHINode>(I); ++I) {
+ unsigned i = PN->getBasicBlockIndex(Preds[0]);
+ PN->setIncomingBlock(i, NewBB);
+ }
+ } else {
+ for (BasicBlock::iterator I = BB->begin();
+ PHINode *PN = dyn_cast<PHINode>(I); ++I) {
- // Move all of the edges from blocks outside the loop to the new PHI
- for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
- Value *V = PN->removeIncomingValue(Preds[i]);
- NewPHI->addIncoming(V, Preds[i]);
+ // Create the new PHI node, insert it into NewBB at the end of the block
+ PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI);
+
+ // Move all of the edges from blocks outside the loop to the new PHI
+ for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
+ Value *V = PN->removeIncomingValue(Preds[i]);
+ NewPHI->addIncoming(V, Preds[i]);
+ }
+
+ // Add an incoming value to the PHI node in the loop for the preheader
+ // edge.
+ PN->addIncoming(NewPHI, NewBB);
}
-
- // Add an incoming value to the PHI node in the loop for the preheader
- // edge
- PN->addIncoming(NewPHI, NewBB);
}
// Now that the PHI nodes are updated, actually move the edges from
OpenPOWER on IntegriCloud