Recompiler: eliminate BTree/Vec allocations and skip dominator pass on acyclic CFGs in direct DXIL cfg #2642

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

@⁠Decodere on GitHub · 2026-11-26 04:49 UTC · original
Decodere:fix-dxil-cfg-zero-alloc-and-dag-fastpath → main · +147 −31 · 1 files · 1 commits · open

What is in it

Eliminates redundant BTreeMap/BTreeSet/Vec heap allocations and skips the dominator pass on acyclic CFGs during direct DXIL CFG construction (crates/xcl/src/gpu/dxil/cfg.rs):

  • Drop BTreeMap/BTreeSet tables in Cfg::build_with: Replaced index: BTreeMap<u64, usize> with insts.binary_search_by_key(&pc, |d| d.pc) over monotonically decoded instruction PCs, replaced leaders: BTreeSet<usize> and block_of: BTreeMap<usize, usize> with flat is_leader: Vec<bool>, starts: Vec<usize>, and block_of: Vec<usize> (with empty-input and i + 1 < is_leader.len() bounds guards), removed the unused reach: BTreeSet<usize>, and pre-sized blocks, per-block list, post, and order's DFS stack.
  • Zero-allocation successor iteration (Succs): Replaced succ_of(&CfgBlock) -> Vec<usize> with a Copy stack-allocated Succs { buf: [usize; 2], len: usize } (as_slice() + IntoIterator) and borrowed &preds[x] instead of preds[x].clone() in make_reducible_inner's reach closure.
  • Skip dominator computation on acyclic CFGs: Extracted make_reducible_inner returning (post, headers, dom_passes) and short-circuited if headers.is_empty() { return Ok((post, headers, dom_passes)); } before calling irreducible_edge, avoiding pos/preds/idom allocation and Cooper–Harvey–Kennedy dominator iteration on DAG shaders where DFS found no back edges.

Part of #2508
Part of #1833

Tested

  • Failing-first verification against pre-fix make_reducible_inner semantics (cargo test --release -p xcl --lib "gpu::dxil::cfg::tests::" -- --test-threads=1 --nocapture): 1 passed; 1 failed; 0 ignored — acyclic_cfg_skips_dominator_pass_and_matches_rpo_and_preds failed with left: 1, right: 0 (irreducible_edge ran on an acyclic diamond DAG).
  • Post-fix WARP targeted tests (XCL_ADAPTER=warp, XCL_WARP=1, cargo test --release -p xcl --lib "gpu::dxil::cfg::tests::" -- --test-threads=1 --nocapture): 4 passed; 0 failed; 0 ignored; 0 skipped (0.00s; zero warnings in cfg.rs).
  • Post-fix RTX 4060 targeted DXIL suite (cargo test --release -p xcl --lib "gpu::dxil::" -- --test-threads=1 --nocapture): 187 passed; 0 failed; 3 ignored (9.05s, gpu::dxil::cfg::tests:: 4/0/0, 0 skipped; 1 pre-existing SKIPPED: gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole: no wave64).

Regression run

  • Full release workspace on RTX 4060 (cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture): 37 test binaries, 1438 passed; 0 failed; 47 ignored, 29 pre-existing environment-gated SKIPPED lines:

    • 21 skipped: no wave64 (RTX 4060 is wave32)
    • 3 skipped: wave32 per-lane form: refused by driver (f16 arithmetic, f16 packed, f32 conversions)
    • 3 skipped: no D3D12 debug layer (d3d12SDKLayers.dll unavailable on host: debug-layer dred: false/true and uploads_start_from_each_subresources_state)
    • 1 skipped: pso_measurement_compiles_an_exact_synthetic_record (cannot disable driver cache on Windows)
    • 1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
  • Paired 60 s RTX 4060 smoke capture (scripts/smoke.ps1):

Base (origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1576 (PresentX 1576)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13981 MB

PR (742116a9338ffd6c53819dabc636710576a0f74e):

xcl-smoke v1
commit: 742116a9338ffd6c53819dabc636710576a0f74e
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1529 (PresentX 1529)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13974 MB

Not tested

  • Direct wall-clock shader-translation microbenchmarks over a full cold shader corpus beyond the 60 s smoke capture.
  • The 29 host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows).

AI use

Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, and paired 60 s GPU smoke captures were executed directly in this workspace.

**@⁠Decodere** on GitHub · 2026-11-26 04:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/2642) `Decodere:fix-dxil-cfg-zero-alloc-and-dag-fastpath` → `main` · +147 −31 · 1 files · 1 commits · open **What is in it** Eliminates redundant `BTreeMap`/`BTreeSet`/`Vec` heap allocations and skips the dominator pass on acyclic CFGs during direct DXIL CFG construction (`crates/xcl/src/gpu/dxil/cfg.rs`): - **Drop `BTreeMap`/`BTreeSet` tables in `Cfg::build_with`:** Replaced `index: BTreeMap<u64, usize>` with `insts.binary_search_by_key(&pc, |d| d.pc)` over monotonically decoded instruction PCs, replaced `leaders: BTreeSet<usize>` and `block_of: BTreeMap<usize, usize>` with flat `is_leader: Vec<bool>`, `starts: Vec<usize>`, and `block_of: Vec<usize>` (with empty-input and `i + 1 < is_leader.len()` bounds guards), removed the unused `reach: BTreeSet<usize>`, and pre-sized `blocks`, per-block `list`, `post`, and `order`'s DFS `stack`. - **Zero-allocation successor iteration (`Succs`):** Replaced `succ_of(&CfgBlock) -> Vec<usize>` with a `Copy` stack-allocated `Succs { buf: [usize; 2], len: usize }` (`as_slice()` + `IntoIterator`) and borrowed `&preds[x]` instead of `preds[x].clone()` in `make_reducible_inner`'s `reach` closure. - **Skip dominator computation on acyclic CFGs:** Extracted `make_reducible_inner` returning `(post, headers, dom_passes)` and short-circuited `if headers.is_empty() { return Ok((post, headers, dom_passes)); }` before calling `irreducible_edge`, avoiding `pos`/`preds`/`idom` allocation and Cooper–Harvey–Kennedy dominator iteration on DAG shaders where DFS found no back edges. Part of #2508 Part of #1833 **Tested** - **Failing-first verification** against pre-fix `make_reducible_inner` semantics (`cargo test --release -p xcl --lib "gpu::dxil::cfg::tests::" -- --test-threads=1 --nocapture`): `1 passed; 1 failed; 0 ignored` — `acyclic_cfg_skips_dominator_pass_and_matches_rpo_and_preds` failed with `left: 1, right: 0` (`irreducible_edge` ran on an acyclic diamond DAG). - **Post-fix WARP targeted tests** (`XCL_ADAPTER=warp`, `XCL_WARP=1`, `cargo test --release -p xcl --lib "gpu::dxil::cfg::tests::" -- --test-threads=1 --nocapture`): `4 passed; 0 failed; 0 ignored; 0 skipped` (`0.00s`; zero warnings in `cfg.rs`). - **Post-fix RTX 4060 targeted DXIL suite** (`cargo test --release -p xcl --lib "gpu::dxil::" -- --test-threads=1 --nocapture`): `187 passed; 0 failed; 3 ignored` (`9.05s`, `gpu::dxil::cfg::tests::` `4/0/0`, `0` skipped; `1` pre-existing `SKIPPED`: `gpu::dxil::kernel::dispatch_chain_native_wave64_builds_whole: no wave64`). **Regression run** - **Full release workspace on RTX 4060** (`cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture`): `37` test binaries, `1438 passed; 0 failed; 47 ignored`, `29` pre-existing environment-gated `SKIPPED` lines: - `21` skipped: `no wave64` (RTX 4060 is wave32) - `3` skipped: wave32 `per-lane form: refused` by driver (`f16 arithmetic`, `f16 packed`, `f32 conversions`) - `3` skipped: no D3D12 debug layer (`d3d12SDKLayers.dll` unavailable on host: debug-layer `dred: false`/`true` and `uploads_start_from_each_subresources_state`) - `1` skipped: `pso_measurement_compiles_an_exact_synthetic_record` (cannot disable driver cache on Windows) - `1` skipped: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows) - **Paired 60 s RTX 4060 smoke capture (`scripts/smoke.ps1`):** Base (`origin/main` `b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7`): ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1576 (PresentX 1576) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13981 MB ``` PR (`742116a9338ffd6c53819dabc636710576a0f74e`): ``` xcl-smoke v1 commit: 742116a9338ffd6c53819dabc636710576a0f74e gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1529 (PresentX 1529) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13974 MB ``` **Not tested** - Direct wall-clock shader-translation microbenchmarks over a full cold shader corpus beyond the 60 s smoke capture. - The `29` host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows). **AI use** Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, and paired 60 s GPU smoke captures were executed directly in this workspace.
Replace BTreeMap/BTreeSet leader and block-index tables in Cfg::build_with
with binary search over monotonically decoded instruction PCs and flat
Vec tables, remove the unused reach BTreeSet, replace heap-allocated
succ_of Vec<usize> with a Copy stack-allocated Succs, avoid cloning
preds[x] in make_reducible, and short-circuit the dominator pass in
make_reducible when order() finds no back edges (acyclic DAG).

Part of #2508
Part of #1833
Assisted-by: Google Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:14:25 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-26 05:07 UTC · original

Native wave64 run (the wave64 tests skipped on the RTX 4060) on an AMD RX 9070 XT, plus an RTX 3060: the 3 new tests pass, and nothing else changes in the direct-DXIL GPU suite.

Head 742116a applied on main b49be18, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4 on main and with the PR, card chosen with XCL_ADAPTER:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010) 708 passed, 2 failed, 6 SKIPPED 711 passed, 2 failed, 6 SKIPPED
RTX 3060 (32.0.16.1088) 710 passed, 0 failed, 24 SKIPPED 713 passed, 0 failed, 24 SKIPPED

On both cards, the only result changes against main are the new acyclic_cfg_skips_dominator_pass_and_matches_rpo_and_preds, empty_reducible_loop_irreducible_and_geometry_cfgs_match and succ_of_is_copy_and_covers_all_terminators, all ok, with no new skips. The wave64 GPU tests that skip on a 32-lane card ran with this PR's CFG code on the RX 9070 XT and still pass. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same on main.

Not tested: translation timings, the D3D12 debug-layer tests (no d3d12SDKLayers.dll here either), a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-26 05:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/2642#issuecomment-7183202118) Native wave64 run (the wave64 tests skipped on the RTX 4060) on an AMD RX 9070 XT, plus an RTX 3060: the 3 new tests pass, and nothing else changes in the direct-DXIL GPU suite. Head `742116a` applied on `main` `b49be18`, debug, Windows 11 Pro 26200, `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4` on `main` and with the PR, card chosen with `XCL_ADAPTER`: | | `main` | this PR | |---|---|---| | RX 9070 XT (RDNA4, 32.0.32029.2010) | 708 passed, 2 failed, 6 SKIPPED | 711 passed, 2 failed, 6 SKIPPED | | RTX 3060 (32.0.16.1088) | 710 passed, 0 failed, 24 SKIPPED | 713 passed, 0 failed, 24 SKIPPED | On both cards, the only result changes against `main` are the new `acyclic_cfg_skips_dominator_pass_and_matches_rpo_and_preds`, `empty_reducible_loop_irreducible_and_geometry_cfgs_match` and `succ_of_is_copy_and_covers_all_terminators`, all ok, with no new skips. The wave64 GPU tests that skip on a 32-lane card ran with this PR's CFG code on the RX 9070 XT and still pass. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same on `main`. Not tested: translation timings, the D3D12 debug-layer tests (no `d3d12SDKLayers.dll` here either), a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠sage-sage on GitHub · 2026-11-26 05:18 UTC · original

Test report: passes on NVIDIA. Exact head 742116a9 (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the three new cfg tests pass, and so do the GPU recompiler tests that run on wave32
  • SKIPPED (29 lines, the same as on main on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dll not installed), 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off)

Not tested

  • The wave64 paths (NVIDIA is wave32 only); no game shaders.

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

**@⁠sage-sage** on GitHub · 2026-11-26 05:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2642#issuecomment-7183363073) **Test report: passes on NVIDIA.** Exact head `742116a9` (its base is current `main` `b49be18`, so head = merged). **Tested** - RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build - `cargo test --workspace -- --test-threads=4`: 1438 passed, 0 failed, 47 ignored; the three new `cfg` tests pass, and so do the GPU recompiler tests that run on wave32 - SKIPPED (29 lines, the same as on `main` on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (`d3d12SDKLayers.dll` not installed), 1 `no heap windows`, 1 `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off) **Not tested** - The wave64 paths (NVIDIA is wave32 only); no game shaders. Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 05:28 UTC · original

I ran the exact head 742116a9 on this RX 6800M setup with XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64, and direct DXIL enabled. The four CFG unit tests and two focused compact-form GPU tests passed with no explicit skips. The full commands, hardware details, counts, and limits are in issue #42.

**@⁠luckyteagirl** on GitHub · 2026-11-26 05:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2642#issuecomment-7183512253) I ran the exact head `742116a9` on this RX 6800M setup with `XCL_ADAPTER=6800M`, `XCL_REQUIRE_GPU=wave64`, and direct DXIL enabled. The four CFG unit tests and two focused compact-form GPU tests passed with no explicit skips. The [full commands, hardware details, counts, and limits are in issue #42](https://git.gtahub.st/github/xcl-dev--xcl/issues/42).
This pull request can be merged automatically.
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/2642/head:github-bot/gh-2642'
git switch 'github-bot/gh-2642'

Merge

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