Shaders: a folded empty block keeps one phi entry per predecessor (#2621) #2692

Closed
github-bot wants to merge 1 commit from gh-pr/2692/head into gh-pr/2692/base
Owner

@⁠Calvix2k on GitHub · 2026-11-25 18:18 UTC · original
Calvix2k:codex/shader-folded-phi-entry → main · +71 −1 · 1 files · 1 commits · closed without merging

Fixes #2621.

Since 286a00e the writer takes a constant branch's one edge, drops phi entries of edges that are gone, and folds an empty block with one predecessor into it. Plan::edge kept an entry from b when any of b's successors, through folded targets, landed in the phi's block. After entry: CondBr(true, empty, join) folds empty into entry -> join, the folded block's own entry stays (written from entry), but the untaken direct edge entry -> join was still counted: the phi got two entries for its one predecessor, which the validator and drivers reject.

A successor folded from b is the edge b itself leaves on and no longer counts as another way into the phi: the folded block's entry is the one that stays, written from src(b). A successor that was not folded is an edge of its own, even when it is b itself: a self-looping header keeps its back-edge entry (found by the synthetic tests, whose validator rejected the first version of this change).

The first test is the issue's entry/empty/join shape: the phi keeps the entry from empty (written from entry) and loses the direct one; it fails on the old Plan::edge at the second assertion. The second keeps a self-loop's back edge.

Tests: cargo test -p victory-shader --lib emit::bitcode:: passes (14). With the test-binaries' Agility opt-in (#486) merged locally, the full cargo test -p victory-shader --lib --locked also passes on an AMD Radeon RX 7800 XT (Windows 10 19045, driver 32.0.32029.2010): 272 passed, 0 failed, 3 ignored, with the synthetic and waterfall modules validating on hardware. Clippy clean.

**@⁠Calvix2k** on GitHub · 2026-11-25 18:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2692) `Calvix2k:codex/shader-folded-phi-entry` → `main` · +71 −1 · 1 files · 1 commits · closed without merging Fixes #2621. Since 286a00e the writer takes a constant branch's one edge, drops phi entries of edges that are gone, and folds an empty block with one predecessor into it. `Plan::edge` kept an entry from `b` when any of `b`'s successors, through folded targets, landed in the phi's block. After `entry: CondBr(true, empty, join)` folds `empty` into `entry -> join`, the folded block's own entry stays (written from `entry`), but the untaken direct edge `entry -> join` was still counted: the phi got two entries for its one predecessor, which the validator and drivers reject. A successor folded from `b` is the edge `b` itself leaves on and no longer counts as another way into the phi: the folded block's entry is the one that stays, written from `src(b)`. A successor that was not folded is an edge of its own, even when it is `b` itself: a self-looping header keeps its back-edge entry (found by the synthetic tests, whose validator rejected the first version of this change). The first test is the issue's `entry/empty/join` shape: the phi keeps the entry from `empty` (written from `entry`) and loses the direct one; it fails on the old `Plan::edge` at the second assertion. The second keeps a self-loop's back edge. Tests: `cargo test -p victory-shader --lib emit::bitcode::` passes (14). With the test-binaries' Agility opt-in (#486) merged locally, the full `cargo test -p victory-shader --lib --locked` also passes on an AMD Radeon RX 7800 XT (Windows 10 19045, driver 32.0.32029.2010): **272 passed, 0 failed, 3 ignored**, with the synthetic and waterfall modules validating on hardware. Clippy clean.
Since 286a00e the writer takes a constant branch's one edge, drops phi
entries of edges that are gone, and folds an empty block with one
predecessor into it. `Plan::edge` kept an entry from `b` when any of `b`'s
successors, through folded targets, landed in the phi's block. After
`entry: CondBr(true, empty, join)` folds `empty` into `entry -> join`, the
folded block's own entry stays (written from `entry`), but the untaken
direct edge `entry -> join` was still counted: the phi got two entries for
its one predecessor, which the validator and drivers reject.

A successor folded from `b` is the edge `b` itself leaves on and no longer
counts as another way into the phi: the folded block's entry is the one
that stays, written from `src(b)`. A successor that was not folded is an
edge of its own, even when it is `b` itself: a self-looping header keeps
its back-edge entry (found by the synthetic tests, whose validator rejected
the first version of this change).

The first test is the issue's `entry/empty/join` shape: the phi keeps the
entry from `empty` (written from `entry`) and loses the direct one; it
fails on the old `Plan::edge` at the second assertion. The second keeps a
self-loop's back edge. `cargo test -p victory-shader --lib emit::bitcode::`
passes (14), the synthetic and waterfall suites validate, and clippy is
clean; the other suites need an SM 6.6 device this Windows 10 host lacks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:09 +00:00
github-bot closed this pull request 2026-11-26 05:12:09 +00:00
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 18:34 UTC · original

Consolidating on #2622, which is earlier, green and simpler: successors(m.term(b)).contains(&x) covers the same cases without the src comparison (a folded block's own terminator still has x as its successor, and an untaken constant-branch edge does not). I verified the validator/WARP point too; nothing in #2622 conflicts with the self-loop case.

The one thing worth carrying there is a_self_looping_header_keeps_its_back_edge, since that is the case a first, more eager folded-successor check broke (it dropped a header's own back edge and the validator rejected the phi). It passes on the base as well, so it is a guard rather than a regression test, but it is cheap:

let (mut m, b, sink) = module(3);
let [entry, head, exit] = b[..] else { unreachable!() };
let i32t = m.int(32);
let (zero, one, ten) = (m.i32(0), m.i32(1), m.i32(10));
m.terminate(entry, Term::Br(head));
let i = m.phi(head, i32t);
let next = m.bin(head, Bin::Add, i, one);
let more = m.cmp(head, pred::SLT, next, ten);
m.terminate(head, Term::CondBr(more, head, exit));
m.set_phi(i, vec![(zero, entry), (next, head)]);
let _ = m.call(exit, sink, vec![i]);
m.terminate(exit, Term::Ret);
let plan = m.plan();
assert!(plan.edge(&m, entry, head) && plan.edge(&m, head, head));
let _ = m.write();

Closing this one in favour of #2622 so the queue has one fix per issue. Happy to send the test as a separate PR if you would rather not touch #2622.

**@⁠Calvix2k** on GitHub · 2026-11-25 18:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2692#issuecomment-7171098378) Consolidating on #2622, which is earlier, green and simpler: `successors(m.term(b)).contains(&x)` covers the same cases without the `src` comparison (a folded block's own terminator still has `x` as its successor, and an untaken constant-branch edge does not). I verified the validator/WARP point too; nothing in #2622 conflicts with the self-loop case. The one thing worth carrying there is `a_self_looping_header_keeps_its_back_edge`, since that is the case a first, more eager folded-successor check broke (it dropped a header's own back edge and the validator rejected the phi). It passes on the base as well, so it is a guard rather than a regression test, but it is cheap: ```rust let (mut m, b, sink) = module(3); let [entry, head, exit] = b[..] else { unreachable!() }; let i32t = m.int(32); let (zero, one, ten) = (m.i32(0), m.i32(1), m.i32(10)); m.terminate(entry, Term::Br(head)); let i = m.phi(head, i32t); let next = m.bin(head, Bin::Add, i, one); let more = m.cmp(head, pred::SLT, next, ten); m.terminate(head, Term::CondBr(more, head, exit)); m.set_phi(i, vec![(zero, entry), (next, head)]); let _ = m.call(exit, sink, vec![i]); m.terminate(exit, Term::Ret); let plan = m.plan(); assert!(plan.edge(&m, entry, head) && plan.edge(&m, head, head)); let _ = m.write(); ``` Closing this one in favour of #2622 so the queue has one fix per issue. Happy to send the test as a separate PR if you would rather not touch #2622.

Pull request closed

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!2692
No description provided.