Skip to content

Conversation

@kunalspathak
Copy link
Contributor

@kunalspathak kunalspathak commented Jan 15, 2021

In the recent #45135, we changed the way we go through the heuristics of selecting registers. If we decide to use a busy register, using FAR_NEXT_REF heuristics, we try to pick a register whose next interval reference is farthest. While calculating the location, we were not taking into consideration the next location of other half of the pair of registers, if the interval type is TYP_DOUBLE. Because of this, we were adding a register in "potential candidate to spill" that doesn't even have assigned interval. Further, in REG_NUM heuristics, we ended up picking this wrong register and hitting assert.

The fix was to take into account the next interval ref of other half of double register so we add only the legitimate candidates to be spilled.

Once that was fixed, there was also a problem I discovered in PREV_REG_OPT heuristics. In this, out of remaining candidates, we check if they have valid assigned interval and if not, we assert because they can't be spill candidates. However, if the current interval is TYP_DOUBLE, we should have also check if the other register of the double register pair has valid interval and if yes, just check the heuristics against its refPosition.

Fixes: #46086

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 15, 2021
@kunalspathak
Copy link
Contributor Author

arm failures are related to #46085 and are fixed in #46939 .

@kunalspathak kunalspathak marked this pull request as ready for review January 16, 2021 02:23
@kunalspathak
Copy link
Contributor Author

@dotnet/jit-contrib

@JulieLeeMSFT JulieLeeMSFT added this to the 6.0.0 milestone Jan 16, 2021
// Return Value:
// A RegRecord which forms same double register with regRec
//
regNumber LinearScan::findAnotherHalfRegRec(regNumber regNum)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be renamed findDoubleRegPair or similar: it shouldn't imply that it's finding a RegRecord.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I have changed it to findAnotherHalfRegNum()

Interval* assignedInterval = physRegs[prevRegOptCandidateRegNum].assignedInterval;
// The assigned should be non-null, and should have a recentRefPosition, however since
// this is a heuristic, we don't want a fatal error, so we just assert (not noway_assert).
bool foundPrevRegOptReg = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like foundPrevRegOptReg will always be true; how can it be set to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I went back and forth and seems I missed the case when it should be false. I have updated the code.

For reference, I was trying to add back the missing code that was present pre #45135,. You can see it at https://github.com/dotnet/runtime/pull/45135/files#diff-a985c84f41c0c758b9a2f849758cdfd6eac4acf6cfc2151a28d206d70e0358e0L3816-L3824 (need to load diffs for lsra.cpp changes).

Copy link
Contributor

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (if the tests pass)

// None
//
// Return Value:
// A register number which forms same double register with regRec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: regRec is wrong here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@kunalspathak kunalspathak merged commit 247e0ea into dotnet:master Jan 20, 2021
kunalspathak added a commit to kunalspathak/runtime that referenced this pull request Feb 2, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Feb 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

3 participants