Skip to content

fix(relinker): lower VEX.W=1 VPMOVSX and VPMOVZX under --to-avx - #24324

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
HistoryTeacher69:pr/decoder-audit
Nov 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
HistoryTeacher69:pr/decoder-audit

Conversation

@HistoryTeacher69

Copy link
Copy Markdown
Contributor

What

--to-avx lowered 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. DecodeWidenBroadcast now 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, including widen_broadcast_lowering. python3 tools/check_conventions.py --base upstream/main passed. python3 tools/pr_overlap.py --branch pr/decoder-audit: no overlap with open pull requests.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

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 PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against fbb32f9730:

  • Conventions: tools/check_conventions.py passed.
  • Build: widen_broadcast_lowering_tests built 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.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #6137: widen_broadcast_lowering .........***Failed    0.05 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • 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 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and WidenBroadcastLoweringTests.cpp.
  • Used repo_read.py search 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.

@HistoryTeacher69

Copy link
Copy Markdown
Contributor Author

Thanks both for checking, and for the negative control with the lowering reverted.

@edglz edglz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_AVAILABLE is 0 on arm64; CI covers them on x86-64.

Verdict

Approved.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head fbb32f9730, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#18156, #21208, #22013, #22795, #23226, #23385, #24533, #24582, #24690, #24693, #17553, #19619, #20085, #21081, #19682, #22123, #22529, #22572, #22662, #23479, #23787, #24568, #15330, #21249, #21630, #21713, #22040, #23490, #24394). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
widen_broadcast_lowering (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6540 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #17553 (guest_memory); none is in this PR's area. The 2143 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

This was referenced Nov 21, 2026
@oneandonlydean
oneandonlydean merged commit 92ce275 into boykopovar:main Nov 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants