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
github-bot wants to merge 1 commit from github-bot/gh-2011 into main AGit
Owner

@⁠ShotTechOp on GitHub · 2026-11-25 18:05 UTC · original
ShotTechOp:fix/cmov32-mask-and-dst → main · +360 −8 · 4 files · 1 commits · open

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
**@⁠ShotTechOp** on GitHub · 2026-11-25 18:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2011) `ShotTechOp:fix/cmov32-mask-and-dst` → `main` · +360 −8 · 4 files · 1 commits · open 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`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:14:43 +00:00
Author
Owner

@⁠xel1uz on GitHub · 2026-11-25 21:14 UTC · original · approved these changes

Approving 8fbcc22b. I verified it on main 747809e7 (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.

**@⁠xel1uz** on GitHub · 2026-11-25 21:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2011#pullrequestreview-6065078734) · **approved these changes** Approving `8fbcc22b`. I verified it on `main` 747809e7 (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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2011/head:github-bot/gh-2011'
git switch 'github-bot/gh-2011'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2011'
git switch 'github-bot/gh-2011'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2011'
git switch 'github-bot/gh-2011'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2011'
git switch 'main'
git merge --squash 'github-bot/gh-2011'
git switch 'main'
git merge --ff-only 'github-bot/gh-2011'
git switch 'main'
git merge 'github-bot/gh-2011'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.