Skip to content

shader: lower s_xor_b32 in the mesh frontend, with s_movk_i32/s_xor_b32 tests (Part of #2413) - #3635

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
mumba17:shader/mesh-movk-xor
Dec 1, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
mumba17:shader/mesh-movk-xor

Conversation

@mumba17

@mumba17 mumba17 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2413.

The C++ mesh frontend (src/gfx1013_direct_mesh.inl) refused s_xor_b32 as unsupported 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_i32 for SGPR destinations while this PR was open. I merged main and kept that implementation. This PR now adds s_xor_b32 and tests for both instructions.

Change

  • s_xor_b32 joins the existing SOP2 bitwise branch next to s_or_b32 and s_and_b32. It lowers to xor 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, then s_xor_b32 s21, s20, -1, feeds v_and_b32 v1, s21, v0 and the exported X position. The test asserts xor i32 -2, -1 (so the s_movk_i32 immediate is sign-extended) and that the and reaching the position export uses that result.
  • Negative controls: s_movk_i32 to VCC, EXEC and M0, and s_xor_b32 to EXEC and VCC. Each one must be refused at +0x14 with its exact reason.

Mutation checks on the merged branch, each caught by native_direct_mesh:

  • lowering s_xor_b32 as or;
  • dropping s_xor_b32 from the SOP2 branch;
  • zero-extending the s_movk_i32 immediate in the shared scalar ALU (gfx1013_direct_compute.inl).

Verification

🤖 Generated with Claude Code

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 lukaslw-lab 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 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_i32 writes the same sign-extended i.a constant as transfer() (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 through alu.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_values only extends on s_and_b32 and s_lshl_b32, so an xor result can never pass as a masked root-constant heap slot. The value and SCC use the existing or/and code.

  • Checked against real programs: 310 cached slot 57 programs from our runs, disassembled:

    Instruction Programs Destinations
    s_movk_i32 61 213 SGPR, 1 vcc_lo, none M0
    s_xor_b32 46 SGPR only

    The one vcc_lo write (a34e610e +0x2ef0) comes after v_writelane_b32 spills VCC to v127. The compiler then uses vcc_lo/vcc_hi as 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>
@mumba17 mumba17 changed the title shader: lower s_movk_i32 and s_xor_b32 in the mesh frontend (Part of #2413) shader: lower s_xor_b32 in the mesh frontend, with s_movk_i32/s_xor_b32 tests (Part of #2413) Nov 30, 2026

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@mumba17

mumba17 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the real-program table. While this was open, #3638 landed its own s_movk_i32 handler (SGPR destinations, through the shared scalar ALU). I merged main and kept that one, so the s_movk_i32 code you reviewed is gone. This PR is now s_xor_b32 plus tests for both.

Two test changes came with it:

I re-ran the mutation checks on the merged head e5c65430. Each one fails native_direct_mesh:

  • xor lowered as or;
  • s_xor_b32 dropped;
  • zero-extending the s_movk_i32 immediate.

The mesh suite passes, 202/202. The vcc_lo case stays refused, as you said.

@lukaslw-lab lukaslw-lab 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.

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_b32 joins the SOP2 bitwise branch (src/gfx1013_direct_mesh.inl:1517-1528). It uses the same known() guard, the same unknown-destination fallback and SCC = result ≠ 0 as s_or_b32/s_and_b32.
    • root_values is 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 no s_xor_b32 case, so the symbolic state is the same as for s_or_b32.
    • #3638's s_movk_i32 handler (:1504) takes only dst < 106. VCC/EXEC/M0 destinations fall through to the generic refusal, which matches the updated test reasons. A VCC destination, as at a34e610e +0x2ef0 in my earlier census, stays refused.
    • Test encodings: SOPK 0xb014fffe = s_movk_i32 s20, 0xfffe; SOP2 op 18 0x8915c114 = s_xor_b32 s21, s20, -1; VOP2 0x36020015 = v_and_b32 v1, s21, v0. The negative words differ only in sdst (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants