Skip to content

[upstream #1090] Recompiler: solve split-wave64 mask liveness per basic block with precomputed operand plans - #66

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1090
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1090

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

What is in it

Accelerate split-wave64 SGPR mask liveness analysis (crates/xcl/src/gpu/recomp/x64_masks.rs), which runs during shader translation for wave64 compute, mesh, and geometry programs on 32-lane-wave GPUs:

  • Basic-block liveness solver: Partition instructions into basic blocks (splitting at branch targets, after terminators/branches, and at loop boundaries so every instruction in a block shares the exact same enclosing loops and LOOP_GUARD exit mask). Because (X & !k) | X == X for bitmasks, the constant per-block exit mask collapses out of intra-block composition, reducing the backward fixpoint from instruction granularity (O(iters * N)) to basic-block granularity (O(iters * B)) with a single linear backward pass per block to reconstruct live_out.
  • Zero per-instruction heap allocations: Replace the BTreeMap<u64, usize> PC table, per-instruction Vec<usize> successor lists, and per-instruction Vec<Option<usize>> loop-exit lists with binary search on sorted PCs, an inline BlockSucc enum, and a single flat exit_targets buffer populated via an O(B * depth + L log B) sweep.
  • O(L log L) nested loop-range fast path: Detect properly nested backward-jump intervals in a single stack sweep, falling back to the exact original merge only for rare irreducible CFGs with partial overlaps.
  • Precomputed per-encoding operand plans (UsePlanTable): Lazily precompute static bit-range descriptors and fixed register masks per (InstEnc, Encoding) in a flat open-addressed table, eliminating per-instruction string .contains() scans and linear Encoding::field lookups in uses().

Release benchmark (cargo test --release --lib gpu::recomp::x64_masks::tests::bench_whole_live_out -- --ignored --nocapture, synthetic multi-loop shaders with nested loops, diamond branches, compares, v_cndmask, and carry chains; bit-for-bit verified against the original solver):

Synthetic shader Original (whole_live_out_reference) Optimized (whole_live_out) Speedup
928 insts (8 outer loops) 669.7 us 28.7 us 23.37x
4,635 insts (40 outer loops) 2,890.1 us 238.5 us 12.12x
9,268 insts (80 outer loops) 6,198.4 us 556.8 us 11.13x

Tested

  • Hardware / toolchain: AMD Radeon RX 6800, Windows x64, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), debug and release.
  • cargo test --lib gpu::recomp::x64_masks: 19 passed, 0 failed, 1 ignored (manual release benchmark). Includes exhaustive equivalence check of uses() vs uses_fallback() across every RDNA2 instruction and encoding, 200-case fuzz check of nested_loop_ranges() against the quadratic merge, and bit-for-bit whole_live_out() equivalence across synthetic multi-loop shaders for both end_reads_all = false and true.
  • cargo test --release --lib gpu::recomp::x64_masks::tests::bench_whole_live_out -- --ignored --nocapture: 1 passed, 0 failed (11.13x–23.37x speedup).
  • cargo build --release -p xcl: succeeded cleanly.

Regression run

Baseline (origin/main):

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 954 (PresentX 954)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15118 MB

PR (7bea019319cc08a54cdb3c9e49a0941d88b35283):

xcl-smoke v1
commit: 7bea019319cc08a54cdb3c9e49a0941d88b35283
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 1034 (PresentX 1034)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15103 MB

Not tested

  • Full cargo test --workspace and live split-wave64 shader compilation on an NVIDIA (wave32-only) GPU; covered by the exhaustive unit and bit-for-bit equivalence tests above.

AI use

  • Assisted by Gemini 4 Neon: designed and implemented the basic-block liveness solver, precomputed UsePlanTable, equivalence tests, and release benchmark, and ran local builds, unit tests, and the retail smoke run.

Mirror of xcl-dev#1090 (auto-synced, do not edit).

…computed operand plans

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#1090 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/1090 branch November 25, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants