Repository navigation
Recompiler: fold constant CFG terminators and recompute live DXIL flags - #3268
Conversation
Fixes two Direct DXIL correctness bugs (xcl-dev#1894, xcl-dev#1890): - Module::uses_double_extensions now iterates live instructions in self.blocks (matching insts_use_type) instead of all self.insts, preventing DCE-removed f64 ops from spuriously setting DoubleExtensions shader flags. - Lw::top_vgpr now incorporates Lw::max_vgpr precomputed across all decoded instructions (init.touched is empty outside Entry::Kernel), and v_movrels / v_movreld / v_movrelsd mask M0 to M0[7:0] (& 0xFF) per RDNA2 ISA. Assisted-by: Antigravity (Gemini 4 Neon High) (cherry picked from commit 2c33f9f) Port onto nvidia-dev: only `max_vgpr` is added to Lw; the `barrier_uav_fence` field next to it upstream belongs to 85a9480, which this branch does not have. (cherry picked from commit aac4343) Ported to main without the neighbouring test of fcbd0d1, which is a PR of its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
merge-check |
|
merge-check Re-verified updated head
|
|
merge-check claim |
|
merge-check |
Port xcl-dev#1818's constant-CFG terminator and path-fact folding onto Direct DXIL and fix the stale shader-flag validation gap that blocked it: 1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate dominating branch/switch path facts (bounded to 16 RPO passes so large shaders stay linear), fold constant CondBr/Switch terminators, drop newly unreachable blocks and obsolete PHI edges (preserving loop backedges), and rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg). 2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA), ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and TypedUavLoadAdditionalFormats in Shader::infer_type_features() against surviving reachable instructions after optimize(), preventing stale shader flags when dead branches are pruned. Adds unit tests covering constant branches/switches, dominated branch facts, reconvergence, loop PHI backedges, and pruned i64/heap shader flags. Assisted-by: Antigravity (Gemini 4 Neon High) (cherry picked from commit f4b0706) (cherry picked from commit 3c54e55) Ported to main: simplify_phis keeps main's back-edge check (5a984e0: a phi is not replaced by a value defined after it in the layout), with positions recomputed after the CFG fold; XCL_DXIL_NO_OPT lists both main's select and this cfg pass; main's tests stay next to the new ones. Review fixes (xcl-dev#3268): a cmpxchg is typed as its { T, i1 } pair, so the live scan now takes T from the compared value and keeps AtomicInt64GroupShared for a 64-bit group-shared cmpxchg; and a folded CondBr(c, t, t) or a switch with several cases to one block keeps one phi entry per remaining edge (drop_phi_edges, as simplify_cfg does), not one per case. Both have a test that fails without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a343eaf to
04df590
Compare
|
Thanks throny. Changes in 04df590:
The new suite and smoke runs are in the description. #3269 is rebased onto this. (Written with Claude Code, Claude Opus 5.5.) |
Port xcl-dev#1818's constant-CFG terminator and path-fact folding onto Direct DXIL and fix the stale shader-flag validation gap that blocked it: 1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate dominating branch/switch path facts (bounded to 16 RPO passes so large shaders stay linear), fold constant CondBr/Switch terminators, drop newly unreachable blocks and obsolete PHI edges (preserving loop backedges), and rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg). 2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA), ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and TypedUavLoadAdditionalFormats in Shader::infer_type_features() against surviving reachable instructions after optimize(), preventing stale shader flags when dead branches are pruned. Adds unit tests covering constant branches/switches, dominated branch facts, reconvergence, loop PHI backedges, and pruned i64/heap shader flags. Assisted-by: Antigravity (Gemini 4 Neon High) (cherry picked from commit f4b0706) (cherry picked from commit 3c54e55) Ported to main: simplify_phis keeps main's back-edge check (5a984e0: a phi is not replaced by a value defined after it in the layout), with positions recomputed after the CFG fold; XCL_DXIL_NO_OPT lists both main's select and this cfg pass; main's tests stay next to the new ones. Review fixes (xcl-dev#3268): a cmpxchg is typed as its { T, i1 } pair, so the live scan now takes T from the compared value and keeps AtomicInt64GroupShared for a 64-bit group-shared cmpxchg; and a folded CondBr(c, t, t) or a switch with several cases to one block keeps one phi entry per remaining edge (drop_phi_edges, as simplify_cfg does), not one per case. Both have a test that fails without the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KOLESNiii
left a comment
There was a problem hiding this comment.
Static review of 527a8b26 for the stack in the #3041 comparison.
For readers of the #3041 comparison, the measured CFG commit had two issues already addressed by the later revision. The feature scan could clear AtomicInt64GroupShared on a live 64-bit cmpxchg because it checked the {T, i1} result type. The fold could also retain too many PHI inputs when several switch edges to one block collapsed into one. The PR documents both fixes at 04df5904. I verified the fixes in the rebased copy under #3269. Historical feature scan ?? Historical PHI pruning
Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
Stacked on #3266: the first commit here is #3266's own commit (
4a20b256), and the CFG commit (04df5904) is on top. Once #3266 merges, only the CFG commit remains in this PR. Thev_movrel*change in this PR's diff is #3266's, not this PR's. The CFG folding needs #3266 first: folding removes f64 instructions but leftDoubleExtensionsdeclared, and the validator rejected the module (fuzz_validate_and_gpu_0..2, seeds 33 / 641 / 1448, found by CI). #3269 builds on these two commits.Review fixes (throny), in the CFG commit:
AtomicInt64GroupSharedfor acmpxchgonly when the instruction's type was i64, but acmpxchgis typed as its{ T, i1 }pair, so a 64-bit group-shared compare-exchange lost its flag. T now comes from the compared value (live_64_bit_group_shared_atomics_keep_their_shader_flag).CondBr(c, t, t), or a constant switch with several cases to one block, kept one phi entry per case in the target although only one edge remains. Main keeps one entry per edge (simplify_cfg'sdrop_phi_edges), and the fold now does too (a_constant_switch_with_two_cases_to_one_block_leaves_one_phi_entry).Both tests fail without their fix and pass with it.
Overlaps #1818 (mokkamokacaffe, the original constant-CFG folding, conflicting with main): this is amd-dev's port of it (
3c54e558, raylitebull), which adds the live shader-flag fix below. Maintainers, keep one. The IR optimizations of amd-dev'sf089a9df(next PR) build on this one.The direct DXIL optimizer did not fold a conditional branch or switch whose condition is constant (directly, or because a dominating branch already decided it), so dead branches survived. Their instructions also left shader flags set (Int64Ops, Doubles, ResourceHeapIndexing, ...) that the surviving code no longer needs.
What is in it
crates/xcl/src/gpu/dxil/module/opt.rs: CSE / trivial-phi replacements resolved before CFG folding; dominating branch / switch facts (bounded to 16 RPO passes); constantCondBr/Switchfolded (phi entries dropped per removed edge); unreachable blocks and obsolete phi edges dropped (loop back-edges kept); trivial phis simplified again.XCL_DXIL_NO_OPT=cfgturns it off.crates/xcl/src/gpu/dxil/shader.rs,module.rs:infer_type_featuresrecomputes Int64Ops, Doubles, DoubleExtensions (f64 FMA too), resource / sampler heap indexing, 64-bit atomics and typed UAV load formats from the instructions that survivedoptimize()simplify_phiskeeps main's back-edge check from5a984e02(a phi is not replaced by a value defined after it), with positions recomputed after the CFG fold; main's select pass and tests are keptTested
cargo test --workspace --no-fail-fast -- --test-threads=4on 04df590: 2613 passed, 4 failed, 49 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(E_OUTOFMEMORYfromCreateComputePipelineState, seeds 70 / 545 / 1019 / 1507). They fail the same way on this branch's base, main fa20459, on this machine, and pass here on newer main (Recompiler: early-exit-safe multi-wave s_barrier in direct DXIL #3264, rebased onto 0fe06eb, has 0 failures). SKIPPED GPU tests: 30 distinct notices, almost allno wave64.-StartupTimeoutSeconds 3600for the cold pipeline rebuild new DXIL needs.Regression run
main:
this PR:
Not tested
AI use
3c54e558(raylitebull, fromf4b07062, written with Antigravity (Gemini 4 Neon High)), itself a port of dxil: fold constant CFG terminators after CSE #1818.🤖 Generated with Claude Code