Shaders/IR: pruned SSA via bitset IDF + dominator-tree renaming, linear CFG scan, and early dropped-inst skip #2955

Open
RVZO6 wants to merge 1 commit from upstream-pr/2957 into main
RVZO6 commented 2026-11-26 01:30:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T01:30:09Z.


Speed up victory_shader::ir::build across all shaders while producing structurally identical SSA output (crates/victory-shader/src/ir.rs):

  • Pruned SSA via parallel [u64; 7] bitset IDF + dominator-tree DFS renaming: propagate iterated dominance frontiers for all 385 registers simultaneously in bitset words, gate phi insertion by live_in, and rename in a single iterative dominator-tree DFS with an undo trail — eliminating maximal-SSA trivial phi creation, per-block outs Vec allocations, and binary-search lookup() calls.
  • Trim liveness() and fast-return in remove_trivial_phis_steps(): drop unused live_out computation from liveness() and skip extra passes when no phis exist or none are eliminated.
  • Linear CFG block assignment & early is_dropped() skip: assign basic blocks linearly in build_bounded() (dropping next_offsets and per-instruction leaders binary searches) and skip scheduling/waitcnt hints before machine.fields(wave64) via is_dropped().
  • Completely disjoint from #2664 (Exit::succs and effects() dedup).

Measured (--release, median of 3 runs)

  • bench_ir_build_cfg_and_ssa (102 basic blocks, 40 phis): 613.6 µs → 292.1 µs/run (2.10×, -52.4%)

Verification

  • Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + --tests + --features diagnostics clippy, xtask policy, full workspace tests): RVZO6/VIctory CI run #45734072839 (green, combined Wave 7 check on 63bcca4).
  • All 11 ir::tests pass, including pruned_ssa_matches_maximal_ssa_oracle (verifying structural equivalence against the maximal-SSA algorithm) and is_dropped_matches_dropped_names.
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6617438449 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2957). Originally posted by [RVZO6](https://github.com/RVZO6) on 2026-11-26T01:30:09Z. --- Speed up `victory_shader::ir::build` across all shaders while producing structurally identical SSA output (`crates/victory-shader/src/ir.rs`): - **Pruned SSA via parallel `[u64; 7]` bitset IDF + dominator-tree DFS renaming:** propagate iterated dominance frontiers for all 385 registers simultaneously in bitset words, gate phi insertion by `live_in`, and rename in a single iterative dominator-tree DFS with an undo trail — eliminating maximal-SSA trivial phi creation, per-block `outs` `Vec` allocations, and binary-search `lookup()` calls. - **Trim `liveness()` and fast-return in `remove_trivial_phis_steps()`:** drop unused `live_out` computation from `liveness()` and skip extra passes when no phis exist or none are eliminated. - **Linear CFG block assignment & early `is_dropped()` skip:** assign basic blocks linearly in `build_bounded()` (dropping `next_offsets` and per-instruction `leaders` binary searches) and skip scheduling/waitcnt hints before `machine.fields(wave64)` via `is_dropped()`. - Completely disjoint from #2664 (`Exit::succs` and `effects()` dedup). ### Measured (`--release`, median of 3 runs) - `bench_ir_build_cfg_and_ssa` (102 basic blocks, 40 phis): **613.6 µs → 292.1 µs/run (2.10×, -52.4%)** ### Verification - Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + `--tests` + `--features diagnostics` clippy, `xtask policy`, full workspace tests): [RVZO6/VIctory CI run #45734072839](https://github.com/RVZO6/VIctory/actions/runs/45734072839) (green, combined Wave 7 check on `63bcca4`). - All 11 `ir::tests` pass, including `pruned_ssa_matches_maximal_ssa_oracle` (verifying structural equivalence against the maximal-SSA algorithm) and `is_dropped_matches_dropped_names`. - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
fuzeofficlal commented 2026-11-26 02:06:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:55:44Z.

Review: COMMENTED


Reviewed and verified against main (63bcca43) on Windows 11 (RTX 5090 + WARP + dxil.dll) — clean, fast, and ready to merge:

  • build_pruned_ssa (crates/victory-shader/src/ir.rs:236-423) computes idoms/DF after split_irreducible, builds pruned phi shells via [u64; REGS.div_ceil(64)] bitset IDF filtered by live_in[y], and renames in a single explicit-stack dominator-tree pass with trail rollback.
  • Monotonic block scan and early is_dropped(encoding, opcode) skip avoid unnecessary machine.fields(wave64) work, and is_dropped_matches_dropped_names guards against opcode drift.
  • Zero changes to emit/lower.rs.

Local verification:

  • cargo test --locked -p victory-shader --lib: ir:: 11/11, structure:: 13/13, resource:: 35/35, emit::tests 17/17, emit::lower::tests 33/33 (including pruned_ssa_matches_maximal_ssa_oracle and is_dropped_matches_dropped_names)
  • emit::semantics_tests: 34/34 passed on both RTX 5090 and WARP
  • --release bench_ir_build_cfg_and_ssa: 179.3 us/run
  • cargo clippy (default & --all-features) + cargo xtask policy (191 files ok): 0 warnings
<!-- greyfinch-sync:Marvisak/VIctory:review:6067525081 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2957#pullrequestreview-6067525081). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:55:44Z. **Review:** COMMENTED --- Reviewed and verified against `main` (`63bcca43`) on Windows 11 (RTX 5090 + WARP + `dxil.dll`) — clean, fast, and ready to merge: - `build_pruned_ssa` (`crates/victory-shader/src/ir.rs:236-423`) computes idoms/DF after `split_irreducible`, builds pruned phi shells via `[u64; REGS.div_ceil(64)]` bitset IDF filtered by `live_in[y]`, and renames in a single explicit-stack dominator-tree pass with trail rollback. - Monotonic block scan and early `is_dropped(encoding, opcode)` skip avoid unnecessary `machine.fields(wave64)` work, and `is_dropped_matches_dropped_names` guards against opcode drift. - Zero changes to `emit/lower.rs`. **Local verification**: - `cargo test --locked -p victory-shader --lib`: `ir::` **11/11**, `structure::` **13/13**, `resource::` **35/35**, `emit::tests` **17/17**, `emit::lower::tests` **33/33** (including `pruned_ssa_matches_maximal_ssa_oracle` and `is_dropped_matches_dropped_names`) - `emit::semantics_tests`: **34/34 passed** on both **RTX 5090** and **WARP** - `--release` `bench_ir_build_cfg_and_ssa`: **`179.3 us/run`** - `cargo clippy` (default & `--all-features`) + `cargo xtask policy` (`191 files ok`): 0 warnings
kotekompotek commented 2026-11-26 03:04:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:34:32Z.

Review: COMMENTED


Verified: textbook pruned SSA. The parallel bitset IDF inserts phis only at df nodes where the reg is live-in (defs & live_in & !phi_regs), re-queueing on new bits — monotone so it terminates. Renaming is standard Cytron: phi values bound before reads, successor args filled at parent exit with current[], trail undo on Leave. The NONE-arg invariant holds because a reg live-in at a join is either defined on all reaching paths or lands in live_in[0] as an input. The is_dropped opcode table self-validates against DROPPED names via decode, and the linear leader scan replaces binary_search correctly since both lists are offset-sorted. The canonical oracle test comparing against maximal SSA on identical blocks is exactly the right check.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067797273 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2957#pullrequestreview-6067797273). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:34:32Z. **Review:** COMMENTED --- Verified: textbook pruned SSA. The parallel bitset IDF inserts phis only at df nodes where the reg is live-in (defs & live_in & !phi_regs), re-queueing on new bits — monotone so it terminates. Renaming is standard Cytron: phi values bound before reads, successor args filled at parent exit with current[], trail undo on Leave. The NONE-arg invariant holds because a reg live-in at a join is either defined on all reaching paths or lands in live_in[0] as an input. The is_dropped opcode table self-validates against DROPPED names via decode, and the linear leader scan replaces binary_search correctly since both lists are offset-sorted. The canonical oracle test comparing against maximal SSA on identical blocks is exactly the right check.
steven-seagull27 commented 2026-11-26 03:05:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T02:53:05Z.


@RVZO6 I compared this PR and #2942 individually and together through the public translate_with entry point, in light of the eight translation workers reported on #2936. Both commits start at 63bcca4, affect different compiler stages, and merge cleanly.

Median wall time in ms for one batch of 64 distinct compute containers on a Ryzen 7 9850X3D, Windows x64, Rust 1.98.1 MSVC, release build. Lower is faster.

Synthetic batch Workers Base #2957 dfa6126 #2942 1569277 Both
Indexed loads, dependent VALU and stores 1 299.2 307.5 263.3 256.4
Same 8 75.4 74.8 67.4 63.4
16 live VGPRs across successive control-flow joins 1 173.2 164.3 157.8 142.9
Same 8 42.2 40.8 36.4 35.5

The buffer batch varies program size and puts one dynamic diamond per eight loads in half of its shaders. The join batch has 4–130 diamonds; all 16 VGPRs feed the final store. The largest emits 2,080 DXIL phi instructions. Half the inputs in each batch enable view marks. Every timed call parses its compressed synthetic container, builds the IR, structures it, tracks resources and emits DXIL. Each row is 15 measurements across five processes with run order rotated and a warm-up outside the timer. The worker threads use the in-memory inputs directly; no shader cache, D3D pipeline creation, validator, file I/O or GPU dispatch is in the timer.

Correctness: I compared the actual DXIL bytes and the remaining HostShader binding metadata for all 128 inputs. All four builds matched, and the Windows SDK DXIL validator accepted every output on each build (512 validations). Output sizes were 2,512–99,264 bytes. The paired change reduced these eight-worker medians by 16% in both batches. #2942 showed the more consistent individual benefit. The small eight-worker difference between #2957 alone and base is within the spread of repeated runs.

Reproducible, test-only fixture 29c0e1b applies to the common base or either PR. From PowerShell:

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2957-translation-corpus
git cherry-pick 29c0e1b
$env:VICTORY_BENCH_WORKERS = '8'
foreach ($family in 'buffers','joins') {
    $env:VICTORY_BENCH_CORPUS = $family
    cargo test --release -p victory-shader --lib translate_public_compute_batch -- --ignored --nocapture
}

Set VICTORY_BENCH_OUTPUT to a separate directory for each build and batch to validate and save the binary outputs and binding metadata before timing. No title files were used; the eight-worker cold-cache run of the actual game remains the check for gameplay startup.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181203698 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2957#issuecomment-7181203698). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T02:53:05Z. --- @RVZO6 I compared this PR and #2942 individually and together through the public `translate_with` entry point, in light of the eight translation workers reported on #2936. Both commits start at `63bcca4`, affect different compiler stages, and merge cleanly. **Median wall time in ms for one batch of 64 distinct compute containers** on a Ryzen 7 9850X3D, Windows x64, Rust 1.98.1 MSVC, release build. Lower is faster. | Synthetic batch | Workers | Base | #2957 `dfa6126` | #2942 `1569277` | Both | |---|---:|---:|---:|---:|---:| | Indexed loads, dependent VALU and stores | 1 | 299.2 | 307.5 | 263.3 | 256.4 | | Same | 8 | 75.4 | 74.8 | 67.4 | 63.4 | | 16 live VGPRs across successive control-flow joins | 1 | 173.2 | 164.3 | 157.8 | 142.9 | | Same | 8 | 42.2 | 40.8 | 36.4 | 35.5 | The buffer batch varies program size and puts one dynamic diamond per eight loads in half of its shaders. The join batch has 4–130 diamonds; all 16 VGPRs feed the final store. The largest emits 2,080 DXIL phi instructions. Half the inputs in each batch enable view marks. Every timed call parses its compressed synthetic container, builds the IR, structures it, tracks resources and emits DXIL. Each row is 15 measurements across five processes with run order rotated and a warm-up outside the timer. The worker threads use the in-memory inputs directly; no shader cache, D3D pipeline creation, validator, file I/O or GPU dispatch is in the timer. **Correctness:** I compared the actual DXIL bytes and the remaining `HostShader` binding metadata for all 128 inputs. All four builds matched, and the Windows SDK DXIL validator accepted every output on each build (512 validations). Output sizes were 2,512–99,264 bytes. The paired change reduced these eight-worker medians by 16% in both batches. #2942 showed the more consistent individual benefit. The small eight-worker difference between #2957 alone and base is within the spread of repeated runs. [Reproducible, test-only fixture 29c0e1b](https://github.com/steven-seagull27/VIctory/commit/29c0e1b394d011bcfab31fe6b29cc93fda1bb5fe) applies to the common base or either PR. From PowerShell: ```powershell git fetch https://github.com/steven-seagull27/VIctory.git codex/pr2957-translation-corpus git cherry-pick 29c0e1b $env:VICTORY_BENCH_WORKERS = '8' foreach ($family in 'buffers','joins') { $env:VICTORY_BENCH_CORPUS = $family cargo test --release -p victory-shader --lib translate_public_compute_batch -- --ignored --nocapture } ``` Set `VICTORY_BENCH_OUTPUT` to a separate directory for each build and batch to validate and save the binary outputs and binding metadata before timing. No title files were used; the eight-worker cold-cache run of the actual game remains the check for gameplay startup.
Marvisak commented 2026-11-26 06:03:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T05:22:02Z.


Automated triage for the maintainers.

Needs work. This replaces the SSA construction in crates/victory-shader/src/ir.rs (build_pruned_ssa: dominance-frontier phi placement gated by live_in, dominator-tree renaming with an undo trail), scans leaders linearly in build_bounded, and skips dropped instructions before decoding fields. Reading it, the renaming and phi-argument filling look right, and pruned_ssa_matches_maximal_ssa_oracle compares against the old algorithm, but it rewrites the core of every shader's translation, so the bar is a measured benefit.

The 2.1x figure is for ir::build alone on one synthetic program. The end-to-end measurement in this thread (steven-seagull27, translate_with over 128 synthetic containers, byte-identical DXIL on all builds) found this PR alone inside run-to-run noise with 8 workers and slower in one 1-worker batch (299.2 -> 307.5 ms), while #2942 gave the more consistent gain. To move this forward: show a whole-title victory translate timing (cold cache, the worker count the loader uses) where this PR measurably helps on its own or on top of #2942, plus a program-by-program comparison showing identical output across the title's shaders. Without that, the risk of a core IR rewrite isn't matched by a demonstrated gain.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183421650 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2957#issuecomment-7183421650). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T05:22:02Z. --- <!-- victory-triage v1 head=dfa61265fa83dd7e418c07f7615792f556f27e91 verdict=needs-work at=2026-11-26T05:22:00Z --> Automated triage for the maintainers. **Needs work.** This replaces the SSA construction in `crates/victory-shader/src/ir.rs` (`build_pruned_ssa`: dominance-frontier phi placement gated by `live_in`, dominator-tree renaming with an undo trail), scans leaders linearly in `build_bounded`, and skips dropped instructions before decoding fields. Reading it, the renaming and phi-argument filling look right, and `pruned_ssa_matches_maximal_ssa_oracle` compares against the old algorithm, but it rewrites the core of every shader's translation, so the bar is a measured benefit. The 2.1x figure is for `ir::build` alone on one synthetic program. The end-to-end measurement in this thread (steven-seagull27, `translate_with` over 128 synthetic containers, byte-identical DXIL on all builds) found this PR alone inside run-to-run noise with 8 workers and slower in one 1-worker batch (299.2 -> 307.5 ms), while #2942 gave the more consistent gain. To move this forward: show a whole-title `victory translate` timing (cold cache, the worker count the loader uses) where this PR measurably helps on its own or on top of #2942, plus a program-by-program comparison showing identical output across the title's shaders. Without that, the risk of a core IR rewrite isn't matched by a demonstrated gain. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2957:upstream-pr/2957'
git switch 'upstream-pr/2957'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2957'
git switch 'upstream-pr/2957'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2957'
git switch 'upstream-pr/2957'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2957'
git switch 'main'
git merge --squash 'upstream-pr/2957'
git switch 'main'
git merge --ff-only 'upstream-pr/2957'
git switch 'main'
git merge 'upstream-pr/2957'
git push origin 'main'
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
Marvisak/VIctory!2955
No description provided.