[llvm] [AMDGPU] Fix fmul/fma legacy sign-of-zero miscompile (PR #203567)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 21 05:41:00 PDT 2026


================
@@ -404,17 +404,21 @@ bool GCNTTIImpl::canSimplifyLegacyMulToMul(const Instruction &I,
   // The legacy behaviour is that multiplying +/-0.0 by anything, even NaN or
   // infinity, gives +0.0. If we can prove we don't have one of the special
   // cases then we can use a normal multiply instead.
-  // TODO: Create and use isKnownFiniteNonZero instead of just matching
-  // constants here.
-  if (match(Op0, PatternMatch::m_FiniteNonZero()) ||
-      match(Op1, PatternMatch::m_FiniteNonZero())) {
-    // One operand is not zero or infinity or NaN.
-    return true;
-  }
-
   SimplifyQuery SQ = IC.getSimplifyQuery().getWithInstruction(&I);
-  if (isKnownNeverInfOrNaN(Op0, SQ) && isKnownNeverInfOrNaN(Op1, SQ)) {
-    // Neither operand is infinity or NaN.
+  KnownFPClass Known0 = computeKnownFPClass(Op0, fcZero | fcInf | fcNan, SQ);
+  KnownFPClass Known1 = computeKnownFPClass(Op1, fcZero | fcInf | fcNan, SQ);
+  if (I.hasNoSignedZeros()) {
+    if ((Known0.isKnownNeverZero() && Known0.isKnownNeverInfOrNaN()) ||
----------------
arsenm wrote:

This would need to be isKnownNeverLogicalZero (we should probably remove isKnownNeverZero, it's a constantly misused hazard)

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


More information about the llvm-commits mailing list