Shaders/ir: exclude unreachable blocks from preds and multi_entry_loop #712

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

@⁠AscilCH on GitHub · 2026-11-25 05:20 UTC · original
AscilCH:fix/shader-ir-unreachable-preds-panic → main · +60 −4 · 1 files · 1 commits · open

Summary

Fixes a guaranteed SSA-construction panic when a shader contains unreachable blocks with edges into live blocks (crates/victory-shader/src/ir.rs):

  • link() previously added predecessors from all blocks in blocks, including blocks unreachable from entry block 0 (such as dead instructions between an unconditional s_branch and its target, dead code after s_endpgm, or blocks orphaned by CFG transforms).
  • rename() only computes outs[b] for blocks in reverse_postorder(&blocks). Any live block with an unreachable predecessor saw lookup(&outs[dead], reg) == NONE (Value(u32::MAX)), tripping debug_assert!(!phi.args.contains(&NONE)) / debug_assert_ne!(*v, NONE) in debug builds or causing an out-of-bounds panic in remove_trivial_phis() in release builds (and breaking entry block 0 inputs if an unreachable block targeted offset 0).
  • link() now computes reachability from block 0 via reverse_postorder, clears unreachable blocks (insts, phis, exit = Exit::End), and only populates preds from reachable blocks.
  • split_irreducible() now passes the reachable-block mask instead of vec![true; blocks.len()] to multi_entry_loop().

Verification

  • cargo test -p victory-shader --locked -- ir::tests: 9 passed, 0 failed (including 2 new regression tests for dead fallthrough into a live block and dead branch targeting entry block 0)
  • cargo test -p victory-shader --locked -- ir::tests structure::tests resource::tests emit::lower::tests: 67 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean (0 warnings)
  • cargo xtask policy: 169 files ok

(AI-assisted; synthetic unit tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-25 05:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/712) `AscilCH:fix/shader-ir-unreachable-preds-panic` → `main` · +60 −4 · 1 files · 1 commits · open ### Summary Fixes a guaranteed SSA-construction panic when a shader contains unreachable blocks with edges into live blocks (`crates/victory-shader/src/ir.rs`): - `link()` previously added predecessors from *all* blocks in `blocks`, including blocks unreachable from entry block `0` (such as dead instructions between an unconditional `s_branch` and its target, dead code after `s_endpgm`, or blocks orphaned by CFG transforms). - `rename()` only computes `outs[b]` for blocks in `reverse_postorder(&blocks)`. Any live block with an unreachable predecessor saw `lookup(&outs[dead], reg) == NONE` (`Value(u32::MAX)`), tripping `debug_assert!(!phi.args.contains(&NONE))` / `debug_assert_ne!(*v, NONE)` in debug builds or causing an out-of-bounds panic in `remove_trivial_phis()` in release builds (and breaking entry block `0` inputs if an unreachable block targeted offset `0`). - `link()` now computes reachability from block `0` via `reverse_postorder`, clears unreachable blocks (`insts`, `phis`, `exit = Exit::End`), and only populates `preds` from reachable blocks. - `split_irreducible()` now passes the reachable-block mask instead of `vec![true; blocks.len()]` to `multi_entry_loop()`. ### Verification - `cargo test -p victory-shader --locked -- ir::tests`: **9 passed, 0 failed** (including 2 new regression tests for dead fallthrough into a live block and dead branch targeting entry block `0`) - `cargo test -p victory-shader --locked -- ir::tests structure::tests resource::tests emit::lower::tests`: **67 passed, 0 failed, 1 ignored** - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean (0 warnings) - `cargo xtask policy`: `169 files ok` *(AI-assisted; synthetic unit tests only, no game data.)*
`link()` previously populated `Block::preds` from every block in `blocks`,
including blocks unreachable from entry block 0. When a dead block fell
through or jumped into a live block (or block 0), `rename()` only populated
`outs` for blocks in `reverse_postorder`, causing `lookup(&outs[dead], reg)`
to yield `NONE` (`Value(u32::MAX)`) — panicking in debug assertions or
indexing out of bounds in `remove_trivial_phis()`.

Compute reachability from block 0 in `link()`, clear unreachable blocks so
they cannot contribute edges or instructions, and pass the reachable mask
into `multi_entry_loop()` in `split_irreducible()`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:28 +00:00
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/712/head:github-bot/gh-712'
git switch 'github-bot/gh-712'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-712'
git switch 'github-bot/gh-712'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-712'
git switch 'github-bot/gh-712'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-712'
git switch 'main'
git merge --squash 'github-bot/gh-712'
git switch 'main'
git merge --ff-only 'github-bot/gh-712'
git switch 'main'
git merge 'github-bot/gh-712'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.