Skip to content

Commit 736ffdc

Browse files
authored
[RISCV] Add X27 to SavedRegs when X26 is in SavedRegs for cm.push/pop (#92067)
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.
1 parent ac0d415 commit 736ffdc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ getPushPopEncodingAndNum(const Register MaxReg) {
265265
default:
266266
llvm_unreachable("Unexpected Reg for Push/Pop Inst");
267267
case RISCV::X27: /*s11*/
268-
case RISCV::X26: /*s10*/
269268
return std::make_pair(llvm::RISCVZC::RLISTENCODE::RA_S0_S11, 13);
270269
case RISCV::X25: /*s9*/
271270
return std::make_pair(llvm::RISCVZC::RLISTENCODE::RA_S0_S9, 11);
@@ -302,9 +301,7 @@ static Register getMaxPushPopReg(const MachineFunction &MF,
302301
}) != std::end(FixedCSRFIMap))
303302
MaxPushPopReg = std::max(MaxPushPopReg.id(), CS.getReg().id());
304303
}
305-
// if rlist is {rs, s0-s10}, then s11 will also be included
306-
if (MaxPushPopReg == RISCV::X26)
307-
MaxPushPopReg = RISCV::X27;
304+
assert(MaxPushPopReg != RISCV::X26 && "x26 requires x27 to also be pushed");
308305
return MaxPushPopReg;
309306
}
310307

@@ -1047,6 +1044,11 @@ void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
10471044
// Mark BP as used if function has dedicated base pointer.
10481045
if (hasBP(MF))
10491046
SavedRegs.set(RISCVABI::getBPReg());
1047+
1048+
// When using cm.push/pop we must save X27 if we save X26.
1049+
auto *RVFI = MF.getInfo<RISCVMachineFunctionInfo>();
1050+
if (RVFI->isPushable(MF) && SavedRegs.test(RISCV::X26))
1051+
SavedRegs.set(RISCV::X27);
10501052
}
10511053

10521054
std::pair<int64_t, Align>

llvm/test/CodeGen/RISCV/push-pop-popret.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,6 +3225,7 @@ define void @spill_x10() {
32253225
; RV32IZCMP-NEXT: cm.push {ra, s0-s11}, -64
32263226
; RV32IZCMP-NEXT: .cfi_def_cfa_offset 64
32273227
; RV32IZCMP-NEXT: .cfi_offset s10, -8
3228+
; RV32IZCMP-NEXT: .cfi_offset s11, -4
32283229
; RV32IZCMP-NEXT: #APP
32293230
; RV32IZCMP-NEXT: li s10, 0
32303231
; RV32IZCMP-NEXT: #NO_APP
@@ -3235,6 +3236,7 @@ define void @spill_x10() {
32353236
; RV64IZCMP-NEXT: cm.push {ra, s0-s11}, -112
32363237
; RV64IZCMP-NEXT: .cfi_def_cfa_offset 112
32373238
; RV64IZCMP-NEXT: .cfi_offset s10, -16
3239+
; RV64IZCMP-NEXT: .cfi_offset s11, -8
32383240
; RV64IZCMP-NEXT: #APP
32393241
; RV64IZCMP-NEXT: li s10, 0
32403242
; RV64IZCMP-NEXT: #NO_APP
@@ -3245,6 +3247,7 @@ define void @spill_x10() {
32453247
; RV32IZCMP-SR-NEXT: cm.push {ra, s0-s11}, -64
32463248
; RV32IZCMP-SR-NEXT: .cfi_def_cfa_offset 64
32473249
; RV32IZCMP-SR-NEXT: .cfi_offset s10, -8
3250+
; RV32IZCMP-SR-NEXT: .cfi_offset s11, -4
32483251
; RV32IZCMP-SR-NEXT: #APP
32493252
; RV32IZCMP-SR-NEXT: li s10, 0
32503253
; RV32IZCMP-SR-NEXT: #NO_APP
@@ -3255,6 +3258,7 @@ define void @spill_x10() {
32553258
; RV64IZCMP-SR-NEXT: cm.push {ra, s0-s11}, -112
32563259
; RV64IZCMP-SR-NEXT: .cfi_def_cfa_offset 112
32573260
; RV64IZCMP-SR-NEXT: .cfi_offset s10, -16
3261+
; RV64IZCMP-SR-NEXT: .cfi_offset s11, -8
32583262
; RV64IZCMP-SR-NEXT: #APP
32593263
; RV64IZCMP-SR-NEXT: li s10, 0
32603264
; RV64IZCMP-SR-NEXT: #NO_APP

0 commit comments

Comments
 (0)