Repository navigation
Recompiler: fix Direct DXIL live double-ext scan and movrel VGPR range - #3266
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>
e6a6506 to
4a20b25
Compare
The IR part of amd-dev's DXIL size work. optimize() now repeats its passes (up to 4 times) while one of them still changes the function, and gains: - intra-block store-to-load forwarding and dead-store elimination for non-escaping scalar allocas (mostly the compact form's register slots), and removal of stores to allocas nothing loads; - hoisting of repeated constant-argument ReadNone intrinsics (e.g. dx.op.groupId) to the entry block; createHandleFromHeap stays unshared and annotateHandle / getDimensions stay block-local; - branch facts in the dominator-tree CSE: below a branch on c, c is known (and a switch case's value), so dominated compares fold; - in-place collapse of chained selects on the same condition; - removal of adjacent barriers the first one already covers; - in lanes.rs / prelude.rs / lower_valu.rs: constant EXEC lane-bit folds, single-instruction IEEE f32 compares, and constant fast paths for XCL_RDNA_FLOAT's FRC and legacy mul / fma. New XCL_DXIL_NO_OPT names: alloca, facts, hoist, barrier. Ported to main: the loop keeps main's passes (fold_guarded_selects, the trivial-phi pass after simplify_cfg) and main's back-edge check in every trivial-phi pass (positions recomputed after hoisting, CFG folding and merging; layout_positions). The XCL_HEAP_WINDOWS default flip of the original commit is left out. Needs the live double-ext scan of the commit below (xcl-dev#3266): without it, f64 ops the new passes remove leave DoubleExtensions declared and the validator rejects the module (fuzz seed 33). Ported from the IR part of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
merge-check |
The IR part of amd-dev's DXIL size work. optimize() now repeats its passes (up to 4 times) while one of them still changes the function, and gains: - intra-block store-to-load forwarding and dead-store elimination for non-escaping scalar allocas (mostly the compact form's register slots), and removal of stores to allocas nothing loads; - hoisting of repeated constant-argument ReadNone intrinsics (e.g. dx.op.groupId) to the entry block; createHandleFromHeap stays unshared and annotateHandle / getDimensions stay block-local; - branch facts in the dominator-tree CSE: below a branch on c, c is known (and a switch case's value), so dominated compares fold; - in-place collapse of chained selects on the same condition; - removal of adjacent barriers the first one already covers; - in lanes.rs / prelude.rs / lower_valu.rs: constant EXEC lane-bit folds, single-instruction IEEE f32 compares, and constant fast paths for XCL_RDNA_FLOAT's FRC and legacy mul / fma. New XCL_DXIL_NO_OPT names: alloca, facts, hoist, barrier. Ported to main: the loop keeps main's passes (fold_guarded_selects, the trivial-phi pass after simplify_cfg) and main's back-edge check in every trivial-phi pass (positions recomputed after hoisting, CFG folding and merging; layout_positions). The XCL_HEAP_WINDOWS default flip of the original commit is left out. Needs the live double-ext scan of the commit below (xcl-dev#3266): without it, f64 ops the new passes remove leave DoubleExtensions declared and the validator rejects the module (fuzz seed 33). Ported from the IR part of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)). The native Frc of the XCL_RDNA_FLOAT fast path keeps the 0x3F7FFFFF clamp of the old lowering: on NVIDIA Frc rounds a tiny negative input to 1.0, which RDNA never returns (gpu_fract_f32_edges and f32_programs_on_the_gpu failed without it; the original commit was only run on AMD). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The IR part of amd-dev's DXIL size work. optimize() now repeats its passes (up to 4 times) while one of them still changes the function, and gains: - intra-block store-to-load forwarding and dead-store elimination for non-escaping scalar allocas (mostly the compact form's register slots), and removal of stores to allocas nothing loads; - hoisting of repeated constant-argument ReadNone intrinsics (e.g. dx.op.groupId) to the entry block; createHandleFromHeap stays unshared and annotateHandle / getDimensions stay block-local; - branch facts in the dominator-tree CSE: below a branch on c, c is known (and a switch case's value), so dominated compares fold; - in-place collapse of chained selects on the same condition; - removal of adjacent barriers the first one already covers; - in lanes.rs / prelude.rs / lower_valu.rs: constant EXEC lane-bit folds, single-instruction IEEE f32 compares, and constant fast paths for XCL_RDNA_FLOAT's FRC and legacy mul / fma. New XCL_DXIL_NO_OPT names: alloca, facts, hoist, barrier. Ported to main: the loop keeps main's passes (fold_guarded_selects, the trivial-phi pass after simplify_cfg) and main's back-edge check in every trivial-phi pass (positions recomputed after hoisting, CFG folding and merging; layout_positions). The XCL_HEAP_WINDOWS default flip of the original commit is left out. Needs the live double-ext scan of the commit below (xcl-dev#3266): without it, f64 ops the new passes remove leave DoubleExtensions declared and the validator rejects the module (fuzz seed 33). Ported from the IR part of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)). The native Frc of the XCL_RDNA_FLOAT fast path keeps the 0x3F7FFFFF clamp of the old lowering: on NVIDIA Frc rounds a tiny negative input to 1.0, which RDNA never returns (gpu_fract_f32_edges and f32_programs_on_the_gpu failed without it; the original commit was only run on AMD). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The IR part of amd-dev's DXIL size work. optimize() now repeats its passes (up to 4 times) while one of them still changes the function, and gains: - intra-block store-to-load forwarding and dead-store elimination for non-escaping scalar allocas (mostly the compact form's register slots), and removal of stores to allocas nothing loads; - hoisting of repeated constant-argument ReadNone intrinsics (e.g. dx.op.groupId) to the entry block; createHandleFromHeap stays unshared and annotateHandle / getDimensions stay block-local; - branch facts in the dominator-tree CSE: below a branch on c, c is known (and a switch case's value), so dominated compares fold; - in-place collapse of chained selects on the same condition; - removal of adjacent barriers the first one already covers; - in lanes.rs / prelude.rs / lower_valu.rs: constant EXEC lane-bit folds, single-instruction IEEE f32 compares, and constant fast paths for XCL_RDNA_FLOAT's FRC and legacy mul / fma. New XCL_DXIL_NO_OPT names: alloca, facts, hoist, barrier. Ported to main: the loop keeps main's passes (fold_guarded_selects, the trivial-phi pass after simplify_cfg) and main's back-edge check in every trivial-phi pass (positions recomputed after hoisting, CFG folding and merging; layout_positions). The XCL_HEAP_WINDOWS default flip of the original commit is left out. Needs the live double-ext scan of the commit below (xcl-dev#3266): without it, f64 ops the new passes remove leave DoubleExtensions declared and the validator rejects the module (fuzz seed 33). Ported from the IR part of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)). The native Frc of the XCL_RDNA_FLOAT fast path keeps the 0x3F7FFFFF clamp of the old lowering: on NVIDIA Frc rounds a tiny negative input to 1.0, which RDNA never returns (gpu_fract_f32_edges and f32_programs_on_the_gpu failed without it; the original commit was only run on AMD). main's lanes::ps_ballot_tests::direct_ps_mask_and_scc_counts_live_lanes_only split a block with a dead s_add so block-local CSE kept two identical waveActiveBallot(true) calls apart; the fixed-point loop runs CSE again after simplify_cfg merged that block away and folds them (correct: one block, no discard between). The test now exports the skipped s14, so its split stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The IR part of amd-dev's DXIL size work. optimize() now repeats its passes (up to 4 times) while one of them still changes the function, and gains: - intra-block store-to-load forwarding and dead-store elimination for non-escaping scalar allocas (mostly the compact form's register slots), and removal of stores to allocas nothing loads; - hoisting of repeated constant-argument ReadNone intrinsics (e.g. dx.op.groupId) to the entry block; createHandleFromHeap stays unshared and annotateHandle / getDimensions stay block-local; - branch facts in the dominator-tree CSE: below a branch on c, c is known (and a switch case's value), so dominated compares fold; - in-place collapse of chained selects on the same condition; - removal of adjacent barriers the first one already covers; - in lanes.rs / prelude.rs / lower_valu.rs: constant EXEC lane-bit folds, single-instruction IEEE f32 compares, and constant fast paths for XCL_RDNA_FLOAT's FRC and legacy mul / fma. New XCL_DXIL_NO_OPT names: alloca, facts, hoist, barrier. Ported to main: the loop keeps main's passes (fold_guarded_selects, the trivial-phi pass after simplify_cfg) and main's back-edge check in every trivial-phi pass (positions recomputed after hoisting, CFG folding and merging; layout_positions). The XCL_HEAP_WINDOWS default flip of the original commit is left out. Needs the live double-ext scan of the commit below (xcl-dev#3266): without it, f64 ops the new passes remove leave DoubleExtensions declared and the validator rejects the module (fuzz seed 33). Ported from the IR part of amd-dev's f089a9d (raylitebull, cherry-picked there from 46aecbf, Assisted-by: Antigravity (Gemini 4 Neon High)). The native Frc of the XCL_RDNA_FLOAT fast path keeps the 0x3F7FFFFF clamp of the old lowering: on NVIDIA Frc rounds a tiny negative input to 1.0, which RDNA never returns (gpu_fract_f32_edges and f32_programs_on_the_gpu failed without it; the original commit was only run on AMD). main's lanes::ps_ballot_tests::direct_ps_mask_and_scc_counts_live_lanes_only split a block with a dead s_add so block-local CSE kept two identical waveActiveBallot(true) calls apart; the fixed-point loop runs CSE again after simplify_cfg merged that block away and folds them (correct: one block, no discard between). The test now exports the skipped s14, so its split stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KOLESNiii
left a comment
There was a problem hiding this comment.
Static review of a343eafc for the stack in the #3041 comparison.
The relative-VGPR range fix still misses registers accessed only indirectly. The range is bounded by the largest register the program names directly. A relative write to v[0 + 7] followed by a relative read of that slot omits v7 if no instruction names it directly. This is an existing hole that remains in the measured revision and in the rebased copy under #3269. Tested lowering
Review assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
Note: the suite and smoke results below replace an earlier set that, by a test-setup mistake (shared cargo target directory), came from another PR's build. These were run with a forced rebuild of this head.
Overlaps #2037 and #2227 (movrel range / double-ext flags, both conflicting with main): this is amd-dev's version (
aac43438, raylitebull). Maintainers, keep one.Two direct DXIL fixes (#1894, #1890):
Module::uses_double_extensionslooked at every instruction ever built, so f64 ops removed by the optimizer still set theDoubleExtensionsshader flag. It now looks at the live ones (asinsts_use_typedoes).init.touchedis empty, soLw::top_vgprmissed VGPRs that a relative move can reach. It now includesmax_vgprover the whole program, andv_movrels/v_movreld/v_movrelsdmask M0 to M0[7:0] as RDNA2 does.What is in it
crates/xcl/src/gpu/dxil/module.rs,kernel.rs,lower.rs,lower_wide.rscrates/xcl/src/gpu/dxil/core_tests.rs:compute_movrel_uses_program_max_vgpr_and_masks_m0Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on 4a20b25: 2605 passed, 4 failed, 49 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3:E_OUTOFMEMORYfromCreateComputePipelineStateat seeds 70 / 545 / 1019 / 1507, the same as on main on this machine; they pass on Kalmarv's RTX 5070 Ti, so they come from this machine's driver / setup, not the code. SKIPPED GPU tests: 30, almost allno wave64.movreltest's shader stored nothing, so main's DCE removed what it checks (found by Kalmarv). It now stores the result, as in amd-dev's laterf089a9df.-StartupTimeoutSeconds 3600for the cold pipeline rebuild new DXIL needs.Regression run
main:
this PR:
Not tested
AI use
aac43438(raylitebull, from2c33f9f2, written with Antigravity (Gemini 4 Neon High)); ported without the neighbouring test offcbd0d14.🤖 Generated with Claude Code