Recompiler: collapse empty trampolines and merge linear blocks in direct DXIL opt #2194

Manually merged
github merged 1 commit from gh-pr/2194/head into gh-pr/2194/base 2026-11-26 05:22:39 +00:00
Owner

@⁠zondy1i on GitHub · 2026-11-25 08:45 UTC · original
zondy1i:dxil/opt-cfg-cleanup → main · +603 −2 · 1 files · 1 commits · merged 2026-11-25 10:44 UTC

Part of #1269.

After DCE in gpu::dxil::module::opt, guarded lowering helpers and dead branches leave thousands of empty trampoline blocks ([Br(target)]), single-predecessor linear chains, and degenerate CondBr(c, t, t) / Switch terminators in the emitted DXIL.

What is in it

  • crates/xcl/src/gpu/dxil/module/opt.rs: add a fixed-point Module::simplify_cfg pass after DCE (opt-out via XCL_DXIL_NO_OPT=merge, orthogonal to #1818's constant-terminator folding):
    • Collapse degenerate CondBr(_, t, t) to Br(t) and strip Switch cases matching default, updating Op::Phi edge multiplicity to match.
    • Bypass empty trampoline blocks ([Br(t)], b != 0, t != b) whenever t's phis allow it without creating conflicting incoming values or inflating multi-predecessor phi tables (!target_has_phi || total_edges <= 1).
    • Merge single-predecessor linear blocks a -> b along unconditional branches, resolving single-input phis in b, updating def_block, and rewriting successor phis from b to a (including loop backedges).
    • Run a lightweight follow-up trivial-phi + DCE cleanup when CFG simplification changed terminators or phis.
  • Add 5 unit tests covering trampoline chains, phi-conflict preservation, degenerate CondBr/Switch collapse, loop-latch merge with header-phi rewriting, and the multi-predecessor phi guard.

Measured impact

  • Across all 2,682 compute programs from a retail shader pack (XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1, XCL_DXIL_NO_OPT=merge vs default): 2,682 / 2,682 strictly smaller, 0 larger (775,076,910 -> 774,508,202 B).
  • On the largest compute program (95cc13288a27a96e): basic blocks 23,619 -> 20,506 (-13.2%, -3,113 blocks), IR lines 513,461 -> 504,122 (-9,339 lines), DXIL 3,345,980 -> 3,332,628 B (-0.40%).

Tested

  • Windows 11, AMD Ryzen 5 7500F, 64 GB RAM, NVIDIA GeForce RTX 3060 Ti 8 GB (driver 621.01), Rust 1.100.0 MSVC, DXC/dxil 1.9.2602.17.
  • cargo test -p xcl --lib gpu::dxil -- --skip fuzz_validate_and_gpu: 123 passed, 0 failed, 3 ignored (including all 5 new opt::tests::simplify_cfg_* tests and GPU execution tests on RTX 3060 Ti).
  • xcl shaders <pack> --direct --validate --sample 1000 --max-bytes 0 --split 1 with XCL_HEAP_WINDOWS=1: 1,000 / 1,000 (100.0%) across CS (102), GS (18), MS (350), PS (440), VS (90) — 0 validator errors, 0 panics, 0 timeouts.

Not tested

  • AMD / Intel GPUs, Linux / vkd3d-proton, cold cache-off NVIDIA driver compile timings (Windows Developer Mode is disabled on this machine).

Regression run
Base (main):

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1580 (PresentX 1580)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15495 MB

PR (e64bd17):

xcl-smoke v1
commit: e64bd17bc43714c2b3ac940da33a7be84d30999c
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1542 (PresentX 1542)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15367 MB

AI use

  • Implemented, tested, and described with Antigravity (Gemini 4 Neon).
**@⁠zondy1i** on GitHub · 2026-11-25 08:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2194) `zondy1i:dxil/opt-cfg-cleanup` → `main` · +603 −2 · 1 files · 1 commits · merged 2026-11-25 10:44 UTC Part of #1269. After DCE in `gpu::dxil::module::opt`, guarded lowering helpers and dead branches leave thousands of empty trampoline blocks (`[Br(target)]`), single-predecessor linear chains, and degenerate `CondBr(c, t, t)` / `Switch` terminators in the emitted DXIL. **What is in it** - `crates/xcl/src/gpu/dxil/module/opt.rs`: add a fixed-point `Module::simplify_cfg` pass after DCE (opt-out via `XCL_DXIL_NO_OPT=merge`, orthogonal to #1818's constant-terminator folding): - Collapse degenerate `CondBr(_, t, t)` to `Br(t)` and strip `Switch` cases matching `default`, updating `Op::Phi` edge multiplicity to match. - Bypass empty trampoline blocks (`[Br(t)]`, `b != 0`, `t != b`) whenever `t`'s phis allow it without creating conflicting incoming values or inflating multi-predecessor phi tables (`!target_has_phi || total_edges <= 1`). - Merge single-predecessor linear blocks `a -> b` along unconditional branches, resolving single-input phis in `b`, updating `def_block`, and rewriting successor phis from `b` to `a` (including loop backedges). - Run a lightweight follow-up trivial-phi + DCE cleanup when CFG simplification changed terminators or phis. - Add 5 unit tests covering trampoline chains, phi-conflict preservation, degenerate `CondBr`/`Switch` collapse, loop-latch merge with header-phi rewriting, and the multi-predecessor phi guard. **Measured impact** - Across all 2,682 compute programs from a retail shader pack (`XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1`, `XCL_DXIL_NO_OPT=merge` vs default): **2,682 / 2,682 strictly smaller, 0 larger** (`775,076,910` -> `774,508,202` B). - On the largest compute program (`95cc13288a27a96e`): basic blocks **23,619 -> 20,506 (-13.2%, -3,113 blocks)**, IR lines **513,461 -> 504,122 (-9,339 lines)**, DXIL **3,345,980 -> 3,332,628 B (-0.40%)**. **Tested** - Windows 11, AMD Ryzen 5 7500F, 64 GB RAM, NVIDIA GeForce RTX 3060 Ti 8 GB (driver 621.01), Rust 1.100.0 MSVC, DXC/dxil 1.9.2602.17. - `cargo test -p xcl --lib gpu::dxil -- --skip fuzz_validate_and_gpu`: **123 passed, 0 failed, 3 ignored** (including all 5 new `opt::tests::simplify_cfg_*` tests and GPU execution tests on RTX 3060 Ti). - `xcl shaders <pack> --direct --validate --sample 1000 --max-bytes 0 --split 1` with `XCL_HEAP_WINDOWS=1`: **1,000 / 1,000 (100.0%)** across CS (102), GS (18), MS (350), PS (440), VS (90) — 0 validator errors, 0 panics, 0 timeouts. **Not tested** - AMD / Intel GPUs, Linux / vkd3d-proton, cold cache-off NVIDIA driver compile timings (Windows Developer Mode is disabled on this machine). **Regression run** Base (`main`): ```text xcl-smoke v1 commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1580 (PresentX 1580) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15495 MB ``` PR (`e64bd17`): ```text xcl-smoke v1 commit: e64bd17bc43714c2b3ac940da33a7be84d30999c gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1542 (PresentX 1542) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15367 MB ``` **AI use** - Implemented, tested, and described with Antigravity (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:22:38 +00:00
github manually merged commit e64bd17bc4 into gh-pr/2194/base 2026-11-26 05:22:39 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-25 09:00 UTC · original

