Uh oh!
There was an error while loading. Please reload this page.
JIT: Intrinsify Task/ValueTask factory methods - #129810
Conversation
Intrinsify and recognize the following methods when used directly in runtime async variants: - `Task.FromResult` - `Task.CompletedTask` - `ValueTask.FromResult` - `ValueTask.CompletedTask` - `new ValueTask()` - `ValueTask`-typed `default` - `new ValueTask<T>(T value)`
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR extends the CoreCLR JIT’s “runtime async” optimization pipeline by marking common Task/ValueTask factory helpers as intrinsics and teaching the importer to fold/avoid AsyncHelpers.TransparentAwaitWithResult in more cases, reducing call/alloc overhead in optimized async-return paths.
Changes:
- Mark
Task.CompletedTask,Task.FromResult,ValueTask.CompletedTask,ValueTask.FromResult, andValueTask<TResult>(TResult)with[Intrinsic]to enable JIT recognition. - Add new JIT
NamedIntrinsicIDs plus importer expansion logic for async-callconvFromResult/CompletedTask, and add a newimpFoldAwaitedTopOfStackfast-path for certain ValueTask return patterns. - Improve debug local naming by labeling
ASYNC_CONTINUATION_ILNUMlocals asAsyncCont.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs | Adds [Intrinsic] to ValueTask.CompletedTask, ValueTask.FromResult, and ValueTask<TResult>(TResult) ctor to enable JIT recognition. |
| src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs | Adds [Intrinsic] to Task.CompletedTask getter and Task.FromResult to enable async-callconv intrinsic expansion. |
| src/coreclr/jit/namedintrinsiclist.h | Introduces new NamedIntrinsic entries for Task/ValueTask factory methods used by the importer. |
| src/coreclr/jit/importercalls.cpp | Implements async-callconv intrinsic expansion/folding for FromResult/CompletedTask, and extends intrinsic lookup for Task/ValueTask methods. |
| src/coreclr/jit/importer.cpp | Refactors return/await wrapping logic and adds impFoldAwaitedTopOfStack to avoid unnecessary TransparentAwaitWithResult calls. |
| src/coreclr/jit/gentree.cpp | Improves local name printing by labeling async continuation locals as AsyncCont. |
| src/coreclr/jit/compiler.h | Adds the impFoldAwaitedTopOfStack declaration. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jakobbotsch
commented
Jun 25, 2026
cc @dotnet/jit-contrib PTAL @EgorBo |
Uh oh!
There was an error while loading. Please reload this page.
Intrinsify and recognize the following methods when used directly in runtime async context: - `Task.FromResult` - `Task.CompletedTask` - `ValueTask.FromResult` - `ValueTask.CompletedTask` - `new ValueTask()` - `ValueTask`-typed `default` - `new ValueTask<T>(T value)`
Intrinsify and recognize the following methods when used directly in runtime async context:
Task.FromResultTask.CompletedTaskValueTask.FromResultValueTask.CompletedTasknew ValueTask()ValueTask-typeddefaultnew ValueTask<T>(T value)Example
Before:
After: