Recompiler: v_fma_legacy_f32 / v_fmac_legacy_f32 return -0 for a zero product plus -0 #679
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#679
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@joeypercia on GitHub · 2026-11-24 03:21 UTC · original
v_fma_legacy_f32/v_fmac_legacy_f32with a zero factor returncitself; the hardware returnsc + (+0), which is+0whencis-0(the legacy product of ±0 with anything, inf and NaN included, is+0). LLVM spells this case out in itsamdgcn_fma_legacyfolding (AMDGPUInstCombineIntrinsic.cpp): "It's tempting to just return Op2 here, but that would give the wrong result if Op2 was -0.0."XCL (
emit.rs):Measured on
maincb868b2, new testgpu_fma_legacy_with_a_zero_factor_adds_plus_zero, RTX 4070 Ti (616.56) and AMD RDNA2 iGPU (26.11.2), same on both: 6 of 14 wrong, all-0(0x80000000) where+0is right:fma_legacyandfmac_legacyof(0, inf, -0),(-0, 5, -0),(0, NaN, -0). Zero times inf / NaN plus a non-zeroc, and the plain case, are already right.Fix — note the obvious one doesn't work:
select(c == 0.0f, 0.0f, c)still returns-0on both GPUs, because DXC's relaxed float math folds it back toc(+0 == -0). On the bits it holds:With it the test passes on both GPUs (wave64 and wave32).
Low impact: only the sign of a zero result changes, which matters only where something later divides by it or takes its sign. I'll open the PR with the test and fix; it needs the
xcl-smokeruns from someone with a title.AI use: Claude Code (Claude Opus 5.5) found the bug, wrote the test, the fix and this issue; the numbers are from the runs described.