JIT: Fold small-typed load into sign/zero-extending cast on xarch#130201
Closed
AndyAyersMS wants to merge 1 commit into
Closed
JIT: Fold small-typed load into sign/zero-extending cast on xarch#130201AndyAyersMS wants to merge 1 commit into
AndyAyersMS wants to merge 1 commit into
Conversation
Mark small-typed loads as containable in ContainCheckCast to avoid a double extension. The cast's extension is all we need. Fixes dotnet#69472. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates xarch JIT lowering to allow containing small-typed loads under sign/zero-extending casts even when the load’s original signedness doesn’t match the cast’s extension direction, enabling emission of a single extending load instruction instead of a load + separate extend. It also adds a disasm-checked JIT test that exercises the improved folding for byte/char/ushort sources.
Changes:
- Relax
Lowering::ContainCheckCast(xarch) so integral casts can always attempt source containment under Tier0 opts, allowing folding into a singlemovsx/movzxload. - Add a new disasm-check test (
SignExtLoad) covering byte/ushort/char indexing patterns that previously produced double-extension sequences. - Add a dedicated test project that disables tiering/minopts to stabilize codegen for disasm checks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/jit/lowerxarch.cpp | Makes small-typed load containment under casts more permissive to avoid redundant extension instructions on xarch. |
| src/tests/JIT/opt/Casts/SignExtLoad.cs | New disasm-check regression test validating movsx folding (and absence of movzx) for key patterns. |
| src/tests/JIT/opt/Casts/SignExtLoad.csproj | Test harness configuration for process isolation + env vars + disasm checking. |
Comment on lines
+7774
to
+7777
| // Small-typed casts can always be re-expressed as memory loads at the cast's own | ||
| // extension direction; the load has a single use (containment implies it), so | ||
| // the load's own extension mode is irrelevant. This folds patterns like | ||
| // "movzx r, byte ptr [mem]; movsx r, r8" into a single "movsx r, byte ptr [mem]". |
This was referenced Jul 4, 2026
Open
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.
Mark small-typed loads as containable in ContainCheckCast to avoid a double extension. The cast's extension is all we need.
Fixes #69472.