From 29a42c58a082c7112f5a523e56eb0b6a9eb09b25 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 28 Nov 2026 22:35:13 +0100 Subject: [PATCH] dxil: avoid AMD Bfrev.i32 miscompile AMD's RDNA3/4 driver can compute Bfrev.i32 as x | bfrev(x) for some computed values (fuzz seed 1599). Use the group-swap sequence already used for the i64 halves. This makes both reduced countbits/Bfrev variants and the full seed 1599 pass on RX 9070 XT. Seed 722 remains a separate divergent-switch/WaveReadLaneFirst issue. Commit identity is local to this worktree because no identity was configured. --- crates/xcl/src/gpu/dxil/ops.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/xcl/src/gpu/dxil/ops.rs b/crates/xcl/src/gpu/dxil/ops.rs index cf7d47b145..0949a5c066 100644 --- a/crates/xcl/src/gpu/dxil/ops.rs +++ b/crates/xcl/src/gpu/dxil/ops.rs @@ -333,6 +333,12 @@ impl Shader { let rhi = self.m.cast(CastOp::ZExt, rhi, t); return self.m.bin(BinOp::Or, rlo, rhi); } + // AMD's driver also returns `x | bfrev(x)` for some `Bfrev.i32(values of a + // computed i64 expression)` and for `Bfrev.i32(countbits(...))` (fuzz seed 1599). + // The group-swap sequence is exact on every adapter and only costs a few ALU ops. + if t == self.m.i32() { + return self.bfrev32_shifts(v); + } self.op(30, "unary", Some(t), t, &[v], FnAttrs::ReadNone) }