Repository navigation
JIT: Improve cast helper fallbacks - #133324
Merged
Merged
Conversation
Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 5 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
It changes JIT cast expansion behavior/codegen in core paths and should be validated by a human reviewer with appropriate correctness/perf testing coverage.
Pull request overview
This PR refines CoreCLR JIT late cast-helper expansion so the generated fast/slow paths better match helper semantics (notably when the cast target is provably exact), enabling tighter fallbacks and use of the specialized cast helper when its preconditions are already guarded.
Changes:
- Treat
CHKCASTCLASS/CHKCASTARRAYto an exact target type as having an always-throwing fallback on type-check failure (after the null check), allowing the fallback block to be marked no-return. - Prefer
TypeCheckFailedAction::CallHelper_SpecializedforCHKCASTCLASSin cases where the expansion already guards null and exact-type equality. - Minor comment cleanup/clarification around exact-type handling and fallback behavior.
File summaries
| File | Description |
|---|---|
| src/coreclr/jit/helperexpansion.cpp | Adjusts candidate selection and fallback strategy for late cast-helper expansion, including specialized-helper selection and always-throw classification for exact targets. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
Member
Author
|
PTAL @jakobbotsch @dotnet/jit-contrib small change to improve fallbacks for cast expansion |
jakobbotsch
approved these changes
Sep 9, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Optimize fallbacks for cast expansions, e.g. Fallback for
(string[])objalways throws.G_M14817_IG01: sub rsp, 40 G_M14817_IG02: mov rax, rcx test rax, rax - je SHORT G_M14817_IG05 + je SHORT G_M14817_IG04 G_M14817_IG03: mov r8, 0xD1FFAB1E ; System.String[] cmp qword ptr [rax], r8 - je SHORT G_M14817_IG05 + jne SHORT G_M14817_IG05 G_M14817_IG04: + add rsp, 40 + ret +G_M14817_IG05: mov rdx, rcx mov rcx, r8 call [CORINFO_HELP_CHKCASTARRAY] -G_M14817_IG05: - nop -G_M14817_IG06: - add rsp, 40 - ret + int3G_M25441_IG05: cmp qword ptr [rax], rcx je SHORT G_M25441_IG07 G_M25441_IG06: mov rdx, rbx - call [CORINFO_HELP_CHKCASTCLASS] + call [CORINFO_HELP_CHKCASTCLASS_SPECIAL] G_M25441_IG07: nopG_M5904_IG05: mov rdx, rcx mov rcx, r8 - call CORINFO_HELP_CHKCASTCLASS + call CORINFO_HELP_CHKCASTCLASS_SPECIAL jmp SHORT G_M5904_IG04