shader: lower s_cmov_b32, s_cmov_b64 and s_cmovk_i32 in the direct compute path #3071

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3071 into main 2026-11-27 20:33:06 +00:00
legacy-code-archaeologist commented 2026-11-27 14:07:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T14:07:13Z.


Lowers s_cmov_b32, s_cmov_b64 (SOP1) and s_cmovk_i32 (SOPK) in the direct C++ compute path (src/gfx1013_direct_compute.inl), adds reads_scc tracking in uses_scc_after(), and clears constant/symbolic state on s_cmovk_i32 in transfer() (src/gfx1013_compute_native.cpp).

Differences vs tools/startup/gfx2hlsl.py scalar_cmov

  • gfx2hlsl.py refuses vcc and lane-mask operands and accepts only an aligned SGPR pair for s_cmov_b64 S0.
  • The direct path additionally accepts vcc as s_cmov_b64 destination, wave32 vcc_lo/vcc_hi on the 32-bit forms, and inline integers (-16..64, sign-extended) or 32-bit literals (pair_high() zero-extension) on s_cmov_b64.

Verification

Measured on Windows 10.0.26100 (dev preset) on upstream/main 429f11d5 + this commit:

  • ctest --preset dev --no-tests=error -R '^native_salu_cmov_' -V:
    • native_salu_cmov_ir (passed): dumps DXIL IR via native_compute_ir_dump for all 24 cases (SCC=0 and SCC=1 across 12 forms including wave32 vcc_hi dst/src, vcc dst, -1234, 0x7FFF, -1, and 0x80000001), evaluates lane 0 to verify D = SCC ? S0 : D, preserved SCC, untouched neighbors, and sign-extended -1234 (4294966062 vs 64302); verifies the transfer() s_cmovk_i32 baseline + exact-pc +0x10 refusal and 11 destination/source refusals (including 3 no-epilogue symbolic-descriptor dst cases at exact pc +0x20).
    • native_salu_cmov_controls (passed): compiles all 12 accepted forms via compile_dxil, verifies the transfer() baseline + all 12 exact-pc/diagnostic refusals, and checks 5 reference mutants.
    • native_salu_cmov_hardware (skipped, exit 77): Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback (including the unmeasured 0x80000001 literal high word) is not measured on hardware here.
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 47/47 passed.
  • python -B tests/docs_links_check.py: passed (102 Markdown files, 590 links).
  • Broken-lowering sensitivity check: 6 deliberate broken builds (ignores_scc, inverted_select, writes_nothing, zero_ext_cmovk, keeps_old_high_word, and dropping s_cmovk_i32 from transfer()) each failed native_salu_cmov_ir.

Fixes #3070

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5527982933 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3071). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T14:07:13Z. --- Lowers `s_cmov_b32`, `s_cmov_b64` (SOP1) and `s_cmovk_i32` (SOPK) in the direct C++ compute path (`src/gfx1013_direct_compute.inl`), adds `reads_scc` tracking in `uses_scc_after()`, and clears constant/symbolic state on `s_cmovk_i32` in `transfer()` (`src/gfx1013_compute_native.cpp`). ## Differences vs `tools/startup/gfx2hlsl.py` `scalar_cmov` - `gfx2hlsl.py` refuses `vcc` and lane-mask operands and accepts only an aligned SGPR pair for `s_cmov_b64` `S0`. - The direct path additionally accepts `vcc` as `s_cmov_b64` destination, wave32 `vcc_lo`/`vcc_hi` on the 32-bit forms, and inline integers (`-16..64`, sign-extended) or 32-bit literals (`pair_high()` zero-extension) on `s_cmov_b64`. ## Verification Measured on Windows 10.0.26100 (`dev` preset) on `upstream/main` `429f11d5` + this commit: - `ctest --preset dev --no-tests=error -R '^native_salu_cmov_' -V`: - `native_salu_cmov_ir` (**passed**): dumps DXIL IR via `native_compute_ir_dump` for all 24 cases (`SCC=0` and `SCC=1` across 12 forms including wave32 `vcc_hi` dst/src, `vcc` dst, `-1234`, `0x7FFF`, `-1`, and `0x80000001`), evaluates lane 0 to verify `D = SCC ? S0 : D`, preserved `SCC`, untouched neighbors, and sign-extended `-1234` (`4294966062` vs `64302`); verifies the `transfer()` `s_cmovk_i32` baseline + exact-pc `+0x10` refusal and 11 destination/source refusals (including 3 no-epilogue symbolic-descriptor dst cases at exact pc `+0x20`). - `native_salu_cmov_controls` (**passed**): compiles all 12 accepted forms via `compile_dxil`, verifies the `transfer()` baseline + all 12 exact-pc/diagnostic refusals, and checks 5 reference mutants. - `native_salu_cmov_hardware` (**skipped**, exit `77`): Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback (including the unmeasured `0x80000001` literal high word) is not measured on hardware here. - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **47/47 passed**. - `python -B tests/docs_links_check.py`: **passed** (102 Markdown files, 590 links). - Broken-lowering sensitivity check: 6 deliberate broken builds (`ignores_scc`, `inverted_select`, `writes_nothing`, `zero_ext_cmovk`, `keeps_old_high_word`, and dropping `s_cmovk_i32` from `transfer()`) each failed `native_salu_cmov_ir`. Fixes #3070 AI-assisted.
JohnConnorNPC commented 2026-11-27 18:01:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-27T18:01:51Z.


