shader: coalesce single-pred blocks and fold dead diamonds in DXIL opt #2623

Merged
nidea1 merged 1 commit from upstream-pr/2623 into main 2026-11-30 14:12:02 +00:00
nidea1 commented 2026-11-29 15:04:32 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nidea1 on 2026-11-29T15:04:32Z.


Summary

Adds simplify_cfg() to the DXIL module optimizer (crates/victory-shader/src/emit/bitcode/opt.rs, gated under FOLD alongside prune() and mid-loop drop_dead_insts() when DEAD is enabled):

  1. Same-target conditional branch folding: folds CondBr(_, t, t) -> Br(t) whenever all phis in t agree for that predecessor.
  2. Single-predecessor block coalescing: merges a -> Br(b) chains when b has only predecessor a (resolving single-entry phis with a degenerate phi-cycle guard and remapping successor phi incoming block IDs).
  3. Empty trampoline threading: threads empty phi-free trampoline blocks (e: Br(t)) into phi-free targets t, collapsing dead if/else diamonds into straight-line blocks and unlocking cross-block LOADS reuse/DSE and BARRIERS coalescing on subsequent rounds.

Verification

  • cargo test -p victory-shader --lib: 462 passed, 0 failed (27/27 opt::tests::, including randomized differential oracle, RTX 3060 Ti DXIL parity, and new CFG coalescing / diamond / phi-remap tests).
  • cargo clippy -p victory-shader --tests: 0 warnings in opt.rs.
  • cargo xtask policy --staged: passed.
  • Corpus benchmark across top 10 largest Wave64-folded compute shaders (RTX 3060 Ti host settings):
    • Total DXIL basic blocks: 41,896 → 33,885 (-19.1%, -8,011 blocks; largest ~1.8 MB folded compute shader dropped 8,548 → 6,992 blocks, -18.2%).
    • Total DXIL bytes: 8,453,912 → 8,412,904 B (-41 KB across top 10; up to -5.4% on branch-heavy folded compute shaders).
  • Full corpus translation & pipeline validation on RTX 3060 Ti: 2,720 / 2,720 used pipelines compiled cleanly with 0 failures and verified in live gameplay.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5551980473 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2623). Originally posted by [nidea1](https://github.com/nidea1) on 2026-11-29T15:04:32Z. --- ## Summary Adds `simplify_cfg()` to the DXIL module optimizer (`crates/victory-shader/src/emit/bitcode/opt.rs`, gated under `FOLD` alongside `prune()` and mid-loop `drop_dead_insts()` when `DEAD` is enabled): 1. **Same-target conditional branch folding**: folds `CondBr(_, t, t) -> Br(t)` whenever all phis in `t` agree for that predecessor. 2. **Single-predecessor block coalescing**: merges `a -> Br(b)` chains when `b` has only predecessor `a` (resolving single-entry phis with a degenerate phi-cycle guard and remapping successor phi incoming block IDs). 3. **Empty trampoline threading**: threads empty phi-free trampoline blocks (`e: Br(t)`) into phi-free targets `t`, collapsing dead `if/else` diamonds into straight-line blocks and unlocking cross-block `LOADS` reuse/DSE and `BARRIERS` coalescing on subsequent rounds. ## Verification - `cargo test -p victory-shader --lib`: 462 passed, 0 failed (27/27 `opt::tests::`, including randomized differential oracle, RTX 3060 Ti DXIL parity, and new CFG coalescing / diamond / phi-remap tests). - `cargo clippy -p victory-shader --tests`: 0 warnings in `opt.rs`. - `cargo xtask policy --staged`: passed. - Corpus benchmark across top 10 largest Wave64-folded compute shaders (RTX 3060 Ti host settings): - Total DXIL basic blocks: **41,896 → 33,885** (**-19.1%**, -8,011 blocks; largest ~1.8 MB folded compute shader dropped **8,548 → 6,992** blocks, -18.2%). - Total DXIL bytes: **8,453,912 → 8,412,904 B** (-41 KB across top 10; up to -5.4% on branch-heavy folded compute shaders). - Full corpus translation & pipeline validation on RTX 3060 Ti: 2,720 / 2,720 used pipelines compiled cleanly with 0 failures and verified in live gameplay.
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
trustno1-coder/VIctory-NVIDIA!2623
No description provided.