shader: lower a forward s_cbranch_scc0/scc1 skip over vector ALU in pixel_aot #1433

Merged
MasterDomino merged 1 commit from upstream-pr/1440 into main 2026-11-24 11:41:55 +00:00
MasterDomino commented 2026-11-24 11:33:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T11:33:24Z.


Refs #1413 (stage 1)

pixel_aot now lowers one forward s_cbranch_scc0/s_cbranch_scc1 on a tracked scalar compare that skips a block of per-lane vector ALU. This follows the scope R0Y00 approved on #1413.

Behaviour (tools/pixel_aot.py)

  • Condition: SCC must be the result of a tracked scalar compare, i.e. a named scc<N> from s_cmp_* or s_bitcmp*. An SCC that comes from an ALU result (s_and_b32, s_add_u32, …) or is untracked rejects with Uniform branch requires a tracked scalar compare.
  • Target: must be a later instruction boundary, checked on real (offset, text) input. Plain strings, a backward or self target, and a target outside the program reject.
  • Block: opens at the branch and closes at the target, before the target instruction runs and is checked. It admits only the per-lane vector ALU that masked regions admit (REGION_ALU) and s_nop. Memory, sampling, exports, waits, EXEC writes, scalar and wave updates, nested branches and regions reject with Instruction cannot run in a uniform skip block. A branch inside a masked region is refused by the region gate. Wave64 entry mask only.
  • Merge: SCC is a wave value, so each VGPR the block writes merges with a select on the condition under which the block runs: scc for s_cbranch_scc0, !scc for s_cbranch_scc1. This reuses the masked-region close_region merge and definedness: a VGPR first written in the block is undefined afterwards, including at the target, until an unconditional write defines it.
  • SCC and VCC: the block writes no scalar state, so both keep their tracked values after it.

Tests

  • check_scc_skip_controls (runs in tests/pixel_aot_check.py with no arguments):
    • the select condition for both polarities, and that the instruction after the target reads the merged value;
    • an untracked SCC from ALU results refused; s_bitcmp1_b32 accepted;
    • plain strings, targets -1, -3 and 400 refused;
    • nine block contents refused, each with its message: image_sample, s_buffer_load_dword, s_mov_b32, s_cmp, an EXEC copy, s_and_saveexec_b64, s_waitcnt, exp, v_readfirstlane_b32;
    • a nested s_cbranch_scc1 refused, and the branch inside a masked region refused;
    • undefined-after-block refused, at the target and later; accepted after a redefinition;
    • an SCC reader after the block, and an empty block, accepted.
  • check_scc_skip_draw, new mode draw-scc-skip, new CTests pixel_aot_scc_skip_{warp,hardware}:
    • Forms: s_cmp_eq_u32 s47, 0 + s_cbranch_scc1, and s_cmp_lg_u32 s47, 0 + s_cbranch_scc0.
    • The runtime flag in constant word 6 is set to 0 (skipped), 1 and 7 (taken), so both directions are drawn from one shader. The block writes v13/v14, and v_mul_f32 v15, 0.5, v14 after the target reads the merged v14.
    • Mutants that must mismatch: the opposite polarity (flags 0 and 1), and the branch dropped (flag 0).
  • LLVM 15 binary regression: both programs with a labelled target.
  • tests/form_coverage_check.py: s_cbranch_scc0/scc1 move from the must-stay-rejected list to an asserted covered set. That list existed because nothing accepted them before.

Results

Rebased on 92bd3362. Windows 11 26H2 (build 26300.9974), dev preset, DXC 1.8.2502.11, Python 3.13.1, LLVM 15.0.7.

python -B tests/pixel_aot_check.py                                   # controls: pass
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll>   # pass
ctest --preset dev --no-tests=error -R '^pixel_aot_(scc_skip|exec_regions|cmpx_regions|region_.*)_(warp|hardware)$'   # 14/14 pass
backend cases (2 forms × flag 0/1/7) mutant cases
WARP 10.0.26100.9818 6/6 match, 64/64 pixels each 6/6 mismatch
AMD Radeon RX 9070 XT, driver 32.0.31044.16 6/6 6/6 mismatch

All 37 pure-Python checks listed in AGENTS.md pass.

Negative control: with tools/pixel_aot.py restored to main, check_scc_skip_controls fails with Unsupported instruction 21: s_cbranch_scc1 2.

Not measured

