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

Open
opened 2026-11-26 21:19:45 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2011
Author: @ShotTechOp
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/cmov32-mask-and-dst


📝 Commits (1)

  • 8fbcc22 rdna2spirv, lane_masks: handle special and lane-mask destinations in s_cmov_b32, s_cmovk_i32, and s_movk_i32

📊 Changes

4 files changed (+360 additions, -8 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_cmov32_mask_and_dst.py (+321 -0)
📝 tools/lane_masks.py (+23 -0)
📝 tools/rdna2spirv.py (+15 -7)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2011 **Author:** [@ShotTechOp](https://github.com/ShotTechOp) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/cmov32-mask-and-dst` --- ### 📝 Commits (1) - [`8fbcc22`](https://github.com/ubiquitarianism/leonida/commit/8fbcc22b4cf005e7e402c36784f7c9f7f95839fa) rdna2spirv, lane_masks: handle special and lane-mask destinations in s_cmov_b32, s_cmovk_i32, and s_movk_i32 ### 📊 Changes **4 files changed** (+360 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_cmov32_mask_and_dst.py` (+321 -0) 📝 `tools/lane_masks.py` (+23 -0) 📝 `tools/rdna2spirv.py` (+15 -7) </details> ### 📄 Description 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2016
No description provided.