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

Tiered compilation fails to elide value type null check #1713

Closed
sharwell opened this issue Jan 14, 2020 · 11 comments · Fixed by #1741
Closed

Tiered compilation fails to elide value type null check #1713

sharwell opened this issue Jan 14, 2020 · 11 comments · Fixed by #1741
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@sharwell
Copy link
Member

AsyncMethodBuilderCore is implemented with the assumption that value type state machines will not be boxed for a runtime comparison with null:

if (stateMachine == null) // TStateMachines are generally non-nullable value types, so this check will be elided
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stateMachine);
}

This assumption does not hold for Tier 0 compilation. For a release build of Roslyn, execution of analyzers on Roslyn.sln produces 20% (70GB) of its total allocations boxing state machines for this null check.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jan 14, 2020
@AndyAyersMS
Copy link
Member

AndyAyersMS commented Jan 14, 2020

Thanks -- is this with latest builds only or do you see it in 3.x too?

The fix for unexpected boxing at Tier0 in the 3.0 cycle was:

I would have expected the IL pattern based opts to kick in here.

@sharwell
Copy link
Member Author

I was running the tool using the executable it generated during the build. Is there a way to see which version of dotnet it executes under the covers?

@sharwell
Copy link
Member Author

sharwell commented Jan 14, 2020

I re-ran this with the dotnet tool to get a specific version where the problematic behavior is observed:

PS C:\dev\roslyn> dotnet --version
5.0.100-alpha1-015536

@AndyAyersMS
Copy link
Member

Yes, the boxing remains in Tier0, but gets optimized away in Tier1.

The unboxing opt at Tier0 gets blocked by the fact that we're boxing a byref arg and the byref might be null. At Tier1 we're able to handle this by leaving a residual null check behind.

Let me see how hard it is to extend the Tier0 version to cover this case.

@AndyAyersMS
Copy link
Member

I'm going to label this as codegen.

We've seen Tier0 code do a lot of allocation in a short time window -- but would be good to verify that the tiering logic is working as expected here. So @kouvel it is probably interesting to look at when/if tiering kicks in on this case.

@AndyAyersMS AndyAyersMS added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed untriaged New issue has not been triaged by the area owner labels Jan 14, 2020
@AndyAyersMS AndyAyersMS added this to the 5.0 milestone Jan 14, 2020
AndyAyersMS added a commit to AndyAyersMS/jitutils that referenced this issue Jan 14, 2020
Update PMI to jit the method from dotnet/runtime#1713.
@sharwell
Copy link
Member Author

💭 One option would be extracting this type of argument null check to a method where aggressive optimizations can be applied. This would allow the code to use the fast null check in Tier 0 without impacting the normal Tier0→Tier1 path.

@AndyAyersMS
Copy link
Member

This looks like it can be fairly easily fixed in the jit -- I'm evaluating a prospective fix now.

AndyAyersMS added a commit to dotnet/jitutils that referenced this issue Jan 14, 2020
AndyAyersMS added a commit to AndyAyersMS/runtime that referenced this issue Jan 15, 2020
Handle simple side effects in the `box; br` pattern based optimization.

Fixes dotnet#1713.
sharwell added a commit to sharwell/roslyn that referenced this issue Jan 15, 2020
AndyAyersMS added a commit that referenced this issue Jan 15, 2020
Handle simple side effects in the `box; br` pattern based optimization.

Fixes #1713.
@AndyAyersMS
Copy link
Member

@sharwell is this something you think we should try and fix in 3.1? I don't know if it would make the cut, but we could propose it and see.

@sharwell
Copy link
Member Author

sharwell commented Mar 5, 2020

@AndyAyersMS it really depends on whether users are expected to use tiered compilation. The numbers at the top are accurate for our scenario, but the issue is resolved by disabling the feature.

@AndyAyersMS
Copy link
Member

It's on by default, so yes we expect most users to use it. If I get this fixed in 3.x will you re-enable?

We do not want users to see regressions when moving from 2.x to 3.x, or decide the feature as a whole can't be trusted and decide to just turn it off forever.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 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 a pull request may close this issue.

4 participants