AMD run (listed as untested), paired against main, with the direct translator on for the whole GPU suite since this changes the optimizer every direct-DXIL program goes through.

Head e64bd17 applied on main 568e7db, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, run on main and on this PR for each card:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010, native wave64) 583 passed, 3 failed, 22 ignored, 6 SKIPPED 588 passed, 3 failed, 22 ignored, 6 SKIPPED
RTX 3060 (32.0.16.1088, wave32, split wave64) 585 passed, 1 failed, 22 ignored, 23 SKIPPED 590 passed, 1 failed, 22 ignored, 23 SKIPPED

Per-test comparison: on both cards the only differences between the two runs are the 5 new simplify_cfg_* tests (all ok). No existing test changes result. The failures are the same on main: gpu_image_get_resinfo_1d_array on both cards (the direct-path bug #2046 fixes) and, on the RX 9070 XT only, the fuzz seeds 722 and 1599 tracked in #2115.

Not tested: driver compile time on AMD, a title with XCL_DIRECT_DXIL=1.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-25 09:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2194#issuecomment-7157754988) AMD run (listed as untested), paired against `main`, with the direct translator on for the whole GPU suite since this changes the optimizer every direct-DXIL program goes through. Head `e64bd17` applied on `main` `568e7db`, debug, Windows 11 Pro 26200, `XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4`, run on `main` and on this PR for each card: | | `main` | this PR | |---|---|---| | RX 9070 XT (RDNA4, 32.0.32029.2010, native wave64) | 583 passed, 3 failed, 22 ignored, 6 SKIPPED | 588 passed, 3 failed, 22 ignored, 6 SKIPPED | | RTX 3060 (32.0.16.1088, wave32, split wave64) | 585 passed, 1 failed, 22 ignored, 23 SKIPPED | 590 passed, 1 failed, 22 ignored, 23 SKIPPED | Per-test comparison: on both cards the only differences between the two runs are the 5 new `simplify_cfg_*` tests (all ok). No existing test changes result. The failures are the same on `main`: `gpu_image_get_resinfo_1d_array` on both cards (the direct-path bug #2046 fixes) and, on the RX 9070 XT only, the fuzz seeds 722 and 1599 tracked in #2115. Not tested: driver compile time on AMD, a title with `XCL_DIRECT_DXIL=1`. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠NWProgramming00 on GitHub · 2026-11-25 09:09 UTC · original

Independent run on NVIDIA and on an AMD GPU with native wave64 (the AMD part is listed as not tested). Exact head e64bd17, compared with its base 568e7db.

Hardware: Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB, and an AMD Radeon RDNA2 iGPU (gfx1036, native 64-lane waves) selected with XCL_ADAPTER=radeon. Release builds.

cargo build --release --workspace then cargo test --release --workspace --no-fail-fast -- --test-threads=4, each adapter with and without XCL_DIRECT_DXIL=all:

Adapter Mode base 568e7db PR e64bd17
RTX 5070 Ti default 1150 passed, 4 failed 1155 passed, 4 failed
RTX 5070 Ti XCL_DIRECT_DXIL=all 1148 passed, 6 failed 1153 passed, 6 failed
Radeon gfx1036 default 1153 passed, 1 failed 1158 passed, 1 failed
Radeon gfx1036 XCL_DIRECT_DXIL=all 1151 passed, 3 failed 1156 passed, 3 failed
  • The +5 passed are the five new opt::tests::simplify_cfg_* tests. They pass on both adapters.
  • The failures are the same tests on base and PR, and each is already tracked:
    • fuzz_validate_and_gpu_0..3 on NVIDIA: CreateComputePipelineState returns E_OUTOFMEMORY (#1905).
    • fuzz_validate_and_gpu_1 on the RDNA2 iGPU: seed 540, res[833] = 0x7, CPU 0x6 (#2115, #2170).
    • gpu_image_get_resinfo_1d_array with XCL_DIRECT_DXIL=all, both adapters: layers come back as 1 instead of 3 (#2046).
    • offline_compute_pipeline_is_reused_by_a_second_process with XCL_DIRECT_DXIL=all, both adapters (#1674).
  • The e2e tests (e2e.rs) pass 3/3 on both adapters.

Not tested: cold-cache NVIDIA driver compile times, and a title run.

AI use: Claude Code (Claude Opus 5.5) ran the suites, compared them with the base and wrote this comment.

**@⁠NWProgramming00** on GitHub · 2026-11-25 09:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/2194#issuecomment-7157951389) Independent run on NVIDIA and on an AMD GPU with native wave64 (the AMD part is listed as not tested). Exact head `e64bd17`, compared with its base `568e7db`. **Hardware:** Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB, and an AMD Radeon RDNA2 iGPU (gfx1036, native 64-lane waves) selected with `XCL_ADAPTER=radeon`. Release builds. `cargo build --release --workspace` then `cargo test --release --workspace --no-fail-fast -- --test-threads=4`, each adapter with and without `XCL_DIRECT_DXIL=all`: | Adapter | Mode | base `568e7db` | PR `e64bd17` | |---|---|---|---| | RTX 5070 Ti | default | 1150 passed, 4 failed | 1155 passed, 4 failed | | RTX 5070 Ti | `XCL_DIRECT_DXIL=all` | 1148 passed, 6 failed | 1153 passed, 6 failed | | Radeon gfx1036 | default | 1153 passed, 1 failed | 1158 passed, 1 failed | | Radeon gfx1036 | `XCL_DIRECT_DXIL=all` | 1151 passed, 3 failed | 1156 passed, 3 failed | - The +5 passed are the five new `opt::tests::simplify_cfg_*` tests. They pass on both adapters. - The failures are the same tests on base and PR, and each is already tracked: - `fuzz_validate_and_gpu_0..3` on NVIDIA: `CreateComputePipelineState` returns `E_OUTOFMEMORY` (#1905). - `fuzz_validate_and_gpu_1` on the RDNA2 iGPU: seed 540, `res[833] = 0x7, CPU 0x6` (#2115, #2170). - `gpu_image_get_resinfo_1d_array` with `XCL_DIRECT_DXIL=all`, both adapters: layers come back as 1 instead of 3 (#2046). - `offline_compute_pipeline_is_reused_by_a_second_process` with `XCL_DIRECT_DXIL=all`, both adapters (#1674). - The e2e tests (`e2e.rs`) pass 3/3 on both adapters. **Not tested:** cold-cache NVIDIA driver compile times, and a title run. **AI use:** Claude Code (Claude Opus 5.5) ran the suites, compared them with the base and wrote this comment.
Author
Owner

@⁠bielfreedom on GitHub · 2026-11-25 10:41 UTC · original

AMD Windows driver timing for #2194: on the RX 9070 XT, AMD's CreateComputePipelineState is about the same speed with this change, except one program that builds 16 % faster. This adds driver timing to DarkPanda69's GPU suite run on the same card.

Setup

  • GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010.
  • CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release.
  • Builds:
    • base 568e7db;
    • this PR at e64bd17.
  • Both builds carry a local patch that logs per-program DXIL size, record hash (fnv64) and per-CreateComputePipelineState time.

Method

  • XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0, XCL_PIPELINE_THREADS=1.
  • XCL_PSO_DISK_CACHE=0 and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name.
  • 26 retail compute programs, 6 KB to 1.0 MB of direct DXIL: the same set I used for #2207.
  • 2 rounds, interleaved.
  • A watchdog killed a run at 24 GB.

26 programs (means of 2 rounds; all 104 builds succeeded, 0 refused)

base #2194 change
direct DXIL, total 8,598,156 B 8,590,924 B −0.08 %
driver, sum (r1 / r2) 271.4 / 271.4 s 268.2 / 267.8 s −1.3 %
driver run, process peak private 4.51–4.60 GB 4.60–4.78 GB about the same
  • All 26 programs are strictly smaller, matching your census. The cuts run from 16 B to 1.1 KB.
  • The other 25 programs stay within ±5 % of their driver time, or within a few ms on those under 0.1 s. The largest, 84eee477d68b6fdf (CS_RaytracingResolve), went 53.2 → 53.6 s.
  • One program stands out: 620491641aa9bad6, 17.9 → 15.1 s (−16 %). Its rounds were 17.93 / 17.90 s on base and 15.12 / 15.06 s on this PR. An earlier pair of base runs gave 17.7 s. Its DXIL shrinks by only 56 B, so the AMD compiler seems to react to the shape of the CFG rather than the size.

ActivateRays (95cc13288a27a96e), plain on this adapter, 1 run:

  • DXIL went 3,916,120 → 3,892,416 B (−0.6 %).
  • It still reached 24 GB after 157 s and was killed (base: 153 s).

Tests on this card (XCL_REQUIRE_GPU=1, XCL_ADAPTER=9070)

  • cargo test --release -p xcl --lib -- dxil::module::opt --test-threads=1: 6 passed, 0 failed.
  • That includes the 5 simplify_cfg_* tests.

Read / inference

  • On the native AMD Windows compiler this is close to neutral overall: −1.3 % on driver time, with no program measurably slower.
  • 620491641aa9bad6 is one of the two programs bobosneefdev reported as slow to build on AMD in #1269, so the 16 % there is the part that matters on this vendor.

Not tested

  • The whole gpu:: suite on this build (DarkPanda69 covered it on this card).
  • The HLSL path.
  • XCL_HEAP_WINDOWS=1.
  • A title run.
  • RDNA2 and RDNA3.

AI use: Claude Code (Claude Opus 5.5) ran the measurements and tests and drafted this. The account owner is away; counts and timings only, no game data.

**@⁠bielfreedom** on GitHub · 2026-11-25 10:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2194#issuecomment-7160049442) **AMD Windows driver timing for #2194: on the RX 9070 XT, AMD's `CreateComputePipelineState` is about the same speed with this change, except one program that builds 16 % faster.** This adds driver timing to DarkPanda69's GPU suite run on the same card. **Setup** - GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010. - CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release. - Builds: - base `568e7db`; - this PR at `e64bd17`. - Both builds carry a local patch that logs per-program DXIL size, record hash (`fnv64`) and per-`CreateComputePipelineState` time. **Method** - `XCL_DIRECT_DXIL=1`, `XCL_HEAP_WINDOWS=0`, `XCL_PIPELINE_THREADS=1`. - `XCL_PSO_DISK_CACHE=0` and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name. - 26 retail compute programs, 6 KB to 1.0 MB of direct DXIL: the same set I used for #2207. - 2 rounds, interleaved. - A watchdog killed a run at 24 GB. **26 programs** (means of 2 rounds; all 104 builds succeeded, 0 refused) | | base | #2194 | change | |---|---:|---:|---:| | direct DXIL, total | 8,598,156 B | 8,590,924 B | −0.08 % | | driver, sum (r1 / r2) | 271.4 / 271.4 s | **268.2 / 267.8 s** | **−1.3 %** | | driver run, process peak private | 4.51–4.60 GB | 4.60–4.78 GB | about the same | - All 26 programs are strictly smaller, matching your census. The cuts run from 16 B to 1.1 KB. - The other 25 programs stay within ±5 % of their driver time, or within a few ms on those under 0.1 s. The largest, `84eee477d68b6fdf` (`CS_RaytracingResolve`), went 53.2 → 53.6 s. - One program stands out: **`620491641aa9bad6`, 17.9 → 15.1 s (−16 %)**. Its rounds were 17.93 / 17.90 s on base and 15.12 / 15.06 s on this PR. An earlier pair of base runs gave 17.7 s. Its DXIL shrinks by only 56 B, so the AMD compiler seems to react to the shape of the CFG rather than the size. **ActivateRays (`95cc13288a27a96e`)**, plain on this adapter, 1 run: - DXIL went 3,916,120 → 3,892,416 B (−0.6 %). - It still reached 24 GB after 157 s and was killed (base: 153 s). **Tests on this card** (`XCL_REQUIRE_GPU=1`, `XCL_ADAPTER=9070`) - `cargo test --release -p xcl --lib -- dxil::module::opt --test-threads=1`: **6 passed, 0 failed**. - That includes the 5 `simplify_cfg_*` tests. **Read / inference** - On the native AMD Windows compiler this is close to neutral overall: −1.3 % on driver time, with no program measurably slower. - `620491641aa9bad6` is one of the two programs bobosneefdev reported as slow to build on AMD in #1269, so the 16 % there is the part that matters on this vendor. **Not tested** - The whole `gpu::` suite on this build (DarkPanda69 covered it on this card). - The HLSL path. - `XCL_HEAP_WINDOWS=1`. - A title run. - RDNA2 and RDNA3. AI use: Claude Code (Claude Opus 5.5) ran the measurements and tests and drafted this. The account owner is away; counts and timings only, no game data.
This discussion has been locked. Commenting is limited to contributors.
No description provided.