Repository navigation
fix(relinker): lower VEX.W=1 VPMOVSX and VPMOVZX under --to-avx - #24324
Conversation
The 256-bit VPMOVSX and VPMOVZX moves are VEX.WIG, so an encoding with VEX.W=1 is the same instruction, and binutils decodes it as one. The widen/broadcast decoder rejected every VEX.W=1 encoding, which left such a move unlowered as an AVX2 instruction in output for AVX-only hosts. Only the broadcasts, which require VEX.W=0, now reject it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against fbb32f9730:
- Conventions:
tools/check_conventions.pypassed. - Build:
widen_broadcast_lowering_testsbuilt cleanly. - CTest (
widen_broadcast_lowering):1/1 Test #6137: widen_broadcast_lowering ......... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/relinker/codegen/src/x86/WidenBroadcastLowering.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #6137: widen_broadcast_lowering .........***Failed 0.05 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- core/relinker/codegen/src/x86/WidenBroadcastLowering.cpp: Verified that DecodeWidenBroadcast no longer rejects instruction->Wide (VEX.W=1) for 256-bit VPMOVSX and VPMOVZX widening moves (opcodes 0x20..0x25 and 0x30..0x35) in accordance with Intel SDM where VEX.W is ignored (WIG).
- core/relinker/codegen/src/x86/WidenBroadcastLowering.cpp: Verified that the
else if (instruction->Wide) return std::nullopt;branch accurately preserves rejection of VEX.W=1 for all broadcast instructions (0x18, 0x19, 0x58, 0x59, 0x78, 0x79) which are strictly W0 encodings. - core/relinker/codegen/src/x86/WidenBroadcastLowering.cpp: Verified that EmitWidenBroadcast correctly emits W=0 in Form widen{Map0F38, Prefix66, false, false, operands.Opcode} when generating lowering stub instructions, preserving identical semantics regardless of the guest instruction's VEX.W bit.
- core/relinker/codegen/tests/WidenBroadcastLoweringTests.cpp: Verified helper withW() correctly toggles VEX.W (byte 2 bit 7) and test coverage exercises decoding, Rossetta/AVX matching, and JIT/runner execution of VEX.W=1 forms alongside negative tests for W=1 broadcasts.
- AGENTS.md compliance: Verified no comments in code, conventional commit formatting, valid PR template checklist, and clean mechanical checks.
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The change is narrowly scoped to VEX.W handling for widening moves and includes decoding, matching, and execution coverage for those forms.
What I ran
- Reviewed head
fbb32f973028981aaf413c719ebcec5a96586e55. - Read
description.md,commits.md,manifest.json,diff.patch,WidenBroadcastLowering.cpp, andWidenBroadcastLoweringTests.cpp. - Used
repo_read.pysearch for related VEX and lowering behavior. No tests were run during this review.
Results
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | Both changed files read |
| Automated tests | not run | Author reports 1,079 passing |
| Related context | partial | Search performed; decoder implementation not read |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The VEX decoder implementation and the author-reported test and convention-check results were not independently verified. files.json was unavailable through the reader, so the reviewed-file list could not be cross-checked against its reviewed entries.
To get this to a good state
Nothing is required.
|
Thanks both for checking, and for the negative control with the lowering reverted. |
edglz
left a comment
There was a problem hiding this comment.
Summary
Correct fix. The Intel SDM encodes VPMOVSX*/VPMOVZX* as VEX.256.66.0F38.WIG, so VEX.W must be ignored for the widening forms, while VBROADCASTSS/SD and VPBROADCASTB/D/Q are W0 and stay rejected with W=1. The change moves the Wide check from the shared guard to the broadcast branch, which matches both rules.
Verification
Environment: macOS 26, Apple M4 (arm64), Apple clang 21.0.0, Python 3.15.2, relinker-only build.
| Check | Result |
|---|---|
widen_broadcast_lowering on this head |
Pass |
Same test file against main |
Fails: a 256-bit widening move with VEX.W=1, which the move ignores, was not decoded |
Broadcast forms with W=1 (0x18, 0x59, 0x78) |
Still rejected |
| CI relinker jobs (Linux, Windows, macOS, ASan) | Green |
Notes
- Removing
{0xC4, 0xE2, 0xFD, 0x31, 0xC1}from the rejection list is consistent: it is VEX.256.W1 VPMOVZXBD, which is now lowered as intended. - Not verified: the execution cases.
LOWERING_EXECUTION_AVAILABLEis 0 on arm64; CI covers them on x86-64.
Verdict
Approved.
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
What
--to-avxlowered the 256-bit VPMOVSX/VPMOVZX widening moves only when VEX.W=0. These moves are WIG (VEX.W is ignored), so an encoding with VEX.W=1 is the same instruction and was left unlowered.DecodeWidenBroadcastnow accepts VEX.W=1 for the widening moves and still rejects it for the broadcasts (VBROADCASTSS, VPBROADCASTD/Q/B/W, VBROADCASTSD), which are W0 only. Tests cover decoding, matching and execution of the VEX.W=1 forms and check that VEX.W=1 broadcasts are still rejected.Tested
Windows 11, relinker-only build (
build-relinker, WinLibs GCC 16.2.0):ctest --test-dir build-relinker --output-on-failure --timeout 120 --parallel 8 --no-tests=error, 100% tests passed out of 1079, includingwiden_broadcast_lowering.python3 tools/check_conventions.py --base upstream/mainpassed.python3 tools/pr_overlap.py --branch pr/decoder-audit: no overlap with open pull requests.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)