[llvm] [AMDGPU] Fix performFMACombine FDOT2 fold ignoring denormal mode (PR #205101)

Wooseok Lee via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 06:36:28 PDT 2026


wooseoklee wrote:

> > On AMDGPU, PreserveSign means "denormals flushed to zero with unknown or positive sign", so v_fma_mix_f32 and v_dot2c produce the same sign of zero for flushed results.
> 
> No, this doesn't make any sense. There is no ambiguity.

AFAIK, PreserveSign is for keeping the original sign after FTZ while PostiveZero unconditionally produce +0.0 after FTZ. As you pointed in another PR, AMD is only using PreserveSign and not using PositiveZero. This contracts the hardware behavior of v_dot2c and v_fma_mix as they unconditionally +0.0 under PreserveSign. I confirmed the behavior on gfx90a and gfx950.

Inputs: a.x = -2^-24 (negative f16 subnormal 0x8001), b.x = +2^-14 (positive f16 min normal 0x0400)
Mathematically correct product: -2^-38 = 0xac800000 (negative normal f32)

GPU	Instruction	ieee=1	ieee=0	denorm_flush
gfx90a	v_dot2c_f32_f16	0x00000000 (+0.0)	0x00000000 (+0.0)	0x00000000 (+0.0)
gfx90a	v_dot2_f32_f16	0x00000000 (+0.0)	0x00000000 (+0.0)	0x00000000 (+0.0)
gfx90a	v_fma_mix_f32	0xac800000 (normal)	0xac800000 (normal)	0x00000000 (+0.0)
gfx950	v_dot2c_f32_f16	0xac800000 (normal)	0xac800000 (normal)	0xac800000 (normal)
gfx950	v_dot2_f32_f16	0xac800000 (normal)	0xac800000 (normal)	0xac800000 (normal)
gfx950	v_fma_mix_f32	0xac800000 (normal)	0xac800000 (normal)	0x00000000 (+0.0)

> > v_fma_mix_f32 flushes negative denormals to -0.0 while v_dot2c always flushes to +0.0.
> 
> Can you write out the full expression's evaluation? Is the 0 behavior just the standard consequence of what FMA would do?

I think I describe this as my wrong assumption based on the PreserveSign and PositiveZero distinction. 
".. the assumption that under PreserveSign mode, v_fma_mix_f32 flushes negative denormals to -0.0 while v_dot2c always flushes to +0.0. However, hardware testing on gfx90a showed that both v_fma_mix_f32 and v_dot2c produce +0.0 for a negative f32 denormal under PreserveSign mode."

https://github.com/llvm/llvm-project/pull/205101


More information about the llvm-commits mailing list