feat(relinker): lower the remaining AVX2 instructions under --to-avx #23636
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23636"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pwnAtl4nt1s on 2026-11-19T11:20:55Z.
What
--to-avxnow lowers every remaining AVX2 instruction, so a converted title no longer stops with an illegal instruction on an AVX-only host (Sandy Bridge, Ivy Bridge) because of AVX2:codegen/tests/GprVectorExecution.hppand is shared with the gather test.docs/dev/debt/changes/feat-relinker-avx-avx2-gaps.mdanddocs/user/USAGE.mdupdated.Semantics are from the Intel SDM vol. 2 entries of each instruction.
Tested
Linux x86-64 (Ubuntu 24.04, GCC 13.3), relinker-only build:
ctest1014/1014 passed. The new and extended tests compare every lowering with the SDM result and, since the host has AVX2, with the original instruction executed on the host, for every destination/source register (aliasing included), RFLAGS, the other GPRs and YMM registers and the red zone; memory operands at a page end, and masked-off gather/masked-load elements on a guard page. Mutation checks (deliberately broken lowerings) are caught by the tests. Not tested on an AVX-only CPU, nor with a title.tools/pr_overlap.pycould not be run from this environment (no GraphQL access); I checkedmainand found no lowering of these instructions.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T11:23:47Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
005e682509:tools/check_conventions.pyfailed.avx2_twin_lowering_tests,gather_lowering_tests,lane_split_lowering_tests,move_mask_lowering_tests,variable_shift_lowering_testsbuilt cleanly.avx2_twin_lowering,lane_split_lowering,move_mask_lowering,variable_shift_lowering,gather_lowering):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T07:48:50Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: fix the gather lowering’s incorrect handling of no-base and RIP-relative addresses.
What I ran
Reviewed head
005e68250983386a1821ac868997e0c9519eb1fbusing the prepared diff and pinnedrepo_read.pyreader. No build or tests were run in this review; the test result in the description is author-reported.Results
Findings
Blocking
core/relinker/codegen/src/x86/GatherLowering.cpp:47: Gather address generation does not preserve all valid memory addressing forms. For SIBmod=0, base=5(no base),_addressemits[address + index*scale + displacement], treating the gather index as an additional address index; the original effective address is absolute displacement plus the vector index times scale. For RIP-relative operands, it similarly uses a GPR with the displacement and omits RIP-relative relocation, yielding an incorrect address in the stub. This can make valid gathers load from the wrong location. Preserve these address forms when building each element address, or reject forms that cannot be represented correctly.Non-blocking
None.
Sources
core/relinker/codegen/src/x86/GatherLowering.cpp,core/relinker/codegen/include/codegen/x86/VexEncoding.hpp, andcore/relinker/codegen/src/x86/StubBodyBuilder.cpp.Not verified
To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T09:08:18Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
2b71fe7367:tools/check_conventions.pypassed.avx2_twin_lowering_tests,gather_lowering_tests,lane_split_lowering_tests,move_mask_lowering_tests,variable_shift_lowering_testsbuilt cleanly.avx2_twin_lowering,lane_split_lowering,move_mask_lowering,variable_shift_lowering,gather_lowering):core/relinker/codegen/include/codegen/x86/LaneSplitLowering.hpp,core/relinker/codegen/src/x86/Amd64OnlyInstructionMatcher.cpp,core/relinker/codegen/src/x86/Avx2TwinLowering.cpp,core/relinker/codegen/src/x86/LaneSplitLowering.cpp,core/relinker/codegen/src/x86/GatherLowering.cpp,core/relinker/codegen/src/x86/MoveMaskLowering.cpp,core/relinker/codegen/src/x86/VariableShiftLowering.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T09:22:26Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: keep the gather address temporary distinct from the destination, mask, and index registers so the lowering preserves its inputs.
What I ran
Reviewed head
2b71fe7367ebf3281217dd0aee60a42c4a06e676. I read the prepared description, commits, manifest, diff, and targeted source and test files. I did not run commands or tests.Results
Findings
Blocking
core/relinker/codegen/src/x86/GatherLowering.cpp:121-127: The address register is chosen from a fixed candidate list while excluding only the memory base. It can alias the gather destination, mask, or index. For example, when destination isymm0, mask isymm1, index isymm2, and base isr3, the first candidater0is selected as the address temporary._addressthen overwritesr0before the final merge, so the original destination is lost; if the chosen register aliases the index or mask, those inputs are also lost. Select a temporary that avoids every live operand, or preserve and restore any aliased operand before using it.Non-blocking
None.
Not verified
I did not run the reported test suite, build, or a title on hardware. The prepared diff and manifest were read; targeted full source reads covered the gather, variable shift, move mask, lane split, AVX2 twin, matcher, and gather tests. The remaining changed files were not read in full, although their diff hunks and manifest entries were inspected. No excluded-file list was available in the review folder.
To get this to a good state
Choose a gather address temporary that cannot clobber the destination, mask, or index operands, and rerun the gather lowering tests and reported test suite.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:55:16Z.
Review: COMMENTED
Built this head with
ANYPS5_RELINKER_ONLY=ONusing GCC 14.2 on Linux x86-64. The lane split, move mask, and variable shift suites passed.gather_loweringsegfaulted on the first run and all three reruns. The same fixture passed after changing only its CPU feature probe in the scratch build.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.