Recompiler: generalize bitmask and zero-shift folding via known_nonzero_bits #2557
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!2557
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2557"
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 22:50 UTC · original
ramon-victor:opt/dxil-known-nonzero-bits→main· +323 −40 · 1 files · 1 commits · openPart of #1269.
Problem
Module::simplify_opincrates/xcl/src/gpu/dxil/module/opt.rspreviously only recognized single-hopandmasks overlshr,shl,andwith a constant, orzext(i1). Multi-instruction bit-packing sequences common in translated RDNA2 shaders (or/xor/select/add/mulof byte/half masks,zextof wider sub-32-bit integers,dx.op.binary.i32(UMin/UMax),dx.op.unaryBits.i32(Countbits), non-constant disjointand, and shifts that shift out all possibly-nonzero bits) missed mask elision and zero-shift folding.Fix
Module::known_nonzero_bits(&self, v: Value, w: u32, depth: u8) -> u64(crates/xcl/src/gpu/dxil/module/opt.rs), computing a conservative bitmask of bits that may be1for integer widths1..=32up to depth 4 (leaving 64-bit values untouched soInt64Opsflags stay consistent).And,Or,Xor,LShr,Shl, non-negativeAShr, disjoint/non-overflowingAdd,Mul(trailing-zero and non-overflowing product bounds), constant-divisorUDiv/URem,Select,ZExt,Trunc,dx.op.binary.i32(UMax,UMinvia highest-possible-bit fill), anddx.op.unaryBits.i32(Countbits→0x3F).BinOp::Andspecial cases inModule::simplify_opwith the generalknown_nonzero_bitscheck (covering both redundant masks and disjoint non-constantand→0), and foldLShr,Shl, and sign-bit-zeroAShrto0when all possibly-nonzero bits are shifted out.opt::known_bits_tests, including soundness checks verifying thatumin(x & 0x100, y) & 0xFFand sign-unknownashrare not erroneously 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).2a1fadc):573/573validated (val_fail=0),51,111,472total DXIL bytes (-6,016 B/-0.012%;p50=20,048 us,p95=376,645 us).Tested
cargo test --lib -p xcl module::opt): 9 passed, 0 failed (known_nonzero_bits_folds_compound_masks_and_shifts,known_nonzero_bits_gpu_parity, plus all 7 existingopttests)..\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 (
2a1fadc):AI use
@upipibi on GitHub · 2026-11-25 23:12 UTC · original
NVIDIA test report for
2a1fadc: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug.cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4(thehle::xaudio2tests hang on this machine, also onmain):2a1fadc: 1291 passed, 0 failed, 26 ignored.mainate1d84b7(this PR's base): 1289 passed, 0 failed, 26 ignored.SKIPPEDlines on both sides (no wave64 etc.).Lib tests only; no title run.
AI-assisted (Claude Code, Claude Opus 5.5).
@DarkPanda69 on GitHub · 2026-11-25 23:12 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
2a1fadcapplied onmaine1d84b7, 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 newknown_nonzero_bits_folds_compound_masks_and_shiftsandknown_nonzero_bits_gpu_parity, both ok, with no new skips.known_nonzero_bits_gpu_parityitself runs a wave32 kernel. The wave64 coverage here comes from the rest of the suite: on the RTX 3060, 21 wave64 cases skip. On the RX 9070 XT, 18 of them ran over the new folding 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.
@emirduran707 on GitHub · 2026-11-25 23:16 UTC · original
Independent AMD RDNA4 (native wave64) verification of exact PR head
2a1fadcf8eb4c67079e0b1646528a8603c804be7on Windows 11 Pro 26300 (AMD Radeon RX 9060 XT 16 GB, driver32.0.31044.16, Ryzen 5 5600, Rust 1.100.0 MSVC, DXC1.9.2602.17).Tested
cargo build --workspace(debug): passed (0errors).cargo test --workspace --no-fail-fast -- --test-threads=4:1423 passed, 2 failed, 46 ignored(8 SKIPPED: 6 per-lane DXIL forms refused by host adapter/driver, 1heap_window_out_of_memory_falls_back_to_the_switch_formno heap windows, 1pso_measurement_compiles_an_exact_synthetic_recordWindows Developer Mode off).gpu::dxil::module::opt::known_bits_tests::known_nonzero_bits_folds_compound_masks_and_shiftsgpu::dxil::module::opt::known_bits_tests::known_nonzero_bits_gpu_paritygpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1andfuzz_validate_and_gpu_3) are pre-existing on unmodifiedmainon this RX 9060 XT / driver32.0.31044.16.cargo build --release -p xcl+ 60 s retail-title smoke test (scripts/smoke.ps1, offline):(Compare against
main68a284aon this machine:1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
@DavidM1911 on GitHub · 2026-11-25 23:19 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
@SlopTart on GitHub · 2026-11-25 23:41 UTC · original
Tested: current PR head merged onto current
origin/main(clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo targetx86_64-pc-windows-gnurun under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).gpu_suite (cold cache): 166 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. This PR does not change the mad/mac red on RADV.known_nonzero_bits_gpu_parityran inside the suite. Targeted run ofknown_nonzero_bits_folds_compound_masks_and_shifts(IR-level, outside thegpu_filter): passed.Not tested: retail titles (no title data on this lane, counts only).
AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
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.