diff options
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index afaaf51952..6c632c2aee 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -717,12 +717,20 @@ static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB, I->getOperand(i).setMachineBasicBlock(New); } - // Update the successor information. + // Update the successor information. If New was already a successor, just + // remove the link to Old instead of creating another one. PR 1444. + bool HadSuccessorNew = false; std::vector<MachineBasicBlock*> Succs(BB->succ_begin(), BB->succ_end()); for (int i = Succs.size()-1; i >= 0; --i) + if (Succs[i] == New) { + HadSuccessorNew = true; + break; + } + for (int i = Succs.size()-1; i >= 0; --i) if (Succs[i] == Old) { BB->removeSuccessor(Old); - BB->addSuccessor(New); + if (!HadSuccessorNew) + BB->addSuccessor(New); } } |