Fix xarch instruction size estimates#129877
Draft
AndyAyersMS wants to merge 5 commits into
Draft
Conversation
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>
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
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
emitOutputInstrto 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. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86 |
|
Azure Pipelines successfully started running 2 pipeline(s). |
This was referenced Jun 26, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86 |
|
Azure Pipelines successfully started running 2 pipeline(s). |
| // RyuJIT where possible | ||
| CONFIG_INTEGER(JitAssertOnMaxRAPasses, "JitAssertOnMaxRAPasses", 0) | ||
| CONFIG_INTEGER(JitBreakEmitOutputInstr, "JitBreakEmitOutputInstr", -1) | ||
| // Assert if the xarch encoder emits a different number of bytes than its estimator predicted; set to 0 to disable. |
Comment on lines
+20223
to
+20233
| // Labels and align pseudo-instructions can intentionally shrink after initial size estimation. | ||
| const IS_INFO insFmtInfo = emitGetSchedInfo(insFmt); | ||
| #if !FEATURE_FIXED_OUT_ARGS | ||
| const bool skipStackSizeCheck = ((insFmtInfo & (IS_SF_RD | IS_SF_RW | IS_SF_WR)) != 0); | ||
| #else | ||
| const bool skipStackSizeCheck = false; | ||
| #endif | ||
| const bool skipSizeCheck = (id->idIns() == INS_align) || (insFmt == IF_LABEL) || (insFmt == IF_RWR_LABEL) || | ||
| (insFmt == IF_SWR_LABEL) || skipStackSizeCheck; | ||
| const UNATIVE_OFFSET actualCodeSize = static_cast<UNATIVE_OFFSET>(dst - *dp); | ||
| if (!skipSizeCheck && (id->idCodeSize() != actualCodeSize)) |
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>
Member
Author
|
/azp run runtime-coreclr jitstress-isas-avx512, runtime-coreclr jitstress-isas-x86 |
|
Azure Pipelines successfully started running 2 pipeline(s). |
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.
Summary
Validation
build.cmd -subset clr.jit -c Checkedbuild.cmd -subset clr.jit -arch x86 -c CheckedNote
This PR description was generated by GitHub Copilot.