diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index 86d037e12ac5f6..c1f4f9dd13c1f5 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -11264,8 +11264,8 @@ void LinearScan::RegisterSelection::try_SPILL_COST() RefPosition* recentRefPosition = spillCandidateRegRecord->assignedInterval != nullptr ? spillCandidateRegRecord->assignedInterval->recentRefPosition : nullptr; - if ((recentRefPosition != nullptr) && (recentRefPosition->RegOptional()) && - !(currentInterval->isLocalVar && recentRefPosition->IsActualRef())) + if ((recentRefPosition != nullptr) && (recentRefPosition->RegOptional() && + !(spillCandidateRegRecord->assignedInterval->isLocalVar && recentRefPosition->IsActualRef()))) { // We do not "spillAfter" if previous (recent) refPosition was regOptional or if it // is not an actual ref. In those cases, we will reload in future (next) refPosition.