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 {