Skip to content

Commit

Permalink
[RISC-V] Fix initReg usage in genPushCalleeSavedRegisters (#99353)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirntar authored Mar 7, 2024
1 parent ce34357 commit 8330db9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/coreclr/jit/codegenriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7782,6 +7782,11 @@ void CodeGen::genPushCalleeSavedRegisters(regNumber initReg, bool* pInitRegZeroe
{
assert(compiler->compGeneratingProlog);

// The 'initReg' could have been calculated as one of the callee-saved registers (let's say T0, T1 and T2 are in
// use, so the next possible register is S1, which should be callee-save register). This is fine, as long as we
// save callee-saved registers before using 'initReg' for the first time. Instead, we can use REG_SCRATCH
// beforehand. We don't care if REG_SCRATCH will be overwritten, so we'll skip 'RegZeroed check'.
//
// Unlike on x86/x64, we can also push float registers to stack
regMaskTP rsPushRegs = regSet.rsGetModifiedRegsMask() & RBM_CALLEE_SAVED;

Expand Down Expand Up @@ -7894,11 +7899,11 @@ void CodeGen::genPushCalleeSavedRegisters(regNumber initReg, bool* pInitRegZeroe
calleeSaveSPDelta = AlignUp((UINT)offset, STACK_ALIGN);
offset = calleeSaveSPDelta - offset;

genStackPointerAdjustment(-calleeSaveSPDelta, initReg, pInitRegZeroed, /* reportUnwindData */ true);
genStackPointerAdjustment(-calleeSaveSPDelta, REG_SCRATCH, nullptr, /* reportUnwindData */ true);
}
else
{
genStackPointerAdjustment(-totalFrameSize, initReg, pInitRegZeroed, /* reportUnwindData */ true);
genStackPointerAdjustment(-totalFrameSize, REG_SCRATCH, nullptr, /* reportUnwindData */ true);
}
}

Expand All @@ -7907,6 +7912,8 @@ void CodeGen::genPushCalleeSavedRegisters(regNumber initReg, bool* pInitRegZeroe
genSaveCalleeSavedRegistersHelp(rsPushRegs, offset, 0);
offset += (int)(genCountBits(rsPushRegs) << 3); // each reg has 8 bytes

// From now on, we can safely use initReg.

emit->emitIns_R_R_I(INS_sd, EA_PTRSIZE, REG_RA, REG_SPBASE, offset);
compiler->unwindSaveReg(REG_RA, offset);

Expand Down

0 comments on commit 8330db9

Please sign in to comment.