diff --git a/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp b/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp index 87d62f1619bc3..6de366c2bb664 100644 --- a/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp +++ b/llvm/lib/Target/PowerPC/PPCCTRLoops.cpp @@ -114,14 +114,10 @@ bool PPCCTRLoops::isCTRClobber(MachineInstr *MI, bool CheckReads) const { // CTR defination inside the callee of a call instruction will not impact // the defination of MTCTRloop, so we can use definesRegister() for the // check, no need to check the regmask. - return (MI->definesRegister(PPC::CTR) && - !MI->registerDefIsDead(PPC::CTR)) || - (MI->definesRegister(PPC::CTR8) && - !MI->registerDefIsDead(PPC::CTR8)); + return MI->definesRegister(PPC::CTR) || MI->definesRegister(PPC::CTR8); } - if ((MI->modifiesRegister(PPC::CTR) && !MI->registerDefIsDead(PPC::CTR)) || - (MI->modifiesRegister(PPC::CTR8) && !MI->registerDefIsDead(PPC::CTR8))) + if (MI->modifiesRegister(PPC::CTR) || MI->modifiesRegister(PPC::CTR8)) return true; if (MI->getDesc().isCall()) diff --git a/llvm/test/CodeGen/PowerPC/ctrloops64.mir b/llvm/test/CodeGen/PowerPC/ctrloops64.mir index 8e50c555195b1..de37e6accd40e 100644 --- a/llvm/test/CodeGen/PowerPC/ctrloops64.mir +++ b/llvm/test/CodeGen/PowerPC/ctrloops64.mir @@ -345,3 +345,30 @@ body: | BLR8 implicit $lr8, implicit $rm ... +--- +name: test_fail_dead_def_in_preheader +# CHECK: test_fail_dead_def_in_preheader +tracksRegLiveness: true +body: | + bb.0.entry: + + %0:g8rc = LI8 2048 + %1:g8rc = LI8 1024 + MTCTR8loop killed %0:g8rc, implicit-def dead $ctr8 + MTCTR8 killed %1:g8rc, implicit-def dead $ctr8 + ; CHECK-NOT: MTCTR8loop + ; CHECK-NOT: BDNZ8 + ; CHECK: ADDI8 + ; CHECK: CMPLDI + ; CHECK: BC + + bb.1: + + %2:crbitrc = DecreaseCTR8loop 1, implicit-def dead $ctr8, implicit $ctr8 + BC killed %2:crbitrc, %bb.1 + B %bb.2 + + bb.2: + + BLR8 implicit $lr8, implicit $rm +...