-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[PowerPC] Do not rely on MachineSink threshold to optimize CR spilling #128745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-backend-powerpc Author: Guy David (guy-david) Changesspill_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. Required by #127666. Full diff: https://github.com/llvm/llvm-project/pull/128745.diff 5 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index 9e7893d5c4142..bbbe7e667d73b 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -165,7 +165,7 @@ class TargetInstrInfo : public MCInstrInfo {
/// For a "cheap" instruction which doesn't enable additional sinking,
/// should MachineSink break a critical edge to sink it anyways?
- virtual bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const {
+ virtual bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const {
return false;
}
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
index 9b526066fe75b..974db8c918c2e 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -1072,6 +1072,13 @@ Register PPCInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
return 0;
}
+/// Sink down CodeGen-only, cheap instructions to allow further
+/// optimizations which are only applied intra-block.
+bool PPCInstrInfo::shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const {
+ // These can turn into immediates, see PPCRegisterInfo::lowerCRBitRestore.
+ return MI.getOpcode() == PPC::CRSET || MI.getOpcode() == PPC::CRUNSET;
+}
+
// For opcodes with the ReMaterializable flag set, this function is called to
// verify the instruction is really rematable.
bool PPCInstrInfo::isReallyTriviallyReMaterializable(
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.h b/llvm/lib/Target/PowerPC/PPCInstrInfo.h
index d4554379cdb1d..892a670dbfce1 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.h
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.h
@@ -424,6 +424,7 @@ class PPCInstrInfo : public PPCGenInstrInfo {
unsigned &SubIdx) const override;
Register isLoadFromStackSlot(const MachineInstr &MI,
int &FrameIndex) const override;
+ bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const override;
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
Register isStoreToStackSlot(const MachineInstr &MI,
int &FrameIndex) const override;
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.h b/llvm/lib/Target/RISCV/RISCVInstrInfo.h
index 1c46d761a7e1e..465bbd5dc2b60 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.h
@@ -78,7 +78,7 @@ class RISCVInstrInfo : public RISCVGenInstrInfo {
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
- bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const override {
+ bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const override {
return MI.getOpcode() == RISCV::ADDI && MI.getOperand(1).isReg() &&
MI.getOperand(1).getReg() == RISCV::X0;
}
diff --git a/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll b/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll
index 81c43ce85d59a..b740296e7d710 100644
--- a/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll
+++ b/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll
@@ -16,21 +16,21 @@
define void @p9_setb_spill() {
; CHECK-P9-LABEL: p9_setb_spill:
-; CHECK-P9: # %bb.1: # %if.then
+; CHECK-P9: # %if.then
; CHECK-P9-DAG: crnot 4*cr[[CREG:.*]]+lt, eq
; CHECK-P9-DAG: setb [[REG1:.*]], cr[[CREG]]
; CHECK-P9-DAG: stw [[REG1]]
; CHECK-P9: blr
-; CHECK-P9: .LBB0_4: # %if.then1
+; CHECK-P9: # %if.then1
;
; CHECK-P8-LABEL: p9_setb_spill:
-; CHECK-P8: # %bb.1: # %if.then
+; CHECK-P8: # %if.then
; CHECK-P8-DAG: crnot 4*cr[[CREG2:.*]]+lt, eq
; CHECK-P8-DAG: mfocrf [[REG2:.*]],
; CHECK-P8-DAG: rlwinm [[REG2]], [[REG2]]
; CHECK-P8-DAG: stw [[REG2]]
; CHECK-P8: blr
-; CHECK-P8: .LBB0_4: # %if.then1
+; CHECK-P8: # %if.then1
entry:
br i1 undef, label %if.end, label %if.then
|
|
@llvm/pr-subscribers-backend-risc-v Author: Guy David (guy-david) Changesspill_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. Required by #127666. Full diff: https://github.com/llvm/llvm-project/pull/128745.diff 5 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index 9e7893d5c4142..bbbe7e667d73b 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -165,7 +165,7 @@ class TargetInstrInfo : public MCInstrInfo {
/// For a "cheap" instruction which doesn't enable additional sinking,
/// should MachineSink break a critical edge to sink it anyways?
- virtual bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const {
+ virtual bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const {
return false;
}
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
index 9b526066fe75b..974db8c918c2e 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -1072,6 +1072,13 @@ Register PPCInstrInfo::isLoadFromStackSlot(const MachineInstr &MI,
return 0;
}
+/// Sink down CodeGen-only, cheap instructions to allow further
+/// optimizations which are only applied intra-block.
+bool PPCInstrInfo::shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const {
+ // These can turn into immediates, see PPCRegisterInfo::lowerCRBitRestore.
+ return MI.getOpcode() == PPC::CRSET || MI.getOpcode() == PPC::CRUNSET;
+}
+
// For opcodes with the ReMaterializable flag set, this function is called to
// verify the instruction is really rematable.
bool PPCInstrInfo::isReallyTriviallyReMaterializable(
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.h b/llvm/lib/Target/PowerPC/PPCInstrInfo.h
index d4554379cdb1d..892a670dbfce1 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.h
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.h
@@ -424,6 +424,7 @@ class PPCInstrInfo : public PPCGenInstrInfo {
unsigned &SubIdx) const override;
Register isLoadFromStackSlot(const MachineInstr &MI,
int &FrameIndex) const override;
+ bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const override;
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
Register isStoreToStackSlot(const MachineInstr &MI,
int &FrameIndex) const override;
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.h b/llvm/lib/Target/RISCV/RISCVInstrInfo.h
index 1c46d761a7e1e..465bbd5dc2b60 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.h
@@ -78,7 +78,7 @@ class RISCVInstrInfo : public RISCVGenInstrInfo {
bool isReallyTriviallyReMaterializable(const MachineInstr &MI) const override;
- bool shouldBreakCriticalEdgeToSink(MachineInstr &MI) const override {
+ bool shouldBreakCriticalEdgeToSink(const MachineInstr &MI) const override {
return MI.getOpcode() == RISCV::ADDI && MI.getOperand(1).isReg() &&
MI.getOperand(1).getReg() == RISCV::X0;
}
diff --git a/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll b/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll
index 81c43ce85d59a..b740296e7d710 100644
--- a/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll
+++ b/llvm/test/CodeGen/PowerPC/spill_p9_setb.ll
@@ -16,21 +16,21 @@
define void @p9_setb_spill() {
; CHECK-P9-LABEL: p9_setb_spill:
-; CHECK-P9: # %bb.1: # %if.then
+; CHECK-P9: # %if.then
; CHECK-P9-DAG: crnot 4*cr[[CREG:.*]]+lt, eq
; CHECK-P9-DAG: setb [[REG1:.*]], cr[[CREG]]
; CHECK-P9-DAG: stw [[REG1]]
; CHECK-P9: blr
-; CHECK-P9: .LBB0_4: # %if.then1
+; CHECK-P9: # %if.then1
;
; CHECK-P8-LABEL: p9_setb_spill:
-; CHECK-P8: # %bb.1: # %if.then
+; CHECK-P8: # %if.then
; CHECK-P8-DAG: crnot 4*cr[[CREG2:.*]]+lt, eq
; CHECK-P8-DAG: mfocrf [[REG2:.*]],
; CHECK-P8-DAG: rlwinm [[REG2]], [[REG2]]
; CHECK-P8-DAG: stw [[REG2]]
; CHECK-P8: blr
-; CHECK-P8: .LBB0_4: # %if.then1
+; CHECK-P8: # %if.then1
entry:
br i1 undef, label %if.end, label %if.then
|
2001146 to
fdcf246
Compare
mshockwave
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me. However, I'm not really familiar with the PPC instructions mentioned in this patch, could you tag some PowerPC folks to give this a look too?
fdcf246 to
40b923a
Compare
40b923a to
cebcc2f
Compare
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.
cebcc2f to
95af9b3
Compare
|
Closing because the PR that required this is no longer relevant: #127666. |
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.
Required by #127666.