Skip to content
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

Consider reloadWeight while evaluating spill cost #53853

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Changes from 2 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
31 changes: 27 additions & 4 deletions src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11258,13 +11258,36 @@ void LinearScan::RegisterSelection::try_SPILL_COST()
continue;
}

float currentSpillWeight = linearScan->spillCost[spillCandidateRegNum];
#ifdef TARGET_ARM
if (currentInterval->registerType == TYP_DOUBLE)
float currentSpillWeight = 0;
RefPosition* recentRefPosition = spillCandidateRegRecord->assignedInterval != nullptr
? spillCandidateRegRecord->assignedInterval->recentRefPosition
: nullptr;
if ((recentRefPosition != nullptr) && (recentRefPosition->RegOptional()) &&
!(currentInterval->isLocalVar && recentRefPosition->IsActualRef()))
{
currentSpillWeight = max(currentSpillWeight, linearScan->spillCost[REG_NEXT(spillCandidateRegNum)]);
// 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.
// For such cases, consider the spill cost of next refposition.
// See notes in "spillInterval()".
RefPosition* reloadRefPosition = spillCandidateRegRecord->assignedInterval->getNextRefPosition();
if (reloadRefPosition != nullptr)
{
currentSpillWeight = linearScan->getWeight(reloadRefPosition);
}
}

// Only consider spillCost if we were not able to calculate weight of reloadRefPosition.
if (currentSpillWeight == 0)
{
currentSpillWeight = linearScan->spillCost[spillCandidateRegNum];
#ifdef TARGET_ARM
if (currentInterval->registerType == TYP_DOUBLE)
{
currentSpillWeight = max(currentSpillWeight, linearScan->spillCost[REG_NEXT(spillCandidateRegNum)]);
}
#endif
}

if (currentSpillWeight < bestSpillWeight)
{
bestSpillWeight = currentSpillWeight;
Expand Down