diff --git a/llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp b/llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp --- a/llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp +++ b/llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp @@ -77,8 +77,9 @@ if (J->getOperand(0).getMBB() == &ReturnMBB) { // This is an unconditional branch to the return. Replace the // branch with a blr. - BuildMI(**PI, J, J->getDebugLoc(), TII->get(I->getOpcode())) - .copyImplicitOps(*I); + MachineInstr *MI = ReturnMBB.getParent()->CloneMachineInstr(&*I); + (*PI)->insert(J, MI); + MachineBasicBlock::iterator K = J--; K->eraseFromParent(); BlockChanged = true; @@ -89,10 +90,13 @@ if (J->getOperand(2).getMBB() == &ReturnMBB) { // This is a conditional branch to the return. Replace the branch // with a bclr. - BuildMI(**PI, J, J->getDebugLoc(), TII->get(PPC::BCCLR)) + MachineInstr *MI = ReturnMBB.getParent()->CloneMachineInstr(&*I); + MI->setDesc(TII->get(PPC::BCCLR)); + MachineInstrBuilder(*ReturnMBB.getParent(), MI) .addImm(J->getOperand(0).getImm()) - .addReg(J->getOperand(1).getReg()) - .copyImplicitOps(*I); + .addReg(J->getOperand(1).getReg()); + (*PI)->insert(J, MI); + MachineBasicBlock::iterator K = J--; K->eraseFromParent(); BlockChanged = true; @@ -103,11 +107,13 @@ if (J->getOperand(1).getMBB() == &ReturnMBB) { // This is a conditional branch to the return. Replace the branch // with a bclr. - BuildMI( - **PI, J, J->getDebugLoc(), - TII->get(J->getOpcode() == PPC::BC ? PPC::BCLR : PPC::BCLRn)) - .addReg(J->getOperand(0).getReg()) - .copyImplicitOps(*I); + MachineInstr *MI = ReturnMBB.getParent()->CloneMachineInstr(&*I); + MI->setDesc( + TII->get(J->getOpcode() == PPC::BC ? PPC::BCLR : PPC::BCLRn)); + MachineInstrBuilder(*ReturnMBB.getParent(), MI) + .addReg(J->getOperand(0).getReg()); + (*PI)->insert(J, MI); + MachineBasicBlock::iterator K = J--; K->eraseFromParent(); BlockChanged = true; diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.td b/llvm/lib/Target/PowerPC/PPCInstrInfo.td --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.td +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.td @@ -1523,11 +1523,12 @@ def BCn : BForm_4<16, 4, 0, 0, (outs), (ins crbitrc:$bi, condbrtarget:$dst), "bc 4, $bi, $dst">; - let isReturn = 1, Uses = [LR, RM] in + let isReturn = 1, Uses = [LR, RM] in { def BCLR : XLForm_2_br2<19, 16, 12, 0, (outs), (ins crbitrc:$bi), "bclr 12, $bi, 0", IIC_BrB, []>; def BCLRn : XLForm_2_br2<19, 16, 4, 0, (outs), (ins crbitrc:$bi), "bclr 4, $bi, 0", IIC_BrB, []>; + } } let isReturn = 1, Defs = [CTR], Uses = [CTR, LR, RM] in { diff --git a/llvm/test/CodeGen/PowerPC/early-ret-verify.mir b/llvm/test/CodeGen/PowerPC/early-ret-verify.mir --- a/llvm/test/CodeGen/PowerPC/early-ret-verify.mir +++ b/llvm/test/CodeGen/PowerPC/early-ret-verify.mir @@ -40,7 +40,7 @@ ; CHECK-LABEL: testEarlyRet ; CHECK: bb.0.entry: - ; CHECK: BCLR $cr5lt, implicit $lr, implicit $rm, implicit $lr, implicit $rm + ; CHECK: BCLR $cr5lt, implicit $lr, implicit $rm ; CHECK: bb.1: ; CHECK: renamable $r3 = IMPLICIT_DEF ; CHECK: renamable $r4 = IMPLICIT_DEF diff --git a/llvm/test/CodeGen/PowerPC/early-ret.mir b/llvm/test/CodeGen/PowerPC/early-ret.mir --- a/llvm/test/CodeGen/PowerPC/early-ret.mir +++ b/llvm/test/CodeGen/PowerPC/early-ret.mir @@ -27,7 +27,7 @@ ; CHECK: bb.0.entry: ; CHECK: renamable $cr0 = CMPWI renamable $r3, 0 ; CHECK: BC killed renamable $cr0gt, %bb.1 - ; CHECK: BLR implicit $lr, implicit $rm, implicit $lr, implicit $rm, implicit killed $r3 + ; CHECK: BLR implicit $lr, implicit $rm, implicit killed $r3 ; CHECK: bb.1.entry: ; CHECK: renamable $r3 = ADDI killed renamable $r4, 0 ; CHECK: BLR implicit $lr, implicit $rm, implicit killed $r3 @@ -106,7 +106,7 @@ ; CHECK-LABEL: name: testBCLR ; CHECK: bb.0.entry: ; CHECK: renamable $cr0 = FCMPUS killed renamable $f3, killed renamable $f4 - ; CHECK: BCLR $cr0eq, implicit $lr, implicit $rm, implicit $lr, implicit $rm, implicit killed $v2 + ; CHECK: BCLR $cr0eq, implicit $lr, implicit $rm, implicit killed $v2 ; CHECK: bb.1.entry: ; CHECK: renamable $cr0 = FCMPUS killed renamable $f1, killed renamable $f2 ; CHECK: BCLRn killed renamable $cr0eq, implicit $lr, implicit $rm, implicit killed $v2 @@ -139,8 +139,8 @@ ; CHECK: bb.0.entry: ; CHECK: renamable $r4 = LI 0 ; CHECK: renamable $cr0 = CMPLWI killed renamable $r4, 0 - ; CHECK: BCCLR 68, $cr0, implicit $lr, implicit $rm, implicit $lr, implicit $rm + ; CHECK: BCCLR 68, $cr0, implicit $lr, implicit $rm ; CHECK: bb.1: - ; CHECK: BCCLR 68, $cr0, implicit $lr, implicit $rm, implicit $lr, implicit $rm + ; CHECK: BCCLR 68, $cr0, implicit $lr, implicit $rm ; CHECK: BLR implicit $lr, implicit $rm ...