Skip to content

JIT: Fold small-typed load into sign/zero-extending cast on xarch#130201

Closed
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:andyayersms/fix-69472
Closed

JIT: Fold small-typed load into sign/zero-extending cast on xarch#130201
AndyAyersMS wants to merge 1 commit into
dotnet:mainfrom
AndyAyersMS:andyayersms/fix-69472

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Mark small-typed loads as containable in ContainCheckCast to avoid a double extension. The cast's extension is all we need.

Fixes #69472.

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>
Copilot AI review requested due to automatic review settings July 4, 2026 15:11
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 single movsx/movzx load.
  • 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]".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT perf: ldind.u1 followed by conv.i1 results in suboptimal codegen

2 participants