diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index 31127e89afd75..2fb95562f7abe 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -10955,6 +10955,22 @@ void LinearScan::verifyFinalAllocation() } if (regNum == REG_NA) { + // If this interval is still assigned to a register + if (interval->physReg != REG_NA) + { + // then unassign it if no new register was assigned to the RefTypeDef + if (RefTypeIsDef(currentRefPosition->refType)) + { + assert(interval->assignedReg != nullptr); + if (interval->assignedReg->assignedInterval == interval) + { + interval->assignedReg->assignedInterval = nullptr; + } + interval->physReg = REG_NA; + interval->assignedReg = nullptr; + } + } + dumpLsraAllocationEvent(LSRA_EVENT_NO_REG_ALLOCATED, interval); } else if (RefTypeIsDef(currentRefPosition->refType)) @@ -11093,6 +11109,16 @@ void LinearScan::verifyFinalAllocation() { assert(!currentRefPosition->spillAfter || currentRefPosition->IsActualRef()); + if (RefTypeIsDef(currentRefPosition->refType)) + { + // If an interval got assigned to a different register (while the different + // register got spilled), then clear the assigned interval of current register. + if (interval->physReg != REG_NA && interval->physReg != regNum) + { + interval->assignedReg->assignedInterval = nullptr; + } + } + interval->physReg = REG_NA; interval->assignedReg = nullptr; diff --git a/src/coreclr/jit/lsra.h b/src/coreclr/jit/lsra.h index 345cbb451f788..f381e223ae781 100644 --- a/src/coreclr/jit/lsra.h +++ b/src/coreclr/jit/lsra.h @@ -510,9 +510,6 @@ class RegRecord : public Referenceable void tinyDump(); #endif // DEBUG - // RefPosition * getNextRefPosition(); - // LsraLocation getNextRefLocation(); - // DATA // interval to which this register is currently allocated.