Index: lib/CodeGen/IfConversion.cpp =================================================================== --- lib/CodeGen/IfConversion.cpp +++ lib/CodeGen/IfConversion.cpp @@ -1723,11 +1723,15 @@ // Skip past the dups on each side separately since there may be // differing dbg_value entries. for (unsigned i = 0; i < NumDups1; ++DI1) { + if (DI1 == MBB1.end()) + break; if (!DI1->isDebugValue()) ++i; } while (NumDups1 != 0) { ++DI2; + if (DI2 == MBB2.end()) + break; if (!DI2->isDebugValue()) --NumDups1; } @@ -1762,6 +1766,12 @@ } MBB1.erase(DI1, MBB1.end()); + // Identical blocks, already moved all the instructions up. + if (MBB1.empty() && MBB2.empty()) { + BBI.BB->removeSuccessor(&MBB1, true); + BBI.BB->removeSuccessor(&MBB2, true); + return true; + } DI2 = BBI2->BB->end(); // The branches have been checked to match. Skip over the branch in the false // block so that we don't try to predicate it. Index: test/CodeGen/MIR/PowerPC/ifcvt-diamond-ret.mir =================================================================== --- /dev/null +++ test/CodeGen/MIR/PowerPC/ifcvt-diamond-ret.mir @@ -0,0 +1,34 @@ +# RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -run-pass=if-converter %s -o - | FileCheck %s +--- +name: foo +body: | + bb.0: + liveins: $x0, $x3 + successors: %bb.1(0x40000000), %bb.2(0x40000000) + + dead renamable $x3 = ANDIo8 killed renamable $x3, 1, implicit-def dead $cr0, implicit-def $cr0gt + $cr2lt = CROR $cr0gt, $cr0gt + BCn killed renamable $cr2lt, %bb.2 + B %bb.1 + + bb.1: + renamable $x3 = LIS8 4096 + MTLR8 $x0, implicit-def $lr8 + BLR8 implicit $lr8, implicit $rm, implicit $x3 + + bb.2: + renamable $x3 = LIS8 4096 + MTLR8 $x0, implicit-def $lr8 + BLR8 implicit $lr8, implicit $rm, implicit $x3 +... + +# Diamond testcase with equivalent branches terminating in returns. + +# CHECK: body: | +# CHECK: bb.0: +# CHECK: dead renamable $x3 = ANDIo8 killed renamable $x3, 1, implicit-def dead $cr0, implicit-def $cr0gt +# CHECK: $cr2lt = CROR $cr0gt, $cr0gt +# CHECK: renamable $x3 = LIS8 4096 +# CHECK: MTLR8 $x0, implicit-def $lr8 +# CHECK: BLR8 implicit $lr8, implicit $rm, implicit $x3 +