-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[RISCV] Add X27 to SavedRegs when X26 is in SavedRegs for cm.push/pop #92067
Conversation
cm.push can't save X26 without also saving X27. This removes two other checks for this case. This causes CFI to be emitted since X27 is now explicitly a callee saved register. The affected tests use inline assembly to clobber X26 rather than the whole range of s0-s10.
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) Changescm.push can't save X26 without also saving X27. This removes two other checks for this case. This causes CFI to be emitted since X27 is now explicitly a callee saved register. The affected tests use inline assembly to clobber X26 rather than the whole range of s0-s10. Full diff: https://github.com/llvm/llvm-project/pull/92067.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 316f6a90893a6..436bd4a38a319 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -265,7 +265,6 @@ getPushPopEncodingAndNum(const Register MaxReg) {
default:
llvm_unreachable("Unexpected Reg for Push/Pop Inst");
case RISCV::X27: /*s11*/
- case RISCV::X26: /*s10*/
return std::make_pair(llvm::RISCVZC::RLISTENCODE::RA_S0_S11, 13);
case RISCV::X25: /*s9*/
return std::make_pair(llvm::RISCVZC::RLISTENCODE::RA_S0_S9, 11);
@@ -302,9 +301,7 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
}) != std::end(FixedCSRFIMap))
MaxPushPopReg = std::max(MaxPushPopReg.id(), CS.getReg().id());
}
- // if rlist is {rs, s0-s10}, then s11 will also be included
- if (MaxPushPopReg == RISCV::X26)
- MaxPushPopReg = RISCV::X27;
+ assert(MaxPushPopReg != RISCV::X26 && "x26 requires x27 to also be pushed");
return MaxPushPopReg;
}
@@ -1047,6 +1044,11 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
// Mark BP as used if function has dedicated base pointer.
if (hasBP(MF))
SavedRegs.set(RISCVABI::getBPReg());
+
+ // When using cm.push/pop we must save X27 if we save X26.
+ auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
+ if (RVFI->isPushable(MF) && SavedRegs.test(RISCV::X26))
+ SavedRegs.set(RISCV::X27);
}
std::pair<int64_t, Align>
diff --git a/llvm/test/CodeGen/RISCV/push-pop-popret.ll b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
index e007dcc764e9d..7548faaae61f4 100644
--- a/llvm/test/CodeGen/RISCV/push-pop-popret.ll
+++ b/llvm/test/CodeGen/RISCV/push-pop-popret.ll
@@ -3225,6 +3225,7 @@ define void @spill_x10() {
; RV32IZCMP-NEXT: cm.push {ra, s0-s11}, -64
; RV32IZCMP-NEXT: .cfi_def_cfa_offset 64
; RV32IZCMP-NEXT: .cfi_offset s10, -8
+; RV32IZCMP-NEXT: .cfi_offset s11, -4
; RV32IZCMP-NEXT: #APP
; RV32IZCMP-NEXT: li s10, 0
; RV32IZCMP-NEXT: #NO_APP
@@ -3235,6 +3236,7 @@ define void @spill_x10() {
; RV64IZCMP-NEXT: cm.push {ra, s0-s11}, -112
; RV64IZCMP-NEXT: .cfi_def_cfa_offset 112
; RV64IZCMP-NEXT: .cfi_offset s10, -16
+; RV64IZCMP-NEXT: .cfi_offset s11, -8
; RV64IZCMP-NEXT: #APP
; RV64IZCMP-NEXT: li s10, 0
; RV64IZCMP-NEXT: #NO_APP
@@ -3245,6 +3247,7 @@ define void @spill_x10() {
; RV32IZCMP-SR-NEXT: cm.push {ra, s0-s11}, -64
; RV32IZCMP-SR-NEXT: .cfi_def_cfa_offset 64
; RV32IZCMP-SR-NEXT: .cfi_offset s10, -8
+; RV32IZCMP-SR-NEXT: .cfi_offset s11, -4
; RV32IZCMP-SR-NEXT: #APP
; RV32IZCMP-SR-NEXT: li s10, 0
; RV32IZCMP-SR-NEXT: #NO_APP
@@ -3255,6 +3258,7 @@ define void @spill_x10() {
; RV64IZCMP-SR-NEXT: cm.push {ra, s0-s11}, -112
; RV64IZCMP-SR-NEXT: .cfi_def_cfa_offset 112
; RV64IZCMP-SR-NEXT: .cfi_offset s10, -16
+; RV64IZCMP-SR-NEXT: .cfi_offset s11, -8
; RV64IZCMP-SR-NEXT: #APP
; RV64IZCMP-SR-NEXT: li s10, 0
; RV64IZCMP-SR-NEXT: #NO_APP
|
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.
LGTM.
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.
LGTM.
cm.push can't save X26 without also saving X27. This removes two other checks for this case.
This causes CFI to be emitted since X27 is now explicitly a callee saved register.
The affected tests use inline assembly to clobber X26 rather than the whole range of s0-s10.