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

Wooseok Lee via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 08:48:14 PDT 2026


================
@@ -405,16 +405,22 @@ bool GCNTTIImpl::canSimplifyLegacyMulToMul(const Instruction &I,
   // cases then we can use a normal multiply instead.
   // TODO: Create and use isKnownFiniteNonZero instead of just matching
   // constants here.
----------------
wooseoklee wrote:

Is it fine for us to directly use the KnownFPClass in this function as follows? 

bool GCNTTIImpl::canSimplifyLegacyMulToMul(const Instruction &I,
                                           const Value *Op0, const Value *Op1,
                                           InstCombiner &IC) const {
  // 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.
  SimplifyQuery SQ = IC.getSimplifyQuery().getWithInstruction(&I);
  KnownFPClass Known0 = computeKnownFPClass(Op0, fcZero | fcInf | fcNan, SQ);
  KnownFPClass Known1 = computeKnownFPClass(Op1, fcZero | fcInf | fcNan, SQ);
  if (I.hasNoSignedZeros()) {
    if ((Known0.isKnownNeverZero() && Known0.isKnownNeverInfOrNaN()) ||
        (Known1.isKnownNeverZero() && Known1.isKnownNeverInfOrNaN())) {
      // One operand is not zero or infinity or NaN.
      return true;
    }
    if (Known0.isKnownNeverInfOrNaN() && Known1.isKnownNeverInfOrNaN()) {
      // Neither operand is infinity or NaN.
      return true;
    }
  } else {
    if (Known0.isKnownNeverZero() && Known1.isKnownNeverZero()) {
      // Neither operand is zero.
      return true;
    }
  }
  return false;
}

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


More information about the llvm-commits mailing list