Value *SelectValue,
IRBuilder<> &Builder,
DomTreeUpdater *DTU) {
+ std::vector<DominatorTree::UpdateType> Updates;
+
BasicBlock *SelectBB = SI->getParent();
+ BasicBlock *DestBB = PHI->getParent();
+
+ if (!is_contained(predecessors(DestBB), SelectBB))
+ Updates.push_back({DominatorTree::Insert, SelectBB, DestBB});
+ Builder.CreateBr(DestBB);
+
+ // Remove the switch.
+
while (PHI->getBasicBlockIndex(SelectBB) >= 0)
PHI->removeIncomingValue(SelectBB);
PHI->addIncoming(SelectValue, SelectBB);
- Builder.CreateBr(PHI->getParent());
-
- std::vector<DominatorTree::UpdateType> Updates;
-
- // Remove the switch.
for (unsigned i = 0, e = SI->getNumSuccessors(); i < e; ++i) {
BasicBlock *Succ = SI->getSuccessor(i);
- if (Succ == PHI->getParent())
+ if (Succ == DestBB)
continue;
Succ->removePredecessor(SelectBB);
Updates.push_back({DominatorTree::Delete, SelectBB, Succ});