Fix VPEXPAND byte and word memory load masks #851
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 448 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.365
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #851"
general
weight: 0.35
stlintel
Problem
The memory-source handlers for
VPEXPANDBandVPEXPANDWbuild adense load mask from the number of enabled destination elements:
Both shifts begin with the signed 32-bit integer literal
1. ForVPEXPANDB, a population count of 31 shifts into the sign bit, whilecounts from 32 through 63 use a shift count outside the type's width.
For
VPEXPANDW, count 31 similarly shifts into the sign bit and count32 uses an out-of-range shift. These operations have undefined behavior
in C++.
In the tested optimized build,
VPEXPANDBproduced incorrect resultsfor counts 32 through 63, including an EVEX.256 operation selecting all
32 byte elements.
VPEXPANDWproduced an incorrect result when all 32word elements were selected by an EVEX.512 operation.
Only the masked memory-source handlers construct these dense load masks.
The register-source handlers are unaffected.
Fix
Construct the byte load mask with
BX_CONST64(1), making shifts throughcount 63 well-defined while retaining the existing special case for all
64 byte elements.
For the word load mask, handle all 32 elements with an explicit all-ones
mask and use
Bit32u(1)for smaller counts. This also makes thecount-31 boundary unsigned and well-defined.
Architectural reference
The Intel® 64 and IA-32 Architectures Software Developer's Manual,
Volume 2, section “VPEXPANDB/VPEXPANDW—Load Sparse Packed Byte/Word
Integer Values from Dense Memory/Register,” specifies that consecutive
elements from the dense source are copied to destination positions
selected by the writemask.
Consequently, a memory-source operation must load one consecutive source
element for each enabled destination element. The internal dense load
mask must therefore contain exactly
popcount(k)low set bits, includingthe full 32-byte and 32-word cases.
Validation
A standalone 64-bit CPL3 guest exercised the memory-source forms on the
Bochs
tigerlakeCPU model with AVX-512 state enabled (XCR0=0xe7).Every test used ordinary mapped memory containing distinctive nonzero
elements and initialized the destination with nonzero merge sentinels.
The count-31 cases check the signed-shift boundary. The 64-byte case
checks the existing full-width special case. The remaining cases cover
the observed incorrect ranges and both applicable vector lengths at the
32-byte boundary.
| Instruction | Vector length | Active elements / mask shape | Before | After |
|---|---:|---|---:|---:|
|
VPEXPANDB| 512 | 31 low elements | PASS | PASS ||
VPEXPANDB| 256 | 32 elements (all) | FAIL | PASS ||
VPEXPANDB| 512 | 32 sparse elements | FAIL | PASS ||
VPEXPANDB| 512 | 33 sparse elements | FAIL | PASS ||
VPEXPANDB| 512 | 63 sparse elements | FAIL | PASS ||
VPEXPANDB| 512 | 64 elements (all) | PASS | PASS ||
VPEXPANDW| 512 | 31 sparse elements | PASS | PASS ||
VPEXPANDW| 512 | 32 elements (all) | FAIL | PASS |The source file used by the patched test build exactly matches the
committed source, and the patched tree builds successfully with
make -j2.git diff --checkalso passes.The validation used mapped memory and confirms the result correction. It
did not separately test page-fault behavior.