Index: include/llvm/Support/GenericDomTree.h =================================================================== --- include/llvm/Support/GenericDomTree.h +++ include/llvm/Support/GenericDomTree.h @@ -666,10 +666,30 @@ /// splitBlock - BB is split and now it has one successor. Update dominator /// tree to reflect this change. void splitBlock(NodeT *NewBB) { - if (IsPostDominator) - Split>(NewBB); - else + if (!IsPostDominator) Split(NewBB); + else { + // FIXME: Split(NewBB) only works for dominator trees. For post-dominator + // trees we just uses applyUpdates and so is potentially less efficient + // than it could be. + using GraphT = GraphTraits; + assert(std::distance(GraphT::child_begin(NewBB), + GraphT::child_end(NewBB)) == 1 && + "NewBB should have a single successor!"); + NodeT *OldBB = *GraphT::child_begin(NewBB); + + std::vector Updates; + SmallPtrSet Visited; + for (auto *Pred : children>(NewBB)) { + if (!Visited.insert(Pred).second) + // Make sure our updates and balanced, even if Pred is a child + // multiple times + continue; + Updates.emplace_back(UpdateKind::Insert, Pred, NewBB); + Updates.emplace_back(UpdateKind::Delete, Pred, OldBB); + } + applyUpdates(Updates); + } } /// print - Convert to human readable form