[all-commits] [llvm/llvm-project] 1dd968: [AMDGPU] Fix fmul/fma legacy sign-of-zero miscompi...
Wooseok Lee via All-commits
all-commits at lists.llvm.org
Thu Jul 30 09:20:23 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 1dd9687d41e1331996ece0839e58673ab4d8e10f
https://github.com/llvm/llvm-project/commit/1dd9687d41e1331996ece0839e58673ab4d8e10f
Author: Wooseok Lee <wolee at amd.com>
Date: 2026-07-30 (Thu, 30 Jul 2026)
Changed paths:
M llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
M llvm/test/Transforms/InstCombine/AMDGPU/fma_legacy.ll
M llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll
Log Message:
-----------
[AMDGPU] Fix fmul/fma legacy sign-of-zero miscompile (#203567)
V_MUL_LEGACY_F32 always returns +0.0 when either operand is ±0.0 or a
denormal treated as zero, while IEEE fmul XORs operand signs. This makes
results observably different when one operand is a runtime ±0.0:
fmul.legacy(-2.0, +0.0) = +0.0 (legacy zero clause forces +0.0)
fmul (-2.0, +0.0) = -0.0 (IEEE sign XOR: - * + = -)
The previous code folded whenever one operand matched m_FiniteNonZero()
or both were known never Inf/NaN, without accounting for sign-of-zero
divergence on the other operand.
Restructure the guard:
- Always safe: both operands are known never zero (legacy zero clause
cannot fire). Uses isKnownNeverLogicalZero to correctly account for
denormals flushed to zero under the function's f32 denormal mode.
- With nsz (sign-of-zero is don't-care), two additional cases apply:
1. One operand is not zero or infinity or NaN: zero clause cannot fire
on that side, and 0*Inf/0*NaN (where legacy returns +0.0 but IEEE
returns NaN) is excluded.
2. Neither operand is infinity or NaN: 0*Inf and 0*NaN cases excluded,
nsz covers any sign-of-zero difference from the zero clause.
A single condition captures both cases.
- Compute Known1 lazily: bail before the second computeKnownFPClass call
if Op0 may be zero and nsz is not set, since Op1 cannot help.
Update fmul_legacy.ll and fma_legacy.ll to reflect the corrected
behavior: cases that previously folded without nsz now require it or
require both operands to be provably non-zero.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list