diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp @@ -4784,7 +4784,12 @@ LLVM_DEBUG(DefMI.dump()); MI.getOperand(III.OpNoForForwarding).setReg(RegMO->getReg()); - MI.getOperand(III.OpNoForForwarding).setIsKill(RegMO->isKill()); + if (RegMO->isKill()) { + MI.getOperand(III.OpNoForForwarding).setIsKill(true); + // Clear the killed flag in RegMO. Doing this here can handle some cases + // that DefMI and MI are not in same basic block. + RegMO->setIsKill(false); + } MI.getOperand(III.ImmOpNo).setImm(Imm); // FIXME: fix kill/dead flag if MI and DefMI are not in same basic block. diff --git a/llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir b/llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir --- a/llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir +++ b/llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir @@ -65,3 +65,35 @@ $x3 = COPY %5:g8rc BLR8 implicit $lr8, implicit $rm, implicit $x3 ... +--- +name: killFlagSameBlock +#CHECK : name : killFlagSameBlock +tracksRegLiveness: true +body: | + bb.0.entry: + liveins: $x3 + %0:g8rc_and_g8rc_nox0 = COPY $x3 + %1:g8rc_and_g8rc_nox0 = ADDI8 killed %0:g8rc_and_g8rc_nox0, -8 + ; CHECK: %1:g8rc_and_g8rc_nox0 = ADDI8 %0, -8 + %2:g8rc = LI8 0 + ; CHECK: STD killed %2, 8, killed %0 + STD killed %2:g8rc, 16, %1:g8rc_and_g8rc_nox0 + BLR8 implicit $lr8, implicit $rm +... +--- +name: killFlagDifferentBlocks +#CHECK : name : killFlagDifferentBlocks +tracksRegLiveness: true +body: | + bb.0.entry: + liveins: $x3 + %0:g8rc_and_g8rc_nox0 = COPY $x3 + ; CHECK: %1:g8rc_and_g8rc_nox0 = ADDI8 %0, -8 + %1:g8rc_and_g8rc_nox0 = ADDI8 killed %0:g8rc_and_g8rc_nox0, -8 + + bb.1: + %2:g8rc = LI8 0 + ; CHECK: STD killed %2, 8, killed %0 + STD killed %2:g8rc, 16, %1:g8rc_and_g8rc_nox0 + BLR8 implicit $lr8, implicit $rm +...