Recompiler: skip unused scalar-load analysis for direct compact emission #2746

Open
opened 2026-11-26 11:14:36 +00:00 by github-bot · 1 comment
Owner

@⁠KOLESNiii on GitHub · 2026-11-26 09:47 UTC · original

Part of #2088 and #2508. Reviewed on main at b49be18.

After deciding to produce compact direct DXIL, translate_on_this_thread still calls reload::analyze(&cfg) for compute and kernel entries. Only the ordinary block loop reads reloads, and that loop runs only when plan.is_none(). Compact emission lowers its representative blocks separately. The discarded analysis scans the original CFG and runs a fixed-point pass. Call and compact emitter · Only consumer · Fixed-point analysis

A standalone optimized Rust probe on Linux, AMD Ryzen AI 7 350, used XCL's decoder, CFG construction and reload analysis, and extracted the compact-planner code. Three synthetic scalar programs each had 32,769 decoded instructions and 8,193 reachable blocks. The automatic planner selected compact in each case. Median analysis time over five passes per program was 91 ms, 689 ms and 1,370 ms for 16, 128 and 256 distinct load addresses. These timings are for the analysis alone on synthetic input. Whole-translation, Windows and retail effects remain unmeasured.

Move reload analysis inside the ordinary-emission branch or guard it with plan.is_none(). Keep plain-code reload reuse and compact code generation byte-for-byte equivalent on synthetic fixtures. A compact translation timing with the translated cache disabled can quantify the benefit on a workload that uses the path. Related scalar-load work in #2464/#2479 changes the analysis itself.

AI use was OpenAI Codex (GPT-6, exact serving variant unavailable) for static analysis, the standalone Linux probe and drafting.

