Skip to content

Commit 518ecac

Browse files
author
Paul Murphy
committed
[PowerPC] fix lowering of SPILL_CRBIT on pwr9 and pwr10
If a copy exists between creation of a crbit and a spill, machine-cp may delete the copy since it seems unaware of the relation between a cr and crbit. A fix was previously made for the generic ppc64 lowering. It should be applied to the pwr9 and pwr10 variants too. Likewise, relax and extend the pwr8 test to verify pwr9 and pwr10 codegen too. This fixes #143989.
1 parent 93849a3 commit 518ecac

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

llvm/lib/Target/PowerPC/PPCRegisterInfo.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,24 +1105,31 @@ void PPCRegisterInfo::lowerCRBitSpilling(MachineBasicBlock::iterator II,
11051105
// On Power10, we can use SETNBC to spill all CR bits. SETNBC will set all
11061106
// bits (specifically, it produces a -1 if the CR bit is set). Ultimately,
11071107
// the bit that is of importance to us is bit 32 (bit 0 of a 32-bit
1108-
// register), and SETNBC will set this.
1108+
// register), and SETNBC will set this. Also, in order to preserve the kill
1109+
// flag on the CR bit, we add it as an implicit use.
11091110
if (Subtarget.isISA3_1()) {
11101111
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::SETNBC8 : PPC::SETNBC), Reg)
1111-
.addReg(SrcReg, RegState::Undef);
1112+
.addReg(SrcReg, RegState::Undef)
1113+
.addReg(SrcReg, RegState::Implicit |
1114+
getKillRegState(MI.getOperand(0).isKill()));
11121115
break;
11131116
}
11141117

11151118
// On Power9, we can use SETB to extract the LT bit. This only works for
11161119
// the LT bit since SETB produces -1/1/0 for LT/GT/<neither>. So the value
11171120
// of the bit we care about (32-bit sign bit) will be set to the value of
1118-
// the LT bit (regardless of the other bits in the CR field).
1121+
// the LT bit (regardless of the other bits in the CR field). Also, in
1122+
// order to preserve the kill flag on the CR bit, we add it as an implicit
1123+
// use.
11191124
if (Subtarget.isISA3_0()) {
11201125
if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR1LT ||
11211126
SrcReg == PPC::CR2LT || SrcReg == PPC::CR3LT ||
11221127
SrcReg == PPC::CR4LT || SrcReg == PPC::CR5LT ||
11231128
SrcReg == PPC::CR6LT || SrcReg == PPC::CR7LT) {
11241129
BuildMI(MBB, II, dl, TII.get(LP64 ? PPC::SETB8 : PPC::SETB), Reg)
1125-
.addReg(getCRFromCRBit(SrcReg), RegState::Undef);
1130+
.addReg(getCRFromCRBit(SrcReg), RegState::Undef)
1131+
.addReg(SrcReg, RegState::Implicit |
1132+
getKillRegState(MI.getOperand(0).isKill()));
11261133
break;
11271134
}
11281135
}

llvm/test/CodeGen/PowerPC/NoCRFieldRedefWhenSpillingCRBIT.mir

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# RUN: llc -mcpu=pwr8 -mtriple=powerpc64le-unknown-linux-gnu -start-after \
22
# RUN: virtregrewriter -ppc-asm-full-reg-names -verify-machineinstrs %s \
33
# RUN: -o - | FileCheck %s
4+
# RUN: llc -mcpu=pwr9 -mtriple=powerpc64le-unknown-linux-gnu -start-after \
5+
# RUN: virtregrewriter -ppc-asm-full-reg-names -verify-machineinstrs %s \
6+
# RUN: -o - | FileCheck %s
7+
# RUN: llc -mcpu=pwr10 -mtriple=powerpc64le-unknown-linux-gnu -start-after \
8+
# RUN: virtregrewriter -ppc-asm-full-reg-names -verify-machineinstrs %s \
9+
# RUN: -o - | FileCheck %s
410

511
--- |
612
; ModuleID = 'a.ll'
@@ -30,7 +36,7 @@
3036
; Function Attrs: nounwind
3137
declare void @llvm.stackprotector(ptr, ptr) #1
3238

33-
attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="ppc64le" "target-features"="+altivec,+bpermd,+crypto,+direct-move,+extdiv,+htm,+power8-vector,+vsx,-power9-vector" "unsafe-fp-math"="false" "use-soft-float"="false" }
39+
attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
3440
attributes #1 = { nounwind }
3541

3642
!llvm.ident = !{!0}

0 commit comments

Comments
 (0)