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

Open
AscilCH wants to merge 1 commit from upstream-pr/712 into main
AscilCH commented 2026-11-25 05:20:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T05:20:37Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6597794495 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/712). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T05:20:37Z. --- ### 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.)*
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/712:upstream-pr/712'
git switch 'upstream-pr/712'

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/712'
git switch 'upstream-pr/712'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/712'
git switch 'upstream-pr/712'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/712'
git switch 'main'
git merge --squash 'upstream-pr/712'
git switch 'main'
git merge --ff-only 'upstream-pr/712'
git switch 'main'
git merge 'upstream-pr/712'
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
fxceless/victory-fork!712
No description provided.