Repository navigation
JIT: don't embed masks into narrowing conversions - #138230
Conversation
Narrowing conversions (cvt[t]pd2dq, cvtpd2ps, *qq2ps, *2ph, vpmov*, ...) apply the EVEX write mask per narrower destination element, with the element count set by the source vector length, and zero destination bits above the converted elements. isEmbeddedMaskingCompatible assumed mask lanes evenly cover the result type, so a ConditionalSelect over wider lanes (e.g. Vector128<long> over a 256->128 vcvttpd2dq) was folded into embedded masking and produced wrong results. Reject embedded masking for these instructions. The only cases the old size check accepted were incorrect, so no valid optimizations are lost. Fixes dotnet#137901 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4c747c31-c1bb-4378-b083-0bfdb399534a
|
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. |
|
@tannergooding PTAL |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
🔵 Needs a closer look
The cross-family AVX-512 eligibility changes need JIT maintainer review of instruction-list completeness and reported validation because independent hardware execution and differential codegen checks were unavailable.
No open issues 🎉
What changed in this PR
This PR fixes incorrect JIT code generation when a ConditionalSelect mask is embedded into a narrowing conversion whose destination elements use a different mask width.
Changes:
- Rejects embedded masking for narrowing conversion instructions.
- Adds three regression tests covering double-to-integer and double-to-single conversions with 128-, 256-, and 512-bit inputs.
| File | Description |
|---|---|
src/tests/JIT/Regression_ro_2/Runtime_137901.cs |
Adds guarded regression tests for narrowing conversions followed by conditional selection. |
src/coreclr/jit/gentree.cpp |
Excludes narrowing conversions from embedded-mask compatibility. |
Review effort: Balanced
tannergooding
left a comment
There was a problem hiding this comment.
Changes look correct to me, but left a suggestion on how to make this less error prone or risky for people forgetting with new instructions
Reject embedded masking for narrowing conversions. Their write masks apply to
narrower destination elements, so embedding a mask from a wider-lane
ConditionalSelectcan produce incorrect results.Validation
and built the focused regression project on Windows x64.
and failed with the unfixed JIT in the same runtime layout. A separate probe
passed 2,481 checks with the fix and found 66 mismatches without it.
skipped; the probe passed 177 checks.
conversions followed by blends. Sample same-lane conversions and a masked
add retained identical codegen. No throughput benchmark or full SuperPMI
run was performed.
Resolves #137901
Note
This description was generated with Copilot.