Recompiler: fix trivial phi collapse, 0-pred phis, and chains in recomp::ssa #2138
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2148"
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?
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-25T06:18:19Z.
What is in it
Fixes four Braun et al. SSA construction bugs in
crates/xcl/src/gpu/recomp/ssa.rs(used byrecomp/lower.rsandrecomp/lower_dxil.rs, where uncollapsed trivial phis breakresolve_value(v)checks againstnum_marker/bit_marker):userstransfer on trivial phi collapse (remove_trivial/replace_phi): Previously,self.users.remove(&phi)dropped every user of a collapsed phi that remained non-trivial at that moment (for example,phi3 = phi(phi2, a)whenphi2collapsed to an unsealed outerphi1). Whenphi1later collapsed toa(or collapsed later in the sameusersloop whenusers[phi2]ordered[phi3, phi1]),phi3was never revisited and remained live as a trivialphi(a, a). Live users (user != phi && user != replacement && self.operands.contains_key(&user)) are now transferred intoself.users[replacement]before cascadingremove_trivial().remove_trivial(replace_phi): When a mutual phi cycle (phi1 = phi(a, phi2)andphi2 = phi(phi1, phi2)) collapsedphi2 -> phi1and cascadedphi1 -> a,remove_trivialreturned the already-replacedsame(phi1) instead ofself.resolve(same)(a). Now returnsself.resolve(replacement).add_operands): Sealing an unsealed block withpreds[block].is_empty()previously left a 0-operand phi live (same == None) instead of replacing it withsink.undef(var).add_operands()now replaces 0-predecessor incomplete phis withsink.undef(var)viareplace_phi()(transferring and cascading any users), and for non-empty predecessors collects all incoming(pred, value)pairs and resolves each value before populatingoperands/usersso a half-populated phi is never exposed to a recursiveremove_trivial()cascade.read):read()previously recursed unconditionally onpreds[block].len() == 1, overflowing the stack on deep straight-line chains and on unreachable sealed 1-predecessor cycles (preds[b] = [b]ora <-> b). Sealed single-predecessor chains are now walked iteratively withHashSetcycle detection, returning and cachingsink.undef(var)on unreachable 1-predecessor cycles.Adds four deterministic pure-CPU regression tests in
gpu::recomp::ssa::testscovering all four bugs.Part of #1269
Tested
Hardware/toolchain: Windows 11 (26200), NVIDIA GeForce RTX 4060 (32-lane waves, driver 621.14), DXC
1.9.2609.5 (01b62ad4), Rust1.100.0.delayed_trivial_phi_collapse_transfers_users:live phis left: [4];mutual_phi_cycle_collapse_returns_resolved_value: returned stale3instead of1;unsealed_zero_pred_block_replaces_incomplete_phi_with_undef:0-pred phi stayed live: [1, 2];sealed_single_pred_cycle_and_deep_chain_do_not_overflow:STATUS_STACK_OVERFLOW0xc00000fd).cargo test --release -p xcl --lib gpu::recomp::ssa::tests::: 10 passed, 0 failed, 0 ignored (pure CPU, CI WARP-safe).cargo test --release -p xcl --lib gpu::recomp::lower::tests:: -- --test-threads=1: 35 passed, 0 failed, 0 ignored.cargo test --release -p xcl --lib gpu::recomp::lower_dxil::tests:: -- --test-threads=1: 18 passed, 0 failed, 0 ignored.cargo build --release --workspace: exit 0.cargo test --release --workspace -- --test-threads=4: 1158 passed, 0 failed, 46 ignored across 21 test suites, with 25 pre-existing runtimeSKIPPEDlines (23 native wave64 / unsupported per-lane lowering skips on 32-lane RTX 4060, 1 Windows driver-cache skip, 1 heap-window skip; 0 new skips).Regression run
Paired 60-second
scripts/smoke.ps1runs on the same retail title build (29640639) from cleanorigin/main(6ea813a) and this branch (a7f059b):Base (
origin/main):PR (
fix-1269-recomp-ssa-braun-bugs):Not tested
recomp::ssais wave-size-independent SSA construction and all new tests are deterministic CPU unit tests).AI use
Drafted with Google Antigravity (Gemini 4 Neon) and verified locally by reproducing all four failures before the fix (including stack overflow on the 1-predecessor cycle/chain test), running
recomp::ssa,recomp::lower,recomp::lower_dxil, and the full release workspace test suite, and completing the paired 60-second smoke run above.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-25T07:03:17Z.
Full-suite run, since this PR has no test report yet. Tested exact head
a7f059b(on its base6ea813a).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1146 passed, 0 failed, 44 ignored. SKIPPED (no wave64):a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,a_per_lane_2d_or_3d_group_runs_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.delayed_trivial_phi_collapse_transfers_users,mutual_phi_cycle_collapse_returns_resolved_value,unsealed_zero_pred_block_replaces_incomplete_phi_with_undef,sealed_single_pred_cycle_and_deep_chain_do_not_overflow.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1157 passed, 0 failed, 46 ignored. SKIPPED:f16_programs_on_the_gpu(f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),f32_programs_on_the_gpu(f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out tests that fail on main568e7dbtoo, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651), the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests,const_and_null_mask_operands_agree_with_hlsl_on_the_gpuandmask_ff0_and_flbit_agree_with_hlsl_on_the_gpu(follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T07:05:48Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 1038 passed, 1 failed in one parallel run; the failing test passes on a single-threaded rerun (1039/0). Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.Thanks!
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T23:19:06Z.
Tested head
a7f059b9972bda022a825b6bf3e079b143082b50, merge-base6ea813a61f7d324e2fcbeb0c6a068edcd37e818b, RTX 3070 (Ampere) driver 616.56, Windows 11, rustc 1.100.0cargo test -p xcl --lib -- gpu::recomp::ssa --test-threads=1 --nocapture, 3 runs on head: 10 passed, 0 failed (each run; the 4 new tests included). CPU-only, no GPU involved.ssa.rstest hunk (4 new tests) applied alone to the merge-base (compiles):delayed_trivial_phi_collapse_transfers_users,mutual_phi_cycle_collapse_returns_resolved_valueandunsealed_zero_pred_block_replaces_incomplete_phi_with_undeffail (assertion panics);sealed_single_pred_cycle_and_deep_chain_do_not_overflowoverflows the stack and aborts the test process (exit code 0xc00000fd). The 6 older tests pass.cargo test -p xcl --lib -- --test-threads=4: head 1102 passed, 0 failed, 26 ignored; merge-base (unmodified) 1098 passed, 0 failed, 26 ignored.Not tested: retail title; AMD hardware.
AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).
Imported from ivall/xcl. Originally posted by throny on 2026-11-29T00:12:18Z.
merge-check claim
head:
a7f059b997Imported from ivall/xcl. Originally posted by throny on 2026-11-29T00:29:50Z.
merge-check
base:
b10cc4c6head:
a7f059b997merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2611 passed, 0 failed, 49 ignored on the merge result with main
b10cc4c6(27 SKIPPED lines).review: no blocking finding; all hunks read. When a phi collapses, its users are now also registered on the value that replaces it, so they are looked at again if that value collapses later; the function returns the resolved value instead of a phi already replaced; operands are all read before any user is registered, so a half-filled phi cannot be collapsed in a cascade; a phi in a block without predecessors becomes undefined; chains of single-predecessor blocks are walked with a seen-set, so an unreachable cycle ends. Every collapse removes one live phi, so the loop terminates. No signature changes. Minor: the user lists use a linear search, which is quadratic when one value has very many users.
performance: none measurable expected. It changes a per-lane source only: only per-lane cache entries (XCL_PER_LANE) are re-translated.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by moombathepilot on 2026-11-29T17:05:22Z.
merge-check
base:
0fe06eb0f0head:
a7f059b997merge: clean
build:
cargo build --workspacepassed.tests:
cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapturereported 2,739 passed, 2 failed, and 49 ignored, with 12 explicitSKIPPEDnotices. All 10 SSA unit tests passed, including the four added by this PR. The native-wave branch test and mixed-mask branch comparison against HLSL also passed on AMD.Both failures matched targeted runs previously made on the exact unmodified base on this machine:
fuzz_validate_and_gpu_1produced the same GPU/CPU mismatch at seed 722.two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsfailed the same assertion on releasing two-pass state.review: Read the full PR and trial-merge diffs. Phi replacement transfers users before cascading and returns the resolved value. The iterative predecessor walk handles cycles and deep chains. The new tests cover delayed cascades, mutual phi cycles, zero-predecessor blocks, and a 20,000-block chain. No blocking findings.
git diff --cached --checkpassed.performance: The change affects per-lane shader translation. The predecessor walk uses a visited set, and phi-user deduplication uses linear scans. Translation time and frame time were not measured. No retail smoke run was performed for this Tier 1 check.
verdict: safe to merge
hardware / tool and model: Windows 11 Home build 26300, Ryzen 7 5700X3D, Radeon RX 7800 XT (driver 32.0.32029.2010), Rust 1.100.0 x86_64-pc-windows-msvc. Codex (GPT-6, exact variant unavailable) verified refs, reviewed the diffs, ran the build and tests, compared the baseline logs, and drafted this report.