Thanks for this. The lowering reads cleanly: operands are read before the writes, the immediate is sign-extended
as in s_movk_i32, and the encodings in the fixture disassemble as named.

I ran native_salu_cmov_check.py controls against a few deliberately broken builds of compile_dxil:

  • the move ignores SCC;
  • the select is inverted;
  • nothing is written;
  • s_cmovk_i32 zero-extends;
  • s_cmov_b64 keeps the old high word.

All five still pass controls. A build that accepts an exec destination fails, as it should. I think the reason
is that controls only checks 'select i1' in dump. Every program from compute_program() already has seven of
those (the closing s_cselect_b32 s26, 1, 0 and the lane-masked vector moves), even with no s_cmov lowering at
all. The "5 reference mutants differ" step compares the Python reference with itself. The real assertions are in
hardware, which skipped on your machine and doesn't run in CI. As far as I can tell, D = SCC ? S0 : D isn't
checked anywhere that runs. Could you add one of these?

  1. An IR-level control (as native_f16_alu_check.py ir does with native_compute_ir_dump) asserting the select
    operand order, the sign-extended -1234 and the s_cmov_b64 high word.
  2. A hardware run on a GPU with SM 6.6 wave32, reported with adapter, driver, commit and debug-layer status.

Smaller points:

  • Several accepted forms are compiled only in hardware. Compiling each in controls would catch a later change
    that refuses one:
    • s_cmov_b32 from an SGPR or 1.0;
    • s_cmov_b64 from -1 or a literal;
    • vcc as the s_cmov_b64 destination;
    • wave32 vcc_hi.
  • The 0x80000001 literal case is the one where zero and sign extension differ. LLVM encodes 0x80000001 and
    0xffffffff80000001 identically, so only a measurement or an ISA reference settles it.
  • Dropping the new s_cmovk_i32 entry in transfer() also keeps the suite green. A control that observes it, or a
    note that it is precautionary, would help.
  • scalar_cmov in gfx2hlsl.py refuses vcc and lane-mask operands, and takes only an SGPR pair as the 64-bit
    source. The direct path accepts more, so "matching" in the doc and commit could say what differs.
  • The new reads_scc entries don't change the liveness result: these instructions were already treated as SCC
    readers through uncertain_scalar. Keeping them is fine.
  • The symbolic-destination case could assert the diagnostic and pc. The same "unbound numeric SGPR s24" text also
    comes from the epilogue when there is no s_cmov.
  • There is a one-line conflict with #3091 in the transfer() condition.