**@⁠KOLESNiii** on GitHub · 2026-11-26 09:47 UTC · [original](https://github.com/xcl-dev/xcl/issues/2746) Part of #2088 and #2508. Reviewed on `main` at `b49be18`. After deciding to produce compact direct DXIL, `translate_on_this_thread` still calls `reload::analyze(&cfg)` for compute and kernel entries. Only the ordinary block loop reads `reloads`, and that loop runs only when `plan.is_none()`. Compact emission lowers its representative blocks separately. The discarded analysis scans the original CFG and runs a fixed-point pass. [Call and compact emitter](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/gpu/dxil/kernel.rs#L335-L346) · [Only consumer](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/gpu/dxil/kernel.rs#L370-L377) · [Fixed-point analysis](https://github.com/xcl-dev/xcl/blob/b49be18/crates/xcl/src/gpu/dxil/reload.rs#L162-L253) A standalone optimized Rust probe on Linux, AMD Ryzen AI 7 350, used XCL's decoder, CFG construction and reload analysis, and extracted the compact-planner code. Three synthetic scalar programs each had 32,769 decoded instructions and 8,193 reachable blocks. The automatic planner selected compact in each case. Median analysis time over five passes per program was **91 ms, 689 ms and 1,370 ms** for 16, 128 and 256 distinct load addresses. These timings are for the analysis alone on synthetic input. Whole-translation, Windows and retail effects remain unmeasured. Move reload analysis inside the ordinary-emission branch or guard it with `plan.is_none()`. Keep plain-code reload reuse and compact code generation byte-for-byte equivalent on synthetic fixtures. A compact translation timing with the translated cache disabled can quantify the benefit on a workload that uses the path. Related scalar-load work in #2464/#2479 changes the analysis itself. AI use was OpenAI Codex (GPT-6, exact serving variant unavailable) for static analysis, the standalone Linux probe and drafting.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:14:36 +00:00
Author
Owner

@⁠KOLESNiii on GitHub · 2026-11-26 10:45 UTC · original

Windows probe on main at b49be183: confirmed, and on these inputs the discarded analysis is most of the whole compact translation.

Setup

  • AMD Ryzen 5 3600XT, Windows 11 build 26300, rustc 1.100.0, --release (optimized + debuginfo). Run alone on the machine, nothing else on the GPU or CPU.
  • A #[cfg(test)] probe inside the crate, not committed. It builds synthetic wave32 kernels of 4,096 units [s_load_dwordx4 (offset k), s_add, s_add, s_cmp, s_cbranch_scc1 +2] [s_add, s_add] plus s_endpgm: 28,673 decoded instructions and 8,193 reachable blocks, with 16, 128 or 256 distinct load offsets.
  • For each program the probe checks that automatic selection (translate_full, XCL_DIRECT_COMPACT unset) gives the same bytes as forced compact (translate_full_as(.., true)). It does for all three, and the log shows direct DXIL compact form: 8193 blocks of 18 / 130 / 258 kinds.
  • The probe then times reload::analyze(&cfg) on its own and the whole translate_full_as(code, o, true) call (which, on main, includes that analysis). Medians of 5 passes.
distinct loads reload::analyze whole compact translation analysis share
16 114.1 ms 161.4 ms 70.7 %
128 816.0 ms 869.4 ms 93.9 %
256 1,614.1 ms 1,675.1 ms 96.4 %

The cost scales with distinct addresses × register-writing instructions: for every scalar write, step checks every slot against all 128 registers.

Caveats

  • These are synthetic programs built to make the compact planner fire with many distinct loads. I haven't measured how often retail compute shaders take the compact path or how many distinct scalar loads they have, so the in-game benefit is still unmeasured.
  • Static check: the only reader of reloads is the plain block loop (kernel.rs:372), which runs only when plan.is_none(). compact.rs never refers to reload, and lw.reload stays None outside that loop. So guarding the call with plan.is_none() can't change compact output. I'll check that the bytes stay identical with the same probe.

I'm preparing a PR that guards the call.

AI use: Claude Code, Claude Opus 5.5. It wrote the probe, ran it on the hardware above and drafted this comment.

**@⁠KOLESNiii** on GitHub · 2026-11-26 10:45 UTC · [original](https://github.com/xcl-dev/xcl/issues/2746#issuecomment-7189794278) Windows probe on `main` at `b49be183`: confirmed, and on these inputs the discarded analysis is most of the whole compact translation. **Setup** - AMD Ryzen 5 3600XT, Windows 11 build 26300, rustc 1.100.0, `--release` (optimized + debuginfo). Run alone on the machine, nothing else on the GPU or CPU. - A `#[cfg(test)]` probe inside the crate, not committed. It builds synthetic wave32 kernels of 4,096 units `[s_load_dwordx4 (offset k), s_add, s_add, s_cmp, s_cbranch_scc1 +2] [s_add, s_add]` plus `s_endpgm`: 28,673 decoded instructions and 8,193 reachable blocks, with 16, 128 or 256 distinct load offsets. - For each program the probe checks that automatic selection (`translate_full`, `XCL_DIRECT_COMPACT` unset) gives the same bytes as forced compact (`translate_full_as(.., true)`). It does for all three, and the log shows `direct DXIL compact form: 8193 blocks of 18 / 130 / 258 kinds`. - The probe then times `reload::analyze(&cfg)` on its own and the whole `translate_full_as(code, o, true)` call (which, on `main`, includes that analysis). Medians of 5 passes. | distinct loads | `reload::analyze` | whole compact translation | analysis share | |---:|---:|---:|---:| | 16 | 114.1 ms | 161.4 ms | 70.7 % | | 128 | 816.0 ms | 869.4 ms | 93.9 % | | 256 | 1,614.1 ms | 1,675.1 ms | 96.4 % | The cost scales with distinct addresses × register-writing instructions: for every scalar write, `step` checks every slot against all 128 registers. **Caveats** - These are synthetic programs built to make the compact planner fire with many distinct loads. I haven't measured how often retail compute shaders take the compact path or how many distinct scalar loads they have, so the in-game benefit is still unmeasured. - Static check: the only reader of `reloads` is the plain block loop (`kernel.rs:372`), which runs only when `plan.is_none()`. `compact.rs` never refers to `reload`, and `lw.reload` stays `None` outside that loop. So guarding the call with `plan.is_none()` can't change compact output. I'll check that the bytes stay identical with the same probe. I'm preparing a PR that guards the call. AI use: Claude Code, Claude Opus 5.5. It wrote the probe, ran it on the hardware above and drafted this comment.
This discussion has been locked. Commenting is limited to contributors.
No description provided.