Recompiler: avoid AMD Bfrev.i32 miscompile #3225
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3225"
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 JulienReppert on 2026-11-28T22:51:44Z.
AMD's RDNA4 driver can compute
Bfrev.i32(x)asx | bfrev(x)for some values (direct-DXIL fuzz seed 1599). Route i32 bit reversal through the shift-and-mask sequence already used for the halves ofBfrev.i64. The emitted DXIL still validates and matches DXC's intrinsic attributes.What is in it
crates/xcl/src/gpu/dxil/ops.rs: usebfrev32_shiftsfor i32 values instead of theBfrevDXIL op.Tested
x86_64-pc-windows-msvc).cargo build --workspace: passed.cargo test --workspace -- --test-threads=4: 2453 passed, 2 failed, 29 ignored, 0 measured. SKIPPED GPU tests: 8.7db2f391on the same host: 2452 passed, 3 failed, 29 ignored, 0 measured. This change fixesfuzz_validate_and_gpu_3;fuzz_validate_and_gpu_1andgpu_ps_readfirstlane_loop_on_a_primitive_edge_endsstill fail on clean upstream.cargo test -p xcl --lib fuzz_validate_and_gpu -- --nocapture --test-threads=1: 3 passed, 1 failed; the remaining failure is seed 722 (WaveReadLaneFirstafter a divergent switch), not this code path.Regression run
Not tested
Bfrev.i32lowering; the evidence here is the direct-DXIL GPU fuzz test.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:23:40Z.
Review (head
29a42c58, diff read, not a merge-check; draft):bfrev(gpu/dxil/ops.rs~333) now lowers every i32 bit reversal to the shift-and-mask sequence: about 17 ALU ops instead of oneBfrev, on NVIDIA and Intel too, whereBfrev.i32is correct. It's probably cheap where it's used (lower.rs~748), but nothing measures it. If the direct translator ever gets a vendor in its cache identity, gating this on AMD would keep the single op elsewhere; otherwise say in the comment that it's deliberate.fuzz_validate_and_gpu_3passing on an RDNA4 card, which needs AMD hardware. A DXIL-level test that no i32Bfrev(op 30) is emitted, beside the existing fuzz reductions infuzz_tests.rs(~1316-1353), would run on every machine.Bfrevdirectly. Whether AMD's driver has the same issue there is untested (unverified).Fine: the i64 path already used
bfrev32_shiftsfor its halves for the same driver bug (fuzz seed 817), so this reuses a known-exact sequence.ops.rsis undersrc/gpu/dxil, which the direct-DXIL cache identity hashes, so no stale DXIL is served. The PR's smoke pair on the 9070 XT is flat.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:45:25Z.
Triage (#1607) – head
29a42c5#2231 targets the same AMD miscompile (fuzz seed 1599) by constant-folding
Countbitsof constants inbit_count. This PR instead routes everyBfrev.i32through the existingbfrev32_shiftssequence inops::bfrev, which also covers non-constant inputs. These are different approaches, not duplicates.The change is exact on every adapter (the same sequence already reverses the halves of
Bfrev.i64). No new test; it relies on the existingfuzz_validate_and_gpuseed 1599 and the AMD reduction infuzz_tests.rs.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.