This comment was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7225043470 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3071#issuecomment-7225043470). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-27T18:01:51Z. --- Thanks for this. The lowering reads cleanly: operands are read before the writes, the immediate is sign-extended as in `s_movk_i32`, and the encodings in the fixture disassemble as named. I ran `native_salu_cmov_check.py controls` against a few deliberately broken builds of `compile_dxil`: - the move ignores SCC; - the select is inverted; - nothing is written; - `s_cmovk_i32` zero-extends; - `s_cmov_b64` keeps the old high word. All five still pass `controls`. A build that accepts an `exec` destination fails, as it should. I think the reason is that `controls` only checks `'select i1' in dump`. Every program from `compute_program()` already has seven of those (the closing `s_cselect_b32 s26, 1, 0` and the lane-masked vector moves), even with no `s_cmov` lowering at all. The "5 reference mutants differ" step compares the Python reference with itself. The real assertions are in `hardware`, which skipped on your machine and doesn't run in CI. As far as I can tell, `D = SCC ? S0 : D` isn't checked anywhere that runs. Could you add one of these? 1. An IR-level control (as `native_f16_alu_check.py ir` does with `native_compute_ir_dump`) asserting the select operand order, the sign-extended `-1234` and the `s_cmov_b64` high word. 2. A `hardware` run on a GPU with SM 6.6 wave32, reported with adapter, driver, commit and debug-layer status. Smaller points: - Several accepted forms are compiled only in `hardware`. Compiling each in `controls` would catch a later change that refuses one: - `s_cmov_b32` from an SGPR or `1.0`; - `s_cmov_b64` from `-1` or a literal; - `vcc` as the `s_cmov_b64` destination; - wave32 `vcc_hi`. - The `0x80000001` literal case is the one where zero and sign extension differ. LLVM encodes `0x80000001` and `0xffffffff80000001` identically, so only a measurement or an ISA reference settles it. - Dropping the new `s_cmovk_i32` entry in `transfer()` also keeps the suite green. A control that observes it, or a note that it is precautionary, would help. - `scalar_cmov` in `gfx2hlsl.py` refuses `vcc` and lane-mask operands, and takes only an SGPR pair as the 64-bit source. The direct path accepts more, so "matching" in the doc and commit could say what differs. - The new `reads_scc` entries don't change the liveness result: these instructions were already treated as SCC readers through `uncertain_scalar`. Keeping them is fine. - The symbolic-destination case could assert the diagnostic and pc. The same "unbound numeric SGPR s24" text also comes from the epilogue when there is no `s_cmov`. - There is a one-line conflict with #3091 in the `transfer()` condition. This comment was AI-assisted.
legacy-code-archaeologist commented 2026-11-27 18:13:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T18:13:10Z.


