Repository navigation
Fix x64 instruction size estimates - #137880
AndyAyersMS merged 10 commits into
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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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>
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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@tannergooding have been sitting on this for a while but think we should take it. Code changes don't look too bad. fyi @dotnet/jit-contrib |
There was a problem hiding this comment.
🟡 Changes recommended
Incorrect APX instruction-size estimates for 64-bit IMUL and 16-bit cmpxchg cause valid instructions to fail size checks.
2 open issues
What changed in this PR
This PR tightens instruction-size accounting in the CoreCLR xarch JIT emitter, aiming for exact estimates rather than tolerating overestimates.
Changes:
- Adjusts opcode, prefix, and masked-blend size calculations.
- Strengthens validation of compressed stack displacements.
- Adds a default-enabled debug assertion for estimated versus emitted instruction sizes, with exceptions for intentionally variable-size instructions.
| File | Description |
|---|---|
src/coreclr/jit/jitconfigvalues.h |
Adds the configuration switch for instruction-size mismatch assertions. |
src/coreclr/jit/emitxarch.cpp |
Updates size estimates and adds stricter emission checks. |
Review effort: Balanced
|
Changes otherwise LGTM. Looks like copilot found the same issues I did. |
…ction-size-estimates
|
Local runs with various ISA stress modes found a few more things. I'll address them all with one upcoming commit. From review:
New, found by the APX stress runs:
|
Address review feedback and issues found by APX SuperPMI stress: - Count the 0x66 prefix for 16-bit cmpxchg consistently, and share one rule (NeedsLegacyOperandSizePrefix) between the estimator and the emitters. This also fixes 16-bit shld/shrd and memory xadd, which previously omitted the 0x66 prefix. - Fix extended-register 3-op imul under REX2/EVEX, where the built-in REX byte was double-counted. - Only add the EVEX MI-form byte when the accumulator form was assumed. - Don't count a REX2 prefix for IF_METHPTR calls; it is never emitted. - Subtract the empty prefix slot for no-prefix 0F38/0F3A SIMD opcodes (AVX10v1 FP16, AVX-VNNI-INT). - LSRA: restrict contained int<->float BITCAST stores to low GPRs, as for standalone BITCAST; VEX vmovd cannot encode EGPRs. - Add APX emitter unit test cases for the above. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Require precise estimation instead of tolerating some over-estimates.