FastISel: Avoid adding a successor block twice for degenerate IR.
This fixes http://llvm.org/PR24581
Differential Revision: http://reviews.llvm.org/D12350
llvm-svn: 246074
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index d5011d2..13b097c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1415,7 +1415,11 @@
if (FuncInfo.BPI)
BranchWeight = FuncInfo.BPI->getEdgeWeight(BranchBB,
TrueMBB->getBasicBlock());
- FuncInfo.MBB->addSuccessor(TrueMBB, BranchWeight);
+ // Add TrueMBB as successor unless it is equal to the FalseMBB: This can
+ // happen in degenerate IR and MachineIR forbids to have a block twice in the
+ // successor/predecessor lists.
+ if (TrueMBB != FalseMBB)
+ FuncInfo.MBB->addSuccessor(TrueMBB, BranchWeight);
fastEmitBranch(FalseMBB, DbgLoc);
}