Recompiler: simplify integer min/max (dx.op.binary.i32) via range bounds and absorption in direct DXIL opt #2568
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2568
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2568"
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?
@ramon-victor on GitHub · 2026-11-25 23:16 UTC · original
ramon-victor:opt/dxil-fold-int-minmax→main· +354 −0 · 1 files · 1 commits · openPart of #1269.
Problem
Module::simplify_opincrates/xcl/src/gpu/dxil/module/opt.rsdid not simplifydx.op.binary.i32integer min/max calls (IMax=37,IMin=38,UMax=39,UMin=40).In translated RDNA2 shaders, integer clamps (
v_med3_i32/v_med3_u32/v_med3_i16/v_med3_u16, each lowered as 4dx.op.binary.i32calls) and byte/half range clamps (v_cvt_pk_*,v_sat_pk_*) frequently receive constant bounds via SGPRs that only become constants aftermem2regpromotes them to SSA, or clamp values whose range is already constrained byand,lshr,ashr,zext,sext, or an outermin/max. Becausedx.op.binary.i32was opaque tosimplify_op, all 4 calls stayed live in the emitted DXIL.Fix
[lo, hi]interval helpersModule::unsigned_range_i32andModule::signed_range_i32(depth 4) incrates/xcl/src/gpu/dxil/module/opt.rs, tracking ranges acrossi32constants, constant-maskedAnd(requiring bit 31 clear for signed), constantLShr(shift>= 1for signed), constantAShr,ZExt/SExtfrom narrower widths,Select, and nesteddx.op.binary.i32min/max of matching signedness.Module::simplify_int_minmaxcalled fromModule::simplify_opondx.op.binary.i32(37..=40), folding:min(x, x) -> x,max(x, x) -> x).min(min(x, y), x) -> min(x, y),min(max(x, y), x) -> x,max(min(x, y), x) -> x,max(max(x, y), x) -> max(x, y)).ha <= lb/hb <= lafor min;la >= hb/lb >= hafor max), which subsumes constant folding, identity/absorbing bounds (0,u32::MAX,i32::MIN,i32::MAX), redundant byte/half clamps, and collapses every permutation of constant-boundv_med3_i32/v_med3_u32from 4 calls down to 2 (or 1 whenlo == 0/i32::MINorhi == u32::MAX/i32::MAX) automatically aftermem2reg.opt::int_minmax_tests(including soundness check thatimax(x & 0x8000_00FF, 0)is not folded).Measured impact
573-program retail direct-DXIL validation sweep (
dxil.dll1.8.2502.11):6d12f58):573/573validated (val_fail=0),51,117,488total DXIL bytes (p50=22,865 us,p95=408,132 us).4094ff9):573/573validated (val_fail=0),50,984,004total DXIL bytes (-133,484 B/-0.261%;p50=21,870 us,p95=419,075 us).Tested
cargo test --lib -p xcl int_minmax): 2 passed, 0 failed (simplify_int_minmax_folds_bounds_absorption_and_clamps,med3_via_sgpr_bounds_collapses_and_matches_gpu)..\scripts\test.ps1, NVIDIA GeForce RTX 3070, Windows 11):1425 passed, 0 failed, 46 ignored.dxil.dllvalidation sweep:573/573passed,0failures.cargo build --release -p xcl) and 60 s retail smoke run (see below).Not tested
Regression run
Main (
f087b99):This PR (
4094ff9):AI use
@DavidM1911 on GitHub · 2026-11-25 23:28 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.Thanks!
— Devin
@DarkPanda69 on GitHub · 2026-11-25 23:37 UTC · original
Wave64 run (listed as untested; the wave64 GPU tests skipped on the RTX 3070) on an AMD RX 9070 XT, plus an RTX 3060: both new tests pass, and nothing else changes in the direct-DXIL GPU suite.
Head
4094ff9applied onmain08db802, debug, Windows 11 Pro 26200,XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4onmainand with the PR, card chosen withXCL_ADAPTER:mainOn both cards, the only result changes against
mainare the newsimplify_int_minmax_folds_bounds_absorption_and_clampsandmed3_via_sgpr_bounds_collapses_and_matches_gpu, both ok, with no new skips.med3_via_sgpr_bounds_collapses_and_matches_gputranslates withwave64: false, so its own GPU run is wave32. The wave64 coverage comes from the rest of the suite, which runs through this optimizer pass: on the RTX 3060, 21 wave64 cases skip. On the RX 9070 XT, 18 of them ran with this PR applied and still pass; the other 3 are per-lane forms refused on both cards. The 2 RX 9070 XT failures are the AMD fuzz seeds tracked in #2115, the same onmain.Not tested: Intel, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
@luckyteagirl on GitHub · 2026-11-26 00:11 UTC · original
Independent RX 6800M focused report for exact PR head
4094ff9cb9c3eea2af33f2556dae05a28987bb05(clean detached worktree).Tested
30.0.13002.13003; Ryzen 9 5980HX; Windows 11 Home build 26200; Rust1.99.0MSVC; DXC1.9.2609.5.XCL_ADAPTER=6800M XCL_REQUIRE_GPU=1 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 1 med3_via_sgpr_bounds_collapses_and_matches_gpu -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 skipped (1325filtered out). No explicitSKIPPEDrecords. The fixture’s kernel uses the wave32 form and checks the RDNA2 SGPR-bound med3 clamp against GPU results; it does not test the native wave64 form. Resource guard: none. Log:filter-med3-via-sgpr-bounds-gpu-retry.log.Not tested
AI use
github-bot referenced this pull request2026-11-26 12:40:17 +00:00
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.