-
Notifications
You must be signed in to change notification settings - Fork 5.5k
JIT: don't stress-tailcall named intrinsics (#122479) #128336
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
Open
AndyAyersMS
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
AndyAyersMS:fix-122479-tailcall-stress-intrinsic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−32
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/tests/JIT/Regression/JitBlue/Runtime_122479/Runtime_122479.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // Under STRESS_TAILCALL the JIT importer would promote a "call+ret" pattern | ||
| // to an explicit (or implicit) tailcall before discovering that the callee | ||
| // is a named intrinsic (e.g. GC.KeepAlive, which is imported as a | ||
| // GT_KEEPALIVE node, not a CALL). When combined with a [SuppressGCTransition] | ||
| // P/Invoke earlier in the same block, the resulting BBJ_RETURN ended with a | ||
| // non-CALL/non-RETURN statement and tripped an assert in fgInsertStmtNearEnd | ||
| // during "Insert GC Polls". | ||
| // | ||
| // Run under any jitstress / jitstress_tiered leg to validate. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
| using System.Threading; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_122479 | ||
| { | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static void ReproPattern() | ||
| { | ||
| // Thread.Sleep -> Thread.ClearWaitSleepJoinState which has the | ||
| // exact "SuppressGCTransition QCall; GC.KeepAlive(this); ret" shape | ||
| // that originally triggered the assert. | ||
| Thread.Sleep(0); | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void TestEntryPoint() | ||
| { | ||
| for (int i = 0; i < 100; i++) | ||
| { | ||
| ReproPattern(); | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression/JitBlue/Runtime_122479/Runtime_122479.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also matches hardware and JIT intrinsics, correct?
I know its not exactly related since this is covering stress mode, but we have some other "pessimizations" around intrinsics and tail calls such as https://github.com/dotnet/runtime/blob/main/src/coreclr/jit/importercalls.cpp#L10212-L10225 where we may refuse to import it as non-CALL IR.
I wonder if for cases that are known to expand to trivial IR, like
KEEPALIVEor most HWIntrinsics, if its worth just blanket avoiding tail calls altogether or if we need to centrally handletail. call intrinsicto ensure we never try to expand them (if its required to respect the tail call)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall we have some vague notion of centralizing the tail call logic somewhere, though I can't remember now if it is to move it all earlier (maybe as a post-importer phase) or move it all later, into morph. Either way we'd have resolved intrinsics into closer-to-final IR before making decisions about tail calls.