@JohnConnorNPC Thank you for the detailed review and for testing those broken lowerings! Addressed all points in rebased commit 9ec0c0a6 on upstream/main (429f11d5):

  1. IR-level check (native_salu_cmov_ir): Added ir mode in tests/native_salu_cmov_check.py (registered in tests/cmake/native_salu_cmov.cmake using native_compute_ir_dump) that evaluates lane 0 across all 24 cases (SCC=0 and SCC=1 for all 12 accepted forms). It verifies D = SCC ? S0 : D, preserved SCC, untouched neighbor words, the s_cmov_b64 high word, and sign-extended -1234 (4294966062 present and 64302 absent in the IR). Verified locally that all five broken builds you listed (ignore SCC, inverted select, write nothing, zero-extended s_cmovk_i32, kept old high word on s_cmov_b64) now fail native_salu_cmov_ir (exit 1). (native_salu_cmov_hardware still skips with 77 on Quadro M1000M — no SM 6.6 wave32 GPU here.)
  2. All accepted forms compiled in controls: controls now compiles all 12 accepted forms via compile_dxil (s_cmov_b32 SGPR/literal/1.0/wave32 vcc_hi dst & src, s_cmovk_i32 -1234/0x7FFF/wave32 vcc_hi dst, s_cmov_b64 pair/-1/0x80000001/vcc dst).
  3. 0x80000001 on s_cmov_b64: Documented in docs/experiments/native-direct-salu-cmov.md that 32-bit literal zero-extension comes from pair_high() (consistent with s_mov_b64, s_cselect_b64, s_not_b64, and s_lshr_b64) and remains unmeasured on SM 6.6 wave32 hardware here.
  4. s_cmovk_i32 in transfer(): Added an observable baseline + negative control where s_mov_b32 s21, 0 -> s_cmovk_i32 s21, 1 is followed by s_load_dwordx4 s[32:35], s[20:21], 0x20 (refused at +0x10 with direct descriptor address outside bound table). Dropping s_cmovk_i32 from transfer() causes this check to fail native_salu_cmov_ir (exit 1).
  5. Diff vs gfx2hlsl.py scalar_cmov: Updated the commit message and docs/experiments/native-direct-salu-cmov.md to spell out the differences instead of saying "matching", and noted the existing uncertain_scalar coverage for reads_scc.
  6. Symbolic-destination refusal & rebase: Removed the epilogue from the 3 symbolic-descriptor destination tests (s_cmov_b64, s_cmov_b32, s_cmovk_i32) and asserted native compute +0x20: unbound numeric SGPR s24, and rebased onto upstream/main 429f11d5 (resolving the transfer() context overlap with #3091).

Verification on Windows 10.0.26100 (dev preset): native_salu_cmov_ir and native_salu_cmov_controls pass; native_salu_cmov_hardware skips (77); all 47 native_*_(controls|ir) tests pass; python -B tests/docs_links_check.py passes (102 files, 590 links).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7225255398 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3071#issuecomment-7225255398). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T18:13:10Z. --- @JohnConnorNPC Thank you for the detailed review and for testing those broken lowerings! Addressed all points in rebased commit `9ec0c0a6` on `upstream/main` (`429f11d5`): 1. **IR-level check (`native_salu_cmov_ir`):** Added `ir` mode in `tests/native_salu_cmov_check.py` (registered in `tests/cmake/native_salu_cmov.cmake` using `native_compute_ir_dump`) that evaluates lane 0 across all 24 cases (`SCC=0` and `SCC=1` for all 12 accepted forms). It verifies `D = SCC ? S0 : D`, preserved `SCC`, untouched neighbor words, the `s_cmov_b64` high word, and sign-extended `-1234` (`4294966062` present and `64302` absent in the IR). Verified locally that all five broken builds you listed (ignore SCC, inverted select, write nothing, zero-extended `s_cmovk_i32`, kept old high word on `s_cmov_b64`) now fail `native_salu_cmov_ir` (exit `1`). (`native_salu_cmov_hardware` still skips with `77` on Quadro M1000M — no SM 6.6 wave32 GPU here.) 2. **All accepted forms compiled in `controls`:** `controls` now compiles all 12 accepted forms via `compile_dxil` (`s_cmov_b32` SGPR/literal/`1.0`/wave32 `vcc_hi` dst & src, `s_cmovk_i32` `-1234`/`0x7FFF`/wave32 `vcc_hi` dst, `s_cmov_b64` pair/`-1`/`0x80000001`/`vcc` dst). 3. **`0x80000001` on `s_cmov_b64`:** Documented in [`docs/experiments/native-direct-salu-cmov.md`](docs/experiments/native-direct-salu-cmov.md) that 32-bit literal zero-extension comes from `pair_high()` (consistent with `s_mov_b64`, `s_cselect_b64`, `s_not_b64`, and `s_lshr_b64`) and remains unmeasured on SM 6.6 wave32 hardware here. 4. **`s_cmovk_i32` in `transfer()`:** Added an observable baseline + negative control where `s_mov_b32 s21, 0` -> `s_cmovk_i32 s21, 1` is followed by `s_load_dwordx4 s[32:35], s[20:21], 0x20` (refused at `+0x10` with `direct descriptor address outside bound table`). Dropping `s_cmovk_i32` from `transfer()` causes this check to fail `native_salu_cmov_ir` (exit `1`). 5. **Diff vs `gfx2hlsl.py` `scalar_cmov`:** Updated the commit message and [`docs/experiments/native-direct-salu-cmov.md`](docs/experiments/native-direct-salu-cmov.md) to spell out the differences instead of saying "matching", and noted the existing `uncertain_scalar` coverage for `reads_scc`. 6. **Symbolic-destination refusal & rebase:** Removed the epilogue from the 3 symbolic-descriptor destination tests (`s_cmov_b64`, `s_cmov_b32`, `s_cmovk_i32`) and asserted `native compute +0x20: unbound numeric SGPR s24`, and rebased onto `upstream/main` `429f11d5` (resolving the `transfer()` context overlap with `#3091`). Verification on Windows 10.0.26100 (`dev` preset): `native_salu_cmov_ir` and `native_salu_cmov_controls` pass; `native_salu_cmov_hardware` skips (`77`); all 47 `native_*_(controls|ir)` tests pass; `python -B tests/docs_links_check.py` passes (102 files, 590 links). AI-assisted.
pigalot commented 2026-11-27 20:32:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T20:32:50Z.

Review: APPROVED


I reviewed 9ec0c0a6 merged into main 2e74b778 (tree 44389212, clean merge). This includes the hardware run JohnConnorNPC asked for in option 2.

What I traced.

  • Every operand is read before either write, so s_cmov_b64 with overlapping source and destination is safe.
  • The 32-bit forms accept wave32 vcc_hi (107) as destination and source. s_cmov_b64 accepts vcc (106) or an even SGPR pair, and takes inline or literal sources through pair_high().
  • s_cmovk_i32 sign-extends via int16_t, as s_movk_i32 does.
  • transfer() now clears s_cmovk_i32 destinations along with s_movk's neighbours.

What I ran. I built compile_dxil native_store_replay native_compute_ir_dump in dev and release, then ran:
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_salu_cmov_'

  • 3/3 passed in each preset.
  • native_salu_cmov_hardware ran and passed: all 24 cases report result words, preserved SCC and guards matched. That covers 12 forms × SCC 0/1, including wave32 vcc_hi source and destination, vcc as destination, -1234 and the 0x80000001 literal.

Mutants (in src/gfx1013_direct_compute.inl, rebuilt each time):

mutant _ir _hardware
32-bit select inverted (select(cond, old_lo, next)) fails fails
s_cmov_b64 keeps the old high word fails at ('cmov64 pair SCC=1', (0, 2309737967, 3735928559), (2309737967, 19088743)) fails

_controls passes in both cases, as expected for a compile-only check. Restored, all pass, and git diff --check is clean.

Still unmeasured: whether gfx1013 zero- or sign-extends a 32-bit literal in s_cmov_b64. The hardware run shows only that the lowering matches the PR's reference, which follows pair_high() (zero-extension). Settling it needs RDNA 2 hardware or an ISA statement.

Verdict: approve on 9ec0c0a6.

Environment: NVIDIA GeForce RTX 5090 (wave 32..32, SM 6.8), driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10.
CI: Build and test on Windows passes on 9ec0c0a6. There are no review threads.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093100088 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3071#pullrequestreview-6093100088). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T20:32:50Z. **Review:** APPROVED --- I reviewed `9ec0c0a6` merged into `main` `2e74b778` (tree `44389212`, clean merge). This includes the hardware run JohnConnorNPC asked for in option 2. **What I traced.** - Every operand is read before either write, so `s_cmov_b64` with overlapping source and destination is safe. - The 32-bit forms accept wave32 `vcc_hi` (107) as destination and source. `s_cmov_b64` accepts `vcc` (106) or an even SGPR pair, and takes inline or literal sources through `pair_high()`. - `s_cmovk_i32` sign-extends via `int16_t`, as `s_movk_i32` does. - `transfer()` now clears `s_cmovk_i32` destinations along with `s_movk`'s neighbours. **What I ran.** I built `compile_dxil native_store_replay native_compute_ir_dump` in `dev` and `release`, then ran: `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_salu_cmov_'` - 3/3 passed in each preset. - **`native_salu_cmov_hardware` ran and passed**: all 24 cases report `result words, preserved SCC and guards matched`. That covers 12 forms × SCC 0/1, including wave32 `vcc_hi` source and destination, `vcc` as destination, `-1234` and the `0x80000001` literal. **Mutants** (in `src/gfx1013_direct_compute.inl`, rebuilt each time): | mutant | `_ir` | `_hardware` | |---|---|---| | 32-bit select inverted (`select(cond, old_lo, next)`) | fails | fails | | `s_cmov_b64` keeps the old high word | fails at `('cmov64 pair SCC=1', (0, 2309737967, 3735928559), (2309737967, 19088743))` | fails | `_controls` passes in both cases, as expected for a compile-only check. Restored, all pass, and `git diff --check` is clean. **Still unmeasured:** whether gfx1013 zero- or sign-extends a 32-bit literal in `s_cmov_b64`. The hardware run shows only that the lowering matches the PR's reference, which follows `pair_high()` (zero-extension). Settling it needs RDNA 2 hardware or an ISA statement. **Verdict:** approve on `9ec0c0a6`. Environment: NVIDIA GeForce RTX 5090 (wave 32..32, SM 6.8), driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10. CI: `Build and test on Windows` passes on `9ec0c0a6`. There are no review threads. This reply was AI-assisted.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
R0Y00/Xbox2Windows!3071
No description provided.