Skip to content

Commit 2001146

Browse files
committed
[PowerPC] Do not rely on MachineSink threshold to optimize CR spilling
spill_p0_setb.ll and knowCRBitSpill.ll rely on a probability threshold in MachineSink to pull down CRSET/CRUNSET. It's worth to do so anyway and let register allocation decide otherwise. Additionally, make the interface accept a const MI.
1 parent 9889de8 commit 2001146

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class TargetInstrInfo : public MCInstrInfo {
165165

166166
/// For a "cheap" instruction which doesn't enable additional sinking,
167167
/// should MachineSink break a critical edge to sink it anyways?
168-
virtual bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const {
168+
virtual bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const {
169169
return false;
170170
}
171171

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,13 @@ Register PPCInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
10721072
return 0;
10731073
}
10741074

1075+
/// Sink down CodeGen-only, cheap instructions to allow further
1076+
/// optimizations which are only applied intra-block.
1077+
bool PPCInstrInfo::shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const {
1078+
// These can turn into immediates, see PPCRegisterInfo::lowerCRBitRestore.
1079+
return MI.getOpcode() == PPC::CRSET || MI.getOpcode() == PPC::CRUNSET;
1080+
}
1081+
10751082
// For opcodes with the ReMaterializable flag set, this function is called to
10761083
// verify the instruction is really rematable.
10771084
bool PPCInstrInfo::isReallyTriviallyReMaterializable(

llvm/lib/Target/PowerPC/PPCInstrInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class PPCInstrInfo : public PPCGenInstrInfo {
424424
unsigned &SubIdx) const override;
425425
Register isLoadFromStackSlot(const MachineInstr &MI,
426426
int &FrameIndex) const override;
427+
bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const override;
427428
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
428429
Register isStoreToStackSlot(const MachineInstr &MI,
429430
int &FrameIndex) const override;

llvm/lib/Target/RISCV/RISCVInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class RISCVInstrInfo : public RISCVGenInstrInfo {
7878

7979
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
8080

81-
bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const override {
81+
bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const override {
8282
return MI.getOpcode() == RISCV::ADDI && MI.getOperand(1).isReg() &&
8383
MI.getOperand(1).getReg() == RISCV::X0;
8484
}

llvm/test/CodeGen/PowerPC/spill_p9_setb.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
define void @p9_setb_spill() {
1818
; CHECK-P9-LABEL: p9_setb_spill:
19-
; CHECK-P9: # %bb.1: # %if.then
19+
; CHECK-P9: # %if.then
2020
; CHECK-P9-DAG: crnot 4*cr[[CREG:.*]]+lt, eq
2121
; CHECK-P9-DAG: setb [[REG1:.*]], cr[[CREG]]
2222
; CHECK-P9-DAG: stw [[REG1]]
2323
; CHECK-P9: blr
24-
; CHECK-P9: .LBB0_4: # %if.then1
24+
; CHECK-P9: # %if.then1
2525
;
2626
; CHECK-P8-LABEL: p9_setb_spill:
27-
; CHECK-P8: # %bb.1: # %if.then
27+
; CHECK-P8: # %if.then
2828
; CHECK-P8-DAG: crnot 4*cr[[CREG2:.*]]+lt, eq
2929
; CHECK-P8-DAG: mfocrf [[REG2:.*]],
3030
; CHECK-P8-DAG: rlwinm [[REG2]], [[REG2]]
3131
; CHECK-P8-DAG: stw [[REG2]]
3232
; CHECK-P8: blr
33-
; CHECK-P8: .LBB0_4: # %if.then1
33+
; CHECK-P8: # %if.then1
3434
entry:
3535
br i1 undef, label %if.end, label %if.then
3636

0 commit comments

Comments
 (0)