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

For arm32, kill REG_PROFILER_RET_SCRATCH for LSRA but not for GC #40123

Merged
merged 1 commit into from
Jul 30, 2020

Conversation

AndyAyersMS
Copy link
Member

Reworking of #37969. Block LSRA from using R2 around the profiler leave
callback, but don't kill GC refs in R2, since late codegen will use
R2 to temporarily hold return values around the callback.

Fixes #37223.

Reworking of dotnet#37969. Block LSRA from using R2 around the profiler leave
callback, but don't kill GC refs in R2, since late codegen will use
R2 to temporarily hold return values around the callback.

Fixes dotnet#37223.
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 30, 2020
@AndyAyersMS
Copy link
Member Author

@CarolEidt PTAL
cc @dotnet/jit-contrib

@AndyAyersMS
Copy link
Member Author

Added in the gcstress-extra tests.

#if defined(TARGET_ARM)
// profiler scratch remains gc live
result = RBM_PROFILER_LEAVE_TRASH & ~RBM_PROFILER_RET_SCRATCH;
#else
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please explain why this is only needed for TARGET_ARM and not other architectures?

Copy link
Member Author

Choose a reason for hiding this comment

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

Arm is the only target that does this sort of return value sheltering in jitted code around the profiler leave hook.

No other architecture defines RBM_PROFILER_RET_SCRATCH.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks

@AndyAyersMS
Copy link
Member Author

Added libraries jitstress test.

@AndyAyersMS
Copy link
Member Author

Failure rates in gcstress-extra and libraries-jitstress seem similar to recent numbers. All are gc stress crashes or (in one case) an incorrect result. No recurrence of #37223.

@@ -491,6 +491,8 @@ int LinearScan::BuildNode(GenTree* tree)

case GT_RETURN:
srcCount = BuildReturn(tree);
killMask = getKillSetForReturn();
BuildDefsWithKills(tree, 0, RBM_NONE, killMask);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am OK with this fix as-is, but I think another option that might be slightly cleaner would be to replace the above 3 lines with:

            buildInternalIntRegisterDefForNode(tree, RBM_PROFILER_ENTER_TRASH);
            srcCount = BuildReturn(tree);
            buildInternalRegisterUses();

Then target.h and emit.cpp could, I believe, remain unchanged. This basically says to the register allocator: "I need an extra register and it must be r2", which will cause it to ensure that r2 is free at the return. However, I haven't tested this approach. Note that normally I wouldn't do this separately (outside of an existing BuildXXX method), but in this case BuildReturn() is shared across platforms and already complex.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I mentioned trying something like that over in the issue but wasn't sure how to pull it off.

Seems like the cleanest solution would be to inject these calls early and handle them like any other call.

Not sure how to proceed -- if you're ok with this fix then approve? Else I can try the above.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll approve; not sure it's worth iterating on.

Copy link
Contributor

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

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

Thanks for all your work on this!

@AndyAyersMS AndyAyersMS merged commit 32ddcd3 into dotnet:master Jul 30, 2020
@AndyAyersMS AndyAyersMS deleted the Fix37223 branch July 30, 2020 18:05
Jacksondr5 pushed a commit to Jacksondr5/runtime that referenced this pull request Aug 10, 2020
…net#40123)

Reworking of dotnet#37969. Block LSRA from using R2 around the profiler leave
callback, but don't kill GC refs in R2, since late codegen will use
R2 to temporarily hold return values around the callback.

Fixes dotnet#37223.

Co-authored-by: Carol Eidt <carol.eidt@microsoft.com>
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
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
Development

Successfully merging this pull request may close these issues.

Assertion failed 'nonVarPtrRegs == RBM_NONE'
5 participants