Skip to content

Commit 365dde3

Browse files
authored
JIT/x86: Fix reported kill regs for varargs prologs (#113793)
* x86: Fix reported kill regs for varargs prologs
1 parent b378823 commit 365dde3

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/coreclr/jit/codegencommon.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5924,11 +5924,11 @@ void CodeGen::genFnProlog()
59245924

59255925
// MOV EAX, <VARARGS HANDLE>
59265926
assert(compiler->lvaVarargsHandleArg == compiler->info.compArgsCount - 1);
5927-
GetEmitter()->emitIns_R_S(ins_Load(TYP_I_IMPL), EA_PTRSIZE, REG_EAX, compiler->lvaVarargsHandleArg, 0);
5928-
regSet.verifyRegUsed(REG_EAX);
5927+
GetEmitter()->emitIns_R_S(ins_Load(TYP_I_IMPL), EA_PTRSIZE, REG_SCRATCH, compiler->lvaVarargsHandleArg, 0);
5928+
regSet.verifyRegUsed(REG_SCRATCH);
59295929

59305930
// MOV EAX, [EAX]
5931-
GetEmitter()->emitIns_R_AR(ins_Load(TYP_I_IMPL), EA_PTRSIZE, REG_EAX, REG_EAX, 0);
5931+
GetEmitter()->emitIns_R_AR(ins_Load(TYP_I_IMPL), EA_PTRSIZE, REG_SCRATCH, REG_SCRATCH, 0);
59325932

59335933
// EDX might actually be holding something here. So make sure to only use EAX for this code
59345934
// sequence.
@@ -5940,16 +5940,16 @@ void CodeGen::genFnProlog()
59405940
noway_assert(lastArg->lvFramePointerBased);
59415941

59425942
// LEA EAX, &<VARARGS HANDLE> + EAX
5943-
GetEmitter()->emitIns_R_ARR(INS_lea, EA_PTRSIZE, REG_EAX, genFramePointerReg(), REG_EAX, offset);
5943+
GetEmitter()->emitIns_R_ARR(INS_lea, EA_PTRSIZE, REG_SCRATCH, genFramePointerReg(), REG_SCRATCH, offset);
59445944

59455945
if (varDsc->lvIsInReg())
59465946
{
5947-
GetEmitter()->emitIns_Mov(INS_mov, EA_PTRSIZE, varDsc->GetRegNum(), REG_EAX, /* canSkip */ true);
5947+
GetEmitter()->emitIns_Mov(INS_mov, EA_PTRSIZE, varDsc->GetRegNum(), REG_SCRATCH, /* canSkip */ true);
59485948
regSet.verifyRegUsed(varDsc->GetRegNum());
59495949
}
59505950
else
59515951
{
5952-
GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_EAX, argsStartVar, 0);
5952+
GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SCRATCH, argsStartVar, 0);
59535953
}
59545954
}
59555955

src/coreclr/jit/lsrabuild.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,13 @@ void LinearScan::buildIntervals()
24482448
// do that in the prolog. We handle registers in the prolog and the
24492449
// stack args in the scratch BB that we have ensured exists. The
24502450
// handling clobbers REG_SCRATCH, so kill it here.
2451-
if ((block == compiler->fgFirstBB) && compiler->lvaHasAnySwiftStackParamToReassemble())
2451+
bool prologUsesScratchReg = compiler->lvaHasAnySwiftStackParamToReassemble();
2452+
#ifdef TARGET_X86
2453+
// On x86, CodeGen::genFnProlog does a varargs preprocessing that uses
2454+
// the scratch register.
2455+
prologUsesScratchReg |= compiler->info.compIsVarArgs;
2456+
#endif
2457+
if ((block == compiler->fgFirstBB) && prologUsesScratchReg)
24522458
{
24532459
addKillForRegs(genRegMask(REG_SCRATCH), currentLoc + 1);
24542460
currentLoc += 2;

0 commit comments

Comments
 (0)