Index: llvm/lib/CodeGen/IfConversion.cpp =================================================================== --- llvm/lib/CodeGen/IfConversion.cpp +++ llvm/lib/CodeGen/IfConversion.cpp @@ -1584,8 +1584,11 @@ MergeBlocks(BBI, *CvtBBI, false); } - // Keep the CFG updated. - BBI.BB->removeSuccessor(&CvtMBB, true); + // Keep the CFG updated. If CvtMBB and NextMBB happen to be the same we skip + // removing CvtMBB as successor since that would also remove NextMBB (which we + // want to keep). + if (&CvtMBB != &NextMBB) + BBI.BB->removeSuccessor(&CvtMBB, true); // If 'true' block has a 'false' successor, add an exit branch to it. if (HasEarlyExit) { Index: llvm/test/CodeGen/ARM/ifcvt_triangleSameCvtNext.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/ARM/ifcvt_triangleSameCvtNext.mir @@ -0,0 +1,30 @@ +# RUN: llc -mtriple=arm-apple-ios -run-pass=if-converter -verify-machineinstrs %s -o - | FileCheck %s +... +--- +name: foo +body: | + bb.0: + Bcc %bb.2, 1, $cpsr + + bb.1: + $sp = tADDspi $sp, 2, 14, _ + B %bb.1 + + bb.2: + Bcc %bb.3, 0, $cpsr + B %bb.2 + + bb.3: + Bcc %bb.1, 1, $cpsr + B %bb.1 +... + +# Both branches in bb.3 jump to bb.1. IfConversion treats it as a triangle with +# CvtBB and NextBB both being bb.1. We must make sure that bb.3 at the end still +# has bb.1 as a successor or the CFG will be broken and verifiers will complain +# that the block ends with a branch but the successor list is empty. + +# CHECK: bb.3: +# CHECK: successors: %bb.1 +# CHECK: $sp = tADDspi $sp, 2, 1, $cpsr +# CHECK: B %bb.1