Repository navigation
shader: lower s_xor_b32 in the mesh frontend, with s_movk_i32/s_xor_b32 tests (Part of #2413) - #3635
Conversation
s_movk_i32 writes the sign-extended 16-bit immediate as a known constant; VCC, EXEC and other special destinations stay refused. s_xor_b32 joins the SGPR-destination SOP2 bitwise branch. Source-built tests cover both, plus VCC/EXEC/M0 destination controls. Part of R0Y00#2413. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed 9d21285b by reading the diff; not built or run. I also disassembled our own cache of slot 57 programs to see which forms of these two instructions real code uses.
Verdict: approve. Both lowerings match the scalar analysis they sit next to, and neither can create heap or mask provenance. No MUST, no SHOULD.
-
s_movk_i32writes the same sign-extendedi.aconstant astransfer()(gfx1013_compute_native.cpp:891-892) and leaves the mesh SCC alone, as the ISA does. Overwriting an SGPR that held a saved EXEC mask turns it into a constant, so a later restore from it stays refused. Inside a per-lane skip, the write goes throughalu.write, so the skip-end invalidation covers it. -
s_xor_b32:transfer()has no case for it, so the destination symbol becomes unknown (:908-910).root_valuesonly extends ons_and_b32ands_lshl_b32, so an xor result can never pass as a masked root-constant heap slot. The value and SCC use the existingor/andcode. -
Checked against real programs: 310 cached slot 57 programs from our runs, disassembled:
Instruction Programs Destinations s_movk_i3261 213 SGPR, 1 vcc_lo, none M0s_xor_b3246 SGPR only The one
vcc_lowrite (a34e610e +0x2ef0) comes afterv_writelane_b32spills VCC tov127. The compiler then usesvcc_lo/vcc_hias words 2–3 of a buffer descriptor. Keeping that refused, as this PR does, matches the frontend's other VCC writes. It needs VCC-as-SGPR support, which is separate work.
Tests: scalar-movk-xor proves the sign extension (xor i32 -2, -1) and that the result reaches the position export. The five negative controls pin each destination refusal. CI did not run native_direct_mesh (not in the pr filter); the author ran it locally (192 passed).
R0Y00#3638 added s_movk_i32 for SGPR destinations. Keep that implementation and drop this branch's copy. The tests now expect the generic refusal for VCC, EXEC and M0 destinations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00
left a comment
There was a problem hiding this comment.
Windows passed on this head. The failing Linux job is tests/startup_close_guard_check.py: the Close fixture extracts the trace added by #3638 and its fake state has no trace recording field. I reproduced the failure separately from the mesh lowering and opened #3642 with the narrow fix. Please rerun the Linux check against a base containing that fix before merging this PR.
|
Thanks for the review and the real-program table. While this was open, #3638 landed its own Two test changes came with it:
I re-ran the mutation checks on the merged head
The mesh suite passes, 202/202. The |
lukaslw-lab
left a comment
There was a problem hiding this comment.
Re-reviewed a671a700 by reading the diff; not built or run. Main has been merged twice since my last review. The PR now keeps #3638's s_movk_i32 and adds s_xor_b32 plus tests. Its own lines are the same as at e5c65430.
Verdict: approve. No MUST, no SHOULD.
- Checked, no finding:
s_xor_b32joins the SOP2 bitwise branch (src/gfx1013_direct_mesh.inl:1517-1528). It uses the sameknown()guard, the same unknown-destination fallback and SCC = result ≠ 0 ass_or_b32/s_and_b32.root_valuesis not propagated through xor, so a masked root constant loses its provenance there. That is the conservative choice, and an xor'd heap slot stays refused.transfer()has nos_xor_b32case, so the symbolic state is the same as fors_or_b32.- #3638's
s_movk_i32handler (:1504) takes onlydst < 106. VCC/EXEC/M0 destinations fall through to the generic refusal, which matches the updated test reasons. A VCC destination, as ata34e610e+0x2ef0 in my earlier census, stays refused. - Test encodings: SOPK
0xb014fffe=s_movk_i32 s20, 0xfffe; SOP2 op 180x8915c114=s_xor_b32 s21, s20, -1; VOP20x36020015=v_and_b32 v1, s21, v0. The negative words differ only insdst(0x6a/0x7e/0x7c), inserted at+0x14.
Tests: scalar-movk-xor proves sign extension (xor i32 -2, -1) and that the xor result reaches the position export. The five refusals pin both opcodes' non-SGPR destinations. native_direct_mesh is not in the Windows pr preset filter, so CI does not run it. The author ran it locally on the merge with a0e126c2.
Part of #2413.
The C++ mesh frontend (
src/gfx1013_direct_mesh.inl) refuseds_xor_b32asunsupported mesh instruction or EXEC state. It was the first refusal for 41 of the 454 cached slot 57 requests in my local census.#3638 landed
s_movk_i32for SGPR destinations while this PR was open. I merged main and kept that implementation. This PR now addss_xor_b32and tests for both instructions.Change
s_xor_b32joins the existing SOP2 bitwise branch next tos_or_b32ands_and_b32. It lowers toxor i32, with SCC = (result != 0). A destination of 106 or above is still refused, because that branch only takes SGPR destinations.Tests
In
tests/native_direct_mesh_check.py, next to the scalar EXEC/VCC write checks:scalar-movk-xor:s_movk_i32 s20, 0xfffe, thens_xor_b32 s21, s20, -1, feedsv_and_b32 v1, s21, v0and the exported X position. The test assertsxor i32 -2, -1(so thes_movk_i32immediate is sign-extended) and that theandreaching the position export uses that result.s_movk_i32to VCC, EXEC and M0, ands_xor_b32to EXEC and VCC. Each one must be refused at+0x14with its exact reason.Mutation checks on the merged branch, each caught by
native_direct_mesh:s_xor_b32asor;s_xor_b32from the SOP2 branch;s_movk_i32immediate in the shared scalar ALU (gfx1013_direct_compute.inl).Verification
a0e126c2,ctest --preset release -R "mesh|compile_dxil" -j 4: 202 passed (the twomesh_two_exitscases skip, as on main).compile_dxil --refusalsover the 454 cached slot 57 requests (layout from tracking: fixed mesh pipelines (slot 57) through the native C++ frontend #3416): nos_xor_b32ors_movk_i32refusal is left.🤖 Generated with Claude Code