Skip to content

JIT/x86: Fix reported kill regs for varargs prologs #113793

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

Merged
merged 2 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5924,11 +5924,11 @@ void CodeGen::genFnProlog()

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

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

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

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

if (varDsc->lvIsInReg())
{
GetEmitter()->emitIns_Mov(INS_mov, EA_PTRSIZE, varDsc->GetRegNum(), REG_EAX, /* canSkip */ true);
GetEmitter()->emitIns_Mov(INS_mov, EA_PTRSIZE, varDsc->GetRegNum(), REG_SCRATCH, /* canSkip */ true);
regSet.verifyRegUsed(varDsc->GetRegNum());
}
else
{
GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_EAX, argsStartVar, 0);
GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SCRATCH, argsStartVar, 0);
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/jit/lsrabuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2448,7 +2448,13 @@ void LinearScan::buildIntervals()
// do that in the prolog. We handle registers in the prolog and the
// stack args in the scratch BB that we have ensured exists. The
// handling clobbers REG_SCRATCH, so kill it here.
if ((block == compiler->fgFirstBB) && compiler->lvaHasAnySwiftStackParamToReassemble())
bool prologUsesScratchReg = compiler->lvaHasAnySwiftStackParamToReassemble();
#ifdef TARGET_X86
// On x86, CodeGen::genFnProlog does a varargs preprocessing that uses
// the scratch register.
prologUsesScratchReg |= compiler->info.compIsVarArgs;
#endif
if ((block == compiler->fgFirstBB) && prologUsesScratchReg)
{
addKillForRegs(genRegMask(REG_SCRATCH), currentLoc + 1);
currentLoc += 2;
Expand Down
Loading