JIT: Enable implicit tailcalls for tail-awaits#129255
Merged
jakobbotsch merged 7 commits intoJul 1, 2026
Merged
Conversation
We disabled tailcalls from async methods when we added the context restore, but now that have and use tail-awaits we can reenable implicit tailcalls for those cases. That will also benefit async versions once that PR merges.
Contributor
There was a problem hiding this comment.
Pull request overview
This change adjusts JIT tailcall eligibility for async methods: instead of blanket-disabling tailcalls from async methods, it allows implicit tailcalls only when the call is a tail await, while continuing to disqualify all other tailcall candidates from async methods.
Changes:
- Removed the early “caller is async method” tailcall disqualification.
- Added a late-stage tailcall eligibility check that permits tailcalls from async methods only for calls marked as async +
IsTailAwait.
This was referenced Jun 26, 2026
jakobbotsch
marked this pull request as ready for review
June 29, 2026 17:49
Member
Author
EgorBo
approved these changes
Jun 30, 2026
eiriktsarpalis
pushed a commit
that referenced
this pull request
Jul 15, 2026
We disabled tailcalls from async methods when we added the context
restore logic, but now that have and use tail-awaits we can reenable
implicit tailcalls for those cases.
Example:
```csharp
private static Task Foo(bool b)
{
return b ? Bar() : Baz();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static async Task Bar()
{
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static async Task Baz()
{
}
```
```diff
G_M15357_IG01:
- sub rsp, 40
- ;; size=4 bbWeight=1 PerfScore 0.25
+ ;; size=0 bbWeight=1 PerfScore 0.00
G_M15357_IG02:
test dl, dl
- je SHORT G_M15357_IG04
+ je SHORT G_M15357_IG05
;; size=4 bbWeight=1 PerfScore 1.25
G_M15357_IG03:
xor rcx, rcx
- call [Program:Bar()]
- test rcx, rcx
- jne SHORT G_M15357_IG09
- jmp SHORT G_M15357_IG05
- ;; size=15 bbWeight=0.50 PerfScore 3.25
+ ;; size=2 bbWeight=0.50 PerfScore 0.12
G_M15357_IG04:
- xor rcx, rcx
- call [Program:Baz()]
- test rcx, rcx
- jne SHORT G_M15357_IG08
- ;; size=13 bbWeight=0.50 PerfScore 2.25
+ tail.jmp [Program:Bar()]
+ ;; size=6 bbWeight=0.50 PerfScore 1.00
G_M15357_IG05:
- xor ecx, ecx
- ;; size=2 bbWeight=1 PerfScore 0.25
+ xor rcx, rcx
+ ;; size=2 bbWeight=0.50 PerfScore 0.12
G_M15357_IG06:
- add rsp, 40
- ret
- ;; size=5 bbWeight=1 PerfScore 1.25
-G_M15357_IG07:
- add rsp, 40
- ret
- ;; size=5 bbWeight=0 PerfScore 0.00
-G_M15357_IG08:
- jmp SHORT G_M15357_IG07
- ;; size=2 bbWeight=0 PerfScore 0.00
-G_M15357_IG09:
- jmp SHORT G_M15357_IG07
- ;; size=2 bbWeight=0 PerfScore 0.00
+ tail.jmp [Program:Baz()]
+ ;; size=6 bbWeight=0.50 PerfScore 1.00
-; Total bytes of code 52, prolog size 4, PerfScore 8.50, instruction count 19, allocated bytes for code 52 (MethodHash=2415c402) for method Program:Foo(bool) (FullOpts)
+; Total bytes of code 20, prolog size 0, PerfScore 3.50, instruction count 6, allocated bytes for code 20 (MethodHash=2415c402) for method Program:Foo(bool) (FullOpts)
; ============================================================
```
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We disabled tailcalls from async methods when we added the context restore logic, but now that have and use tail-awaits we can reenable implicit tailcalls for those cases.
Example: