Recompiler: basic blocks, post-dominators and control dependence (#336) #341
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!341
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/341/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@emirduran707 on GitHub · 2026-11-23 23:58 UTC · original
emirduran707:wave64-cfg→main· +336 −1 · 3 files · 1 commits · merged 2026-11-25 00:59 UTCPart of #336. Preparation for classifying wave64 VS / PS by whether their result depends on how a 32-lane GPU cuts their waves: that needs to know which blocks run because of a wave-wide vote. No behaviour change: nothing outside the tests calls it yet.
What is in it
gpu/recomp/cfg.rs(new):Cfg– a program's basic blocks built fromupper_lanes::successors, each block's immediate post-dominator (Cooper, Harvey and Kennedy's iteration on the reversed graph, one exit after every block that ends the program) and the branches it is control-dependent on (Ferrante, Ottenstein and Warren). A successor from which no path ends the program counts as the exit (so a branch into a loop with no way out decides both sides), and every block of such a region depends on the branch that leads into it. A program with an indirect jump gives no graph; a block from which no path ends the program has no post-dominator.gpu/recomp/upper_lanes.rs:successorsispub(super), unchanged otherwise.cfg.rs: an if, an if / else, a loop (control-dependent on its own branch), a loop with no way out, an indirect jump, and the two branches into a region with no way out from the review below (both fail without the fix).Tested
x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug for the suite, release for the runs.cargo test --workspace -- --test-threads=4atf7fd232: 683 passed, 0 failed, 41 ignored; noSKIPPEDlines.Regression run
The
gpu:line names a virtual display adapter of this machine (what #281 / #282 / #285 fix); XCL's log namesbackend 'real' – AMD Radeon RX 9060 XT (16188 MiB VRAM). Nothing in the runtime calls the new code, so this only shows the build is unchanged in use.main:
PR:
Not tested
AI use
@matheusfermiano-source on GitHub · 2026-11-24 00:06 UTC · original
Tested
Arch Linux x86-64, rustc 1.97.1, head
4e6156c9f9af533010a10956f6b5f6b49bff82a8. I used a standalonerustc --edition 2021 --testharness with the PR'scfg.rs,upper_lanes.rs, and RDNA decoder modules, plus the unchangedext_encoding()helper extracted fromemit.rs. This exercises the portable analysis in isolation.[Block(1), Exit, None, Exit, None], and control dependence was[[], [], [0], [], []]. Asserting dependence on branch 0 for both loop blocks fails at block 4 with the empty set. Both blocks execute only on the loop arm in this fixture. This is the case where the walk stops at the firstPostDom::None, despite the comment about blocks on paths that never exit.Not tested
Windows workspace build, DXC, GPU execution and retail titles. The shader-like input was hand-constructed for static analysis and was never executed.
AI use
Codex (GPT-6; exact variant unavailable) wrote the standalone test harness and this report.
@0xKaji on GitHub · 2026-11-24 00:13 UTC · original
Reviewed commit
4e6156cstatically on Linux (not built or executed on Windows; assisted by T3 Code + Gemini 4 Neon).Clean preparation PR overall, and the CHK
intersecttermination invariant holds on the exit-reachable subgraph. However, there are two concrete bugs when a branch has a successor that cannot reach any program exit (PostDom::None):post_dominators(crates/xcl/src/gpu/recomp/cfg.rs:142-147) skips non-exiting successors and produces false post-dominators (dropping real control dependences):if idom[p] == usize::MAX { continue; }conflates two cases: a reverse-reachable node not yet processed on the first pass (seen[p] == true, which must be skipped), and a node that can never reachexit(!seen[p]).!seen[p]causes a branch whose other arm exits to get that exiting successor as itsipdom, falsely implying every path from the branch goes through it.S_CMP_EQ_U32 s0, s1;S_CBRANCH_SCC0 +2→succ[0] = [2, 1]S_ADD_U32 s0, s0, 1;S_BRANCH -2(0xFFFE) →succ[1] = [1](infinite loop)S_ENDPGM→succ[2] = []post_dominators()returns[PostDom::Block(2), PostDom::None, PostDom::Exit], socontrol_dependencebreaks immediately onfirst = 2(PostDom::Block(2) == stop) and returnscd[2] == []— even though branch 0 decides whether block 2 executes at all.rpred(v)loop, treat!seen[p]asexit(i.e.let p = if !seen[p] { exit } else { p };) before checkingidom[p] == usize::MAX. That yieldsipdom[0] == PostDom::Exitandcd[2] == [0]while leaving normal loops (seen[p] == true) and purely non-exiting regions (!seen[v]) unchanged.control_dependence(crates/xcl/src/gpu/recomp/cfg.rs:165-166, 185-188) stops at the firstPostDom::Noneblock, contradicting its doc comment:match ipdom[run]breaks immediately onPostDom::None, only the immediate successorfirstof branchais recorded; blocks downstream offirstin the non-terminating region are never visited.S_CMP_EQ_U32 s0, s1;S_CBRANCH_SCC0 +3→succ[0] = [3, 1]S_MOV_B32 s2, 1→succ[1] = [2]S_ADD_U32 s0, s0, 1;S_BRANCH -2(0xFFFE) →succ[2] = [2]S_ENDPGM→succ[3] = []ipdom = [Exit, None, None, Exit]),control_dependencesetscd[1] = [0]and breaks, leavingcd[2] == []instead of[0].PostDom::Noneblock is itselfPostDom::None, whenipdom[run] == PostDom::Nonea forward DFS/worklist overself.succ(skipping blocks that already containaincd) will mark all downstream non-terminating blocks as documented.@PHeitor1 on GitHub · 2026-11-24 00:13 UTC · original
Tested
4e6156cmerged ontomain3516080.RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed, so the debug-layer tests run), rustc 1.100.0 MSVC, debug,
cargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*.Pass: 675 passed, 0 failed, 41 ignored. SKIPPED: only the 2
no wave64tests (gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware). Build clean.Run and written with Claude Code (Claude Opus 5.5).
@emirduran707 on GitHub · 2026-11-24 00:27 UTC · original
Thanks both – you were right, and it was the same gap: a successor from which no path ends the program. Fixed in
f7fd232(squashed, rebased ona6f5f7a):post_dominators: in the intersection, a successor that cannot reach the exit (!seen) counts as the exit, as @0xKaji suggested. A branch into a loop with no way out now getsPostDom::Exitinstead of its other side.control_dependence: on reaching aPostDom::Noneblock, every block reachable from it (none of them can end the program either) is marked as depending on the branch, as the doc comment said.a_branch_into_a_loop_with_no_way_out_decides_both_sides:[Exit, None, Exit]/[[], [0], [0]];every_block_of_a_side_with_no_way_out_depends_on_the_branch:[Exit, None, None, Exit]/[[], [0], [0], [0]]). Both fail with the old code (checked) and pass now. @matheusfermiano-source, your EXECZ loop fixture is the second shape; its loop blocks now get the dependence on branch 0.Suite at
f7fd232on an RX 9060 XT: 683 passed, 0 failed, 41 ignored, noSKIPPED; new smoke blocks are in the description. Thanks @PHeitor1 for the Blackwell run.AI use: Claude Code with Claude Opus 5.5 made the fix, ran these tests and wrote this reply.
@PHeitor1 on GitHub · 2026-11-24 00:31 UTC · original
Retested the new head
f7fd232merged ontomain2997c9a.RTX 5060 Ti 8 GB (Blackwell, 32-lane waves), NVIDIA 621.24, Ryzen 5 5600X, Windows 11 Pro 26300 (native, Graphics Tools + XGameRuntime installed), rustc 1.100.0 MSVC, debug,
cargo test --workspace --no-fail-fast -- --test-threads=4, noXCL_SAMPLE_*.Pass: 683 passed, 0 failed, 41 ignored (675 on
4e6156cearlier; the difference is the new tests here and onmain). SKIPPED: only the 2no wave64tests. Build clean.Run and written with Claude Code (Claude Opus 5.5).
@13hourstilliland on GitHub · 2026-11-24 01:35 UTC · original
Unit and full workspace run on Ampere 8 GB (RTX 3070) at exact PR head
f7fd232. Note: the new CFG analysis is only called by its unit tests here and does not change runtime GPU behavior yet.Tested
f7fd232a3bd4bfa35313cb124124727a12816008(PR #341 head), clean worktreestable-x86_64-pc-windows-gnu, not MSVC); DXC 1.9.2609.5 (01b62ad4) viaXCL_DXC_DIR; debug build; noXCL_SAMPLE_*setcargo test -p xcl --lib -- cfg:: --show-outputgpu::recomp::cfg::tests::*tests passed)cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output(interactive desktop session)xcllib: 643 passed, 0 failed, 21 ignored;e2e: 3/0)SKIPPED(4, not coverage):no wave64(2):gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardwareno D3D12 debug layer(2):test_title_draws_with_a_root_signature_under_the_debug_layer,uploads_start_from_each_subresources_stateNot tested
scripts/smoke.ps1, D3D12 debug-layer testsAI use
gemini-4-neon: ran the commands and wrote this report from the logs; the human reviewed it.@4MDomo on GitHub · 2026-11-24 01:53 UTC · original
NVIDIA test report for
f7fd232(this PR's head).Tested
stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); debug.cargo test --workspace -- --test-threads=4atf7fd232: 683 passed, 0 failed, 41 ignored.gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware. Same two skips onmain508a0c7(680 passed, 0 failed, 41 ignored).Not tested
AI use