[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerSwitch.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu May 1 17:22:01 PDT 2003
Changes in directory llvm/lib/Transforms/Scalar:
LowerSwitch.cpp updated: 1.1 -> 1.2
---
Log message:
Fix Bug: LowerSwitch/2003-05-01-PHIProblem.ll
---
Diffs of the changes:
Index: llvm/lib/Transforms/Scalar/LowerSwitch.cpp
diff -u llvm/lib/Transforms/Scalar/LowerSwitch.cpp:1.1 llvm/lib/Transforms/Scalar/LowerSwitch.cpp:1.2
--- llvm/lib/Transforms/Scalar/LowerSwitch.cpp:1.1 Wed Apr 23 11:23:59 2003
+++ llvm/lib/Transforms/Scalar/LowerSwitch.cpp Thu May 1 17:21:21 2003
@@ -84,7 +84,7 @@
Instruction *Br = new BranchInst(Succ, NextBlock, Comp);
CurBlock->getInstList().push_back(Br);
- // If there were any PHI nodes in this success, rewrite one entry from
+ // If there were any PHI nodes in this successor, rewrite one entry from
// OrigBlock to come from CurBlock.
for (BasicBlock::iterator I = Succ->begin();
PHINode *PN = dyn_cast<PHINode>(I); ++I) {
@@ -93,9 +93,19 @@
PN->setIncomingBlock((unsigned)BlockIdx, CurBlock);
}
+ if (i == e-2) { // Is this looking at the default destination?
+ // If there is an entry in any PHI nodes for the default edge, make sure
+ // to update them as well.
+ for (BasicBlock::iterator I = NextBlock->begin();
+ PHINode *PN = dyn_cast<PHINode>(I); ++I) {
+ int BlockIdx = PN->getBasicBlockIndex(OrigBlock);
+ assert(BlockIdx != -1 && "Switch didn't go to this successor??");
+ PN->setIncomingBlock((unsigned)BlockIdx, CurBlock);
+ }
+ }
+
CurBlock = NextBlock; // Move on to the next condition
}
-
// We are now done with the switch instruction, delete it.
delete SI;
More information about the llvm-commits
mailing list