diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1610,16 +1610,22 @@ SmallVector Updates; + SmallSetVector SuccsToUpdate; // Update any PHI nodes in our new successors. for (BasicBlock *Succ : successors(BB1)) { AddPredecessorToBlock(Succ, BIParent, BB1); if (DTU) - Updates.push_back({DominatorTree::Insert, BIParent, Succ}); + SuccsToUpdate.insert(Succ); } - if (DTU) - for (BasicBlock *Succ : successors(BI)) - Updates.push_back({DominatorTree::Delete, BIParent, Succ}); + if (DTU) { + for (BasicBlock *Succ : SuccsToUpdate) + Updates.push_back({DominatorTree::Insert, BIParent, Succ}); + + Updates.push_back({DominatorTree::Delete, BIParent, BB1}); + if (BB1 != BB2) + Updates.push_back({DominatorTree::Delete, BIParent, BB2}); + } EraseTerminatorAndDCECond(BI); if (DTU)