Skip to content

rdna2spirv, lane_masks: handle special/mask destinations in s_cmov_b32, s_cmovk_i32, and s_movk_i32 (SHADER-CMOV32-MASK-AND-DST) - #2011

Open
ShotTechOp wants to merge 1 commit into
ProjectLeonida:mainfrom
ShotTechOp:fix/cmov32-mask-and-dst
Open

ShotTechOp wants to merge 1 commit into
ProjectLeonida:mainfrom
ShotTechOp:fix/cmov32-mask-and-dst

Conversation

@ShotTechOp

Copy link
Copy Markdown
Contributor

Claimed in #1608 as SHADER-CMOV32-MASK-AND-DST.

What and why

  • s_cmov_b32 and s_cmovk_i32 (D = SCC ? S0 : D, SCC read and not written) in tools/rdna2spirv.py previously restricted the destination to plain SGPRs (if a[0]["k"] != "sgpr": raise Unsupported(...)), rejecting exec_lo, exec_hi, vcc_lo, vcc_hi, m0, and null even though all are valid 32-bit SDST encodings in RDNA2 SOP1/SOPK.
  • tools/lane_masks.py also had no rules for s_cmov_b32, s_cmovk_i32, or s_movk_i32:
    1. s_cmov_b32 / s_cmovk_i32 targeting a lane-mask SGPR (from another mask or 0/-1) cleared its lane-mask tag, causing later whole-wave readers like s_bcnt1_i32_b32 to read a per-lane bool (0xFFFFFFFF/0) as scalar data (32 or 0) instead of the wave's popcount.
    2. s_movk_i32 writing 0 or -1 (0xffff) did not record EITHER, so:
      • In wave64, s_movk_i32 vcc_lo, 0/-1 failed vcc_half_keeps_mask() and overwrote the whole %vcc (wiping vcc_hi), while s_movk_i32 vcc_hi, 0/-1 only stored %vcc_hi without updating lanes 32..63 of %vcc.
      • Across a CFG join, s_movk_i32 sN, 0/-1 on one path and a lane mask on the other dropped sN from the lane-mask state.
  • Routing s_cmov_b32 and s_cmovk_i32 through the existing 32-bit mask helpers (_mask_b32_dst_half / _mask_b32_src / _store_b32_mask_dst) and modeling s_movk_i32 / s_cmov_b32 / s_cmovk_i32 in lane_masks.step fixes all four cases cleanly.
  • Updated the Scalar select and pack contract row in docs/design.md.

Testing

  • AI-assisted: yes.
  • Environment: Windows 11, Python 3.12 (no GPU / LLVM / SPIRV-Tools installed locally).
  • New regression suite: tests/semantic/test_cmov32_mask_and_dst.py — tests s_cmov_b32 / s_cmovk_i32 into exec_lo/exec_hi (wave32 and wave64, cross-half exec_lo <- vcc_hi, untouched-half preservation), vcc_lo/vcc_hi, m0, null, lane-mask SGPRs (with s_bcnt1_i32_b32), and s_movk_i32 wave64 vcc_lo/vcc_hi half-writes + CFG merge.
  • RED control on origin/main: tests/semantic/test_cmov32_mask_and_dst.py fails with FAILED (failures=8, errors=2) (proving Unsupported on exec/vcc/m0/null, broken s_bcnt1 returning 32/0 after s_cmov_b32/s_cmovk_i32 on mask SGPRs, and broken wave64 s_movk_i32 vcc_lo/vcc_hi half-writes + CFG merge).
  • GREEN checks on branch:
    • python -I tests/semantic/test_cmov32_mask_and_dst.py -v (4/4 OK)
    • python -m unittest discover -s tests/semantic -p test_salu_cmov.py (5/5 OK)
    • python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py (9 ran, OK, 1 skipped)
    • python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py (7/7 OK)
    • python -m unittest discover -s tests/semantic -p test_scalar_alu_imm_bitset.py (17/17 OK)
    • python -m unittest discover -s tests -p "test_docs_*.py" (50/50 OK)
    • python -I tests/test_text_write_line_endings.py (3/3 OK)
    • python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_cmov32_mask_and_dst.py
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tools/lane_masks.py docs/design.md tests/semantic/test_cmov32_mask_and_dst.py
    • git diff --check

@xel1uz xel1uz 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.

Approving 8fbcc22b. I verified it on main 747809e (merged cleanly).

  • Reading: s_cmov_b32 / s_cmovk_i32 now go through the existing 32-bit mask helpers (_mask_b32_dst_half, _mask_b32_src, _store_b32_mask_dst) instead of refusing every non-SGPR destination. null is a no-op, and lane_masks.step gains the matching rules, including EITHER for s_movk_i32 of 0 / 0xffff. The sign extension of s_cmovk_i32's immediate moved into an imm operand, and tests/semantic/test_salu_cmov.py (negative immediates included) still passes in the suite.
  • Own tests: tests/semantic/test_cmov32_mask_and_dst.py is OK.
  • Bite check: with main's tools/rdna2spirv.py and tools/lane_masks.py it fails (8 failures, 2 errors).
  • Whole translator suite: 492 files, 6,316 tests, 0 files failed. This includes test_salu_b32_lane_masks.py and test_wave64_vcc_half_write.py.

Ubuntu 26.04, Python 3.14, LLVM 21.1.8, SPIRV-Tools 2026.1.

AI-assisted review, CPU only.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2011 | head 8fbcc22 (merged cleanly with main 039870e) | python -I tests/semantic/test_cmov32_mask_and_dst.py && python -I scripts/run_semantic_tests.py -p "test_*cmov*.py" tests/semantic | red on main: FAILED (failures=8, errors=2) (rdna2spirv.Unsupported: s_cmov_b32 destination on exec_lo/vcc_lo/m0/null and s_bcnt1 counting lane bool 32 instead of active wave lanes after s_cmov_b32/s_movk_i32) | green on PR+main: 4 tests OK and 3 files, 33 tests, 0 files failed | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited s_movk_i32 / s_cmov_b32 / s_cmovk_i32 mask tracking in tools/lane_masks.py and _mask_b32_dst_half / _mask_b32_src / _store_b32_mask_dst lowering in tools/rdna2spirv.py across wave32 and wave64 (exec_lo/exec_hi, vcc_lo/vcc_hi, m0, null, and SGPR lane-mask CFG joins). Verified 0 merge conflicts with #2154 and #2239, plus passed tests/test_docs_table_ids.py (2 OK), tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Physical RADV gfx906 (Mesa 26.0.8, fixed subgroup 64), with synchronization validation enabled. I used the same nine synthetic shaders, two input patterns and both SCC values against main 4a54aedcb and head 8fbcc22b4 merged with it.

Main translated five shaders: 8/20 dispatches matched an independent integer oracle; the other 12 completed but returned 2,560 wrong words. The four remaining shaders were refused before dispatch (VCC, EXEC, and M0/null conditional destinations), not GPU failures. The merge translated all nine and passed 36/36 readbacks with no wrong words, guard writes, or validation errors.

The data failures on main included a correct selected SGPR mask followed by a wrong population count, and s_movk_i32 changing the untouched half of VCC. The plain SGPR control returned byte-identical results on both builds. This is native wave64 coverage, not a wave32 claim.

AI-assisted.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants