aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-11 15:44:22 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-11 15:44:22 -0800
commit4f6b0c7bbbbc46fb4de7f0a57c7c96b002f3d652 (patch)
tree6384fadfee27dbd035fe6b388dc175c82a764ddf
parent8316c304f3a1cea78f545a1080e490f75cf000a3 (diff)
fix phis from legalized switches
-rw-r--r--lib/Transforms/NaCl/ExpandI64.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/Transforms/NaCl/ExpandI64.cpp b/lib/Transforms/NaCl/ExpandI64.cpp
index 6e6a320b8d..5af1ac197d 100644
--- a/lib/Transforms/NaCl/ExpandI64.cpp
+++ b/lib/Transforms/NaCl/ExpandI64.cpp
@@ -614,21 +614,24 @@ void ExpandI64::splitInst(Instruction *I, DataLayout& DL) {
for (unsigned i = 0; i < V.size(); i++) {
BasicBlock *BB = V[i].second;
HighSI->addCase(cast<ConstantInt>(ConstantInt::get(i32, V[i].first)), BB);
- // fix phis, we used to go SwitchBB->BB, but now go SwitchBB->NewBB->BB, so we look like we arrived from NewBB. Fix that to SwitchBB.
+ // fix phis, we used to go SwitchBB->BB, but now go SwitchBB->NewBB->BB, so we look like we arrived from NewBB. Replace the phi from the
+ // now unneeded SwitchBB to the new BB
for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
PHINode *Phi = dyn_cast<PHINode>(I);
if (!Phi) break;
- // XXX note that we add a new i64 thing here. now the phi was already an i64 operation, and is being legalized anyhow, but we only notice the original inputs!
- // we seem to be safe for now due to order of operation (phis show up after switches, but FIXME
- Phi->addIncoming(Phi->getIncomingValue(Phi->getBasicBlockIndex(SwitchBB)), NewBB);
+ Phi->setIncomingBlock(Phi->getBasicBlockIndex(SwitchBB), NewBB);
}
}
- // We used to go SwitchBB->DD, but now go SwitchBB->NewBB->DD, fix that like with BB above
+ // We used to go SwitchBB->DD, but now go SwitchBB->NewBB->DD, fix that like with BB above. However here we do not replace,
+ // as the switch BB is still possible to arrive from - we can arrive at the default if either the lower bits were wrong (we
+ // arrive from the switchBB) or from the NewBB if the high bits were wrong.
for (BasicBlock::iterator I = DD->begin(); I != DD->end(); ++I) {
PHINode *Phi = dyn_cast<PHINode>(I);
if (!Phi) break;
Phi->addIncoming(Phi->getIncomingValue(Phi->getBasicBlockIndex(SwitchBB)), NewBB);
+ // XXX note that we add a new i64 thing here. now the phi was already an i64 operation, and is being legalized anyhow, but we only notice the original inputs!
+ // we seem to be safe for now due to order of operation (phis show up after switches, but FIXME
}
}
break;