The shape counts on #1413 are layout only: 27,361 skip branches in 8,423 records. The scan's translator verdict still stops at unbound operands under the scanned inputs (#1314), so the number of records this unblocks is not measured. The draws pin the translator's model on desktop adapters; they are not evidence for gfx1013 hardware.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6580827560 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1440). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T11:33:24Z. --- Refs #1413 (stage 1) `pixel_aot` now lowers one forward `s_cbranch_scc0`/`s_cbranch_scc1` on a tracked scalar compare that skips a block of per-lane vector ALU. This follows the scope R0Y00 approved on #1413. ## Behaviour (`tools/pixel_aot.py`) - **Condition:** SCC must be the result of a tracked scalar compare, i.e. a named `scc<N>` from `s_cmp_*` or `s_bitcmp*`. An SCC that comes from an ALU result (`s_and_b32`, `s_add_u32`, …) or is untracked rejects with `Uniform branch requires a tracked scalar compare`. - **Target:** must be a later instruction boundary, checked on real `(offset, text)` input. Plain strings, a backward or self target, and a target outside the program reject. - **Block:** opens at the branch and closes at the target, before the target instruction runs and is checked. It admits only the per-lane vector ALU that masked regions admit (`REGION_ALU`) and `s_nop`. Memory, sampling, exports, waits, EXEC writes, scalar and wave updates, nested branches and regions reject with `Instruction cannot run in a uniform skip block`. A branch inside a masked region is refused by the region gate. Wave64 entry mask only. - **Merge:** SCC is a wave value, so each VGPR the block writes merges with a select on the condition under which the block runs: `scc` for `s_cbranch_scc0`, `!scc` for `s_cbranch_scc1`. This reuses the masked-region `close_region` merge and definedness: a VGPR first written in the block is undefined afterwards, including at the target, until an unconditional write defines it. - **SCC and VCC:** the block writes no scalar state, so both keep their tracked values after it. ## Tests - **`check_scc_skip_controls`** (runs in `tests/pixel_aot_check.py` with no arguments): - the select condition for both polarities, and that the instruction after the target reads the merged value; - an untracked SCC from ALU results refused; `s_bitcmp1_b32` accepted; - plain strings, targets `-1`, `-3` and `400` refused; - nine block contents refused, each with its message: `image_sample`, `s_buffer_load_dword`, `s_mov_b32`, `s_cmp`, an EXEC copy, `s_and_saveexec_b64`, `s_waitcnt`, `exp`, `v_readfirstlane_b32`; - a nested `s_cbranch_scc1` refused, and the branch inside a masked region refused; - undefined-after-block refused, at the target and later; accepted after a redefinition; - an SCC reader after the block, and an empty block, accepted. - **`check_scc_skip_draw`**, new mode `draw-scc-skip`, new CTests `pixel_aot_scc_skip_{warp,hardware}`: - Forms: `s_cmp_eq_u32 s47, 0` + `s_cbranch_scc1`, and `s_cmp_lg_u32 s47, 0` + `s_cbranch_scc0`. - The runtime flag in constant word 6 is set to 0 (skipped), 1 and 7 (taken), so both directions are drawn from one shader. The block writes v13/v14, and `v_mul_f32 v15, 0.5, v14` after the target reads the merged v14. - Mutants that must mismatch: the opposite polarity (flags 0 and 1), and the branch dropped (flag 0). - **LLVM 15 binary regression:** both programs with a labelled target. - **`tests/form_coverage_check.py`:** `s_cbranch_scc0`/`scc1` move from the must-stay-rejected list to an asserted covered set. That list existed because nothing accepted them before. ## Results Rebased on `92bd3362`. Windows 11 26H2 (build 26300.9974), `dev` preset, DXC 1.8.2502.11, Python 3.13.1, LLVM 15.0.7. ``` python -B tests/pixel_aot_check.py # controls: pass python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <LLVM-C.dll> # pass ctest --preset dev --no-tests=error -R '^pixel_aot_(scc_skip|exec_regions|cmpx_regions|region_.*)_(warp|hardware)$' # 14/14 pass ``` | backend | cases (2 forms × flag 0/1/7) | mutant cases | |---|---|---| | WARP 10.0.26100.9818 | 6/6 match, 64/64 pixels each | 6/6 mismatch | | AMD Radeon RX 9070 XT, driver 32.0.31044.16 | 6/6 | 6/6 mismatch | All 37 pure-Python checks listed in `AGENTS.md` pass. **Negative control:** with `tools/pixel_aot.py` restored to main, `check_scc_skip_controls` fails with `Unsupported instruction 21: s_cbranch_scc1 2`. ## Not measured The shape counts on #1413 are layout only: 27,361 skip branches in 8,423 records. The scan's translator verdict still stops at unbound operands under the scanned inputs (#1314), so the number of records this unblocks is not measured. The draws pin the translator's model on desktop adapters; they are not evidence for gfx1013 hardware. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 12:03:02 +00:00
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!1433
No description provided.