Skip to content

Fix xarch instruction size estimates - #129877

Closed
AndyAyersMS wants to merge 6 commits into
dotnet:mainfrom
AndyAyersMS:andy/fix-x64-instruction-size-estimates
Closed

AndyAyersMS wants to merge 6 commits into
dotnet:mainfrom
AndyAyersMS:andy/fix-x64-instruction-size-estimates

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Summary

  • Correct xarch instruction size estimates for VEX/EVEX prefix accounting, K-register moves, CRC32, 16-bit cmpxchg, direct-memory unary ops, IMUL forms, and AVX512 blend-mask operands.
  • Add a DEBUG-only emit-size check that is exact by default, with known x86 stack-memory formats excluded because their size depends on final stack depth.

Validation

  • build.cmd -subset clr.jit -c Checked
  • build.cmd -subset clr.jit -arch x86 -c Checked
  • Windows x64 Checked SuperPMI replay: clean
  • Windows x64 Checked SuperPMI asmdiffs/metricdiff
  • x86 crossgen2 System.Private.CoreLib repro command

Note

This PR description was generated by GitHub Copilot.

AndyAyersMS and others added 2 commits June 25, 2026 14:29
Correct xarch size accounting for VEX/K encodings and add an opt-in debug check.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the emit-size check exact by default and cover the remaining xarch estimator gaps.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 26, 2026 01:45
@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 Jun 26, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

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 the xarch emitter’s instruction-size estimation logic to more accurately account for encoding details (prefixes/opcode forms) and adds a DEBUG-only sanity check to assert when the emitted size differs from the estimated size.

Changes:

  • Add a new DEBUG-only JIT config switch to enable/disable an emit-size mismatch assertion.
  • Refine xarch size estimation in multiple paths (VEX/EVEX prefix accounting, certain opcode forms, K-reg moves, etc.).
  • Add a DEBUG-only emit-time verification in emitOutputInstr to compare estimated vs. actual encoded byte count (with skips for known intentionally-variable cases).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/jitconfigvalues.h Adds JitAssertOnEmitSizeMismatch debug config switch.
src/coreclr/jit/emitxarch.cpp Adjusts instruction size estimation for various xarch encodings and adds DEBUG-only emit-size mismatch checking.

Comment thread src/coreclr/jit/emitxarch.cpp Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 26, 2026 14:38
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/jit/jitconfigvalues.h
Comment thread src/coreclr/jit/emitxarch.cpp
Use the actual opcode prefix state when adjusting K-instruction size estimates so EVEX stress and VEX output stay consistent.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

Correct x86 K-instruction prefix accounting and memory-source IMUL estimates exposed by checked CI runs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 27, 2026 01:30
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/jitconfigvalues.h
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

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.

2 participants