Shaders: walk a predecessor's live-out registers once instead of searching it per register #2520

Open
github-bot wants to merge 1 commit from github-bot/gh-2520 into main AGit
Owner

@⁠liandraraiane on GitHub · 2026-11-25 15:13 UTC · original
liandraraiane:perf/shader-translation-profiling → main · +80 −13 · 3 files · 1 commits · open

The IR's renaming looked up every live register in its predecessor's sorted live-out list by binary search, and again for every phi argument. Both sides are in register order, so one walk along the list
serves them all. The live-out lists are also sized before they are filled.

Change: crates/victory-shader/src/ir.rs (build_bounded), plus a new ir_build benchmark.

Measurement

cargo bench -p victory-shader --bench ir_build (synthetic programs, no title files or GPU), median of 9, release build:

Program main this PR
128 registers, 500 divergent ifs 10.5 ms 7.6 ms
128 registers, 2000 divergent ifs 47.2 ms 36.0 ms

With 8 registers the change is within noise.

Tests

  • cargo test -p victory-shader --lib: 144 passed, 2 ignored (Ubuntu 24.04).
  • The built IR (phis, predecessors, inputs, reads, writes) hashes the same as on main for the benchmark's programs.

Not tested

  • Real title shaders: I have none, so I cannot say how much of a whole translation this is. The gain only shows with many live registers and many blocks.
  • Windows, GPU runs and the Windows CI checks (clippy -D warnings, GPU tests).
  • Loops and irreducible flow in the equality check. Only the existing tests cover them.

AI use

Claude Code (Claude Sonnet 5.5) profiled, wrote the change and the benchmark, and drafted this description. A person reviewed it and opened the PR.

**@⁠liandraraiane** on GitHub · 2026-11-25 15:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2520) `liandraraiane:perf/shader-translation-profiling` → `main` · +80 −13 · 3 files · 1 commits · open The IR's renaming looked up every live register in its predecessor's sorted live-out list by binary search, and again for every phi argument. Both sides are in register order, so one walk along the list serves them all. The live-out lists are also sized before they are filled. Change: `crates/victory-shader/src/ir.rs` (`build_bounded`), plus a new `ir_build` benchmark. ## Measurement `cargo bench -p victory-shader --bench ir_build` (synthetic programs, no title files or GPU), median of 9, release build: | Program | main | this PR | |---|---|---| | 128 registers, 500 divergent ifs | 10.5 ms | 7.6 ms | | 128 registers, 2000 divergent ifs | 47.2 ms | 36.0 ms | With 8 registers the change is within noise. ## Tests - `cargo test -p victory-shader --lib`: 144 passed, 2 ignored (Ubuntu 24.04). - The built IR (phis, predecessors, inputs, reads, writes) hashes the same as on `main` for the benchmark's programs. ## Not tested - Real title shaders: I have none, so I cannot say how much of a whole translation this is. The gain only shows with many live registers and many blocks. - Windows, GPU runs and the Windows CI checks (`clippy -D warnings`, GPU tests). - Loops and irreducible flow in the equality check. Only the existing tests cover them. ## AI use Claude Code (Claude Sonnet 5.5) profiled, wrote the change and the benchmark, and drafted this description. A person reviewed it and opened the PR.
The IR's renaming looked up every live register in its predecessor's
sorted live-out list by binary search, and again for every phi argument.
Both sides are in register order, so one walk along the list serves them
all; the live-out lists are also sized before they are filled.

New ir_build benchmark (synthetic, no title files or GPU), median:
  128 registers, 500 divergent ifs:   10.5 ms -> 7.6 ms
  128 registers, 2000 divergent ifs:  47.2 ms -> 36.0 ms

The built IR hashes the same as on main for the benchmark's programs.
Tested on Ubuntu only (cargo test -p victory-shader --lib: 144 passed).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:06 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 15:27 UTC · original

Verification (Windows 11, WARP/CPU only) — head be6ae54e88af9a4dea8f94889469a803f0ca8a88

Tested: the PR head, which is origin/main 940d32f plus the PR commits (merge-base 940d32f; clean merge, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. VICTORY_WARP=1 and VICTORY_D3D12_WARP=1 set so nothing runs on a physical GPU.

command result
cargo test -p victory-shader --locked --lib -- --test-threads=1 245 passed, 2 failed, 3 ignored
cargo test -p victory-shader --locked --lib ir:: -- --test-threads=1 9 passed, 0 failed
cargo clippy -p victory-shader --all-targets --locked -- -D warnings clean (includes the new bench)
cargo xtask policy asset policy: 183 files ok
cargo bench -p victory-shader --locked --bench ir_build runs; medians below

The 2 failures are the WARP baseline: gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out fail identically on origin/main 940d32f under forced WARP (245 passed, 2 failed, 3 ignored there too; this PR adds no tests, so the counts match).

Bench (single run each on this machine, so only indicative; the PR's bench file copied onto origin/main for the "before" column), median of 9:

program main PR
8 regs, 500 ifs 4.93 ms 4.00 ms
64 regs, 500 ifs 9.47 ms 6.67 ms
128 regs, 500 ifs 12.94 ms 10.08 ms
8 regs, 2000 ifs 16.71 ms 15.26 ms
128 regs, 2000 ifs 55.03 ms 37.80 ms

Diff read: members() yields registers in 0..REGS order and Reg derives Ord in the same variant order the old binary_search_by_key relied on, so the forward walk in lookup_from is equivalent to the search (a register missing from outs leaves the cursor on the next larger entry and returns NONE, as before). Phis are only pushed in that one members loop, so they are in register order when the per-predecessor walk fills args; arg order still follows block.preds. The debug_assert was rewritten to the all-phis form with the same meaning. No findings. Coverage note: the change is only checked by the existing IR/emit tests (no new unit test pins the ordering assumption), which pass.

AI use: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 15:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2520#issuecomment-7166878631) **Verification (Windows 11, WARP/CPU only) — head `be6ae54e88af9a4dea8f94889469a803f0ca8a88`** Tested: the PR head, which is `origin/main` `940d32f` plus the PR commits (merge-base `940d32f`; clean merge, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1` set so nothing runs on a physical GPU. | command | result | |---|---| | `cargo test -p victory-shader --locked --lib -- --test-threads=1` | 245 passed, 2 failed, 3 ignored | | `cargo test -p victory-shader --locked --lib ir:: -- --test-threads=1` | 9 passed, 0 failed | | `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` | clean (includes the new bench) | | `cargo xtask policy` | `asset policy: 183 files ok` | | `cargo bench -p victory-shader --locked --bench ir_build` | runs; medians below | The 2 failures are the WARP baseline: `gathers_at_a_level_match_the_hardware` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out` fail identically on `origin/main` `940d32f` under forced WARP (245 passed, 2 failed, 3 ignored there too; this PR adds no tests, so the counts match). Bench (single run each on this machine, so only indicative; the PR's bench file copied onto `origin/main` for the "before" column), median of 9: | program | main | PR | |---|---|---| | 8 regs, 500 ifs | 4.93 ms | 4.00 ms | | 64 regs, 500 ifs | 9.47 ms | 6.67 ms | | 128 regs, 500 ifs | 12.94 ms | 10.08 ms | | 8 regs, 2000 ifs | 16.71 ms | 15.26 ms | | 128 regs, 2000 ifs | 55.03 ms | 37.80 ms | Diff read: `members()` yields registers in `0..REGS` order and `Reg` derives `Ord` in the same variant order the old `binary_search_by_key` relied on, so the forward walk in `lookup_from` is equivalent to the search (a register missing from `outs` leaves the cursor on the next larger entry and returns `NONE`, as before). Phis are only pushed in that one `members` loop, so they are in register order when the per-predecessor walk fills `args`; arg order still follows `block.preds`. The `debug_assert` was rewritten to the all-phis form with the same meaning. No findings. Coverage note: the change is only checked by the existing IR/emit tests (no new unit test pins the ordering assumption), which pass. AI use: Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:32 UTC · original

Automated triage for the maintainers.

In build_bounded (crates/victory-shader/src/ir.rs), the per-register binary search in a predecessor's live-out list becomes one forward walk (lookup_from). This applies to single-predecessor blocks and to phi arguments, and the walk restarts for each predecessor. I checked the ordering it relies on: outs is built by members in index order, the live-in registers and the phis (pushed only in that members loop) come in the same order, and a missing register returns NONE as before. The ir_build bench target is synthetic and adds no dependency.

The speed-up is measured on synthetic programs only (about 25 % with 128 live registers). The gain on real translations is not measured.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2520#issuecomment-7171041531) <!-- victory-triage v1 head=be6ae54e88af9a4dea8f94889469a803f0ca8a88 verdict=merge-candidate at=2026-11-25T18:32:01Z --> Automated triage for the maintainers. In `build_bounded` (`crates/victory-shader/src/ir.rs`), the per-register binary search in a predecessor's live-out list becomes one forward walk (`lookup_from`). This applies to single-predecessor blocks and to phi arguments, and the walk restarts for each predecessor. I checked the ordering it relies on: `outs` is built by `members` in index order, the live-in registers and the phis (pushed only in that `members` loop) come in the same order, and a missing register returns `NONE` as before. The `ir_build` bench target is synthetic and adds no dependency. The speed-up is measured on synthetic programs only (about 25 % with 128 live registers). The gain on real translations is not measured. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠rezioliver-collab on GitHub · 2026-11-25 21:03 UTC · original

On an Apple M1, the full IR dump matched byte for byte between 940d32f (base) and be6ae54e (PR) for both loop shapes in Wave32 and Wave64, including the order of every phi argument.

Synthetic GFX10 shader IR blocks Phi nodes Wave32 Wave64
Single-entry loop with a back edge 3 2 Identical (15,848 bytes) Identical (16,225 bytes)
Two-entry loop, after node splitting 5 4 Identical (32,386 bytes) Identical (32,766 bytes)

I built each commit separately on macOS 14.7 with native Rust 1.98.1 (dev profile). I passed the same synthetic instruction words to ir::build with 16 VGPRs at each wave size, then compared the complete Program debug dumps directly, preserving block, predecessor and operand order.

Both fixtures carry s2 and s9 through the loop. For each phi, I also checked that each argument was the value last written to that register by the corresponding predecessor. For example, in block 2 of the two-entry Wave32 case, predecessors [0, 1, 4] supplied s2 SSA value IDs [4, 22, 7] in that order on both commits.

**@⁠rezioliver-collab** on GitHub · 2026-11-25 21:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2520#issuecomment-7174555560) On an Apple M1, the full IR dump matched byte for byte between `940d32f` (base) and `be6ae54e` (PR) for both loop shapes in Wave32 and Wave64, including the order of every phi argument. | Synthetic GFX10 shader | IR blocks | Phi nodes | Wave32 | Wave64 | |---|---:|---:|---|---| | Single-entry loop with a back edge | 3 | 2 | Identical (15,848 bytes) | Identical (16,225 bytes) | | Two-entry loop, after node splitting | 5 | 4 | Identical (32,386 bytes) | Identical (32,766 bytes) | I built each commit separately on macOS 14.7 with native Rust 1.98.1 (dev profile). I passed the same synthetic instruction words to `ir::build` with 16 VGPRs at each wave size, then compared the complete `Program` debug dumps directly, preserving block, predecessor and operand order. Both fixtures carry `s2` and `s9` through the loop. For each phi, I also checked that each argument was the value last written to that register by the corresponding predecessor. For example, in block 2 of the two-entry Wave32 case, predecessors `[0, 1, 4]` supplied `s2` SSA value IDs `[4, 22, 7]` in that order on both commits.
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/2520/head:github-bot/gh-2520'
git switch 'github-bot/gh-2520'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2520'
git switch 'github-bot/gh-2520'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2520'
git switch 'github-bot/gh-2520'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2520'
git switch 'main'
git merge --squash 'github-bot/gh-2520'
git switch 'main'
git merge --ff-only 'github-bot/gh-2520'
git switch 'main'
git merge 'github-bot/gh-2520'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2520
No description provided.