From 4e2228e370d36dc16eb1b9f1f0f94d70dd4c815c Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 25 Apr 2023 10:47:09 +0200 Subject: [PATCH] JIT: Allow spill-at-single-def for pure defs (#85251) Allow the spill-at-single-def logic to kick in for defs without subsequent uses before the spill. --- src/coreclr/jit/lsra.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index 64fb68cba56c7..1a35d2cc801d8 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -3423,15 +3423,11 @@ void LinearScan::spillInterval(Interval* interval, RefPosition* fromRefPosition } } - // Only handle the singledef intervals whose firstRefPosition is RefTypeDef and is not yet marked as spillAfter. - // The singledef intervals whose firstRefPositions are already marked as spillAfter, no need to mark them as - // singleDefSpill because they will always get spilled at firstRefPosition. - // This helps in spilling the singleDef at definition + // Only handle the singledef intervals whose firstRefPosition is RefTypeDef. // // Note: Only mark "singleDefSpill" for those intervals who ever get spilled. The intervals that are never spilled // will not be marked as "singleDefSpill" and hence won't get spilled at the first definition. - if (interval->isSingleDef && RefTypeIsDef(interval->firstRefPosition->refType) && - !interval->firstRefPosition->spillAfter) + if (interval->isSingleDef && RefTypeIsDef(interval->firstRefPosition->refType)) { // TODO-CQ: Check if it is beneficial to spill at def, meaning, if it is a hot block don't worry about // doing the spill. Another option is to track number of refpositions and a interval has more than X @@ -6280,6 +6276,11 @@ void LinearScan::resolveLocalRef(BasicBlock* block, GenTreeLclVar* treeNode, Ref varDsc->SetRegNum(REG_STK); interval->physReg = REG_NA; writeLocalReg(treeNode->AsLclVar(), interval->varNum, REG_NA); + + if (currentRefPosition->singleDefSpill) + { + varDsc->lvSpillAtSingleDef = true; + } } else // Not reload and Not pure-def that's spillAfter {