[llvm-branch-commits] [llvm] InstCombine: Fold known-qnan results to a literal nan (PR #176123)

Yingwei Zheng via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 15 08:55:07 PST 2026


================
@@ -2013,21 +2013,24 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest Mask,
   if (Mask == fcPosZero)
     return Constant::getNullValue(Ty);
 
-  // Turn any possible snans into quiet if we can.
-  if (Mask == fcNan && IsCanonicalizing)
-    return ConstantFP::getQNaN(Ty);
-
   // TODO: Support aggregate types that are allowed by FPMathOperator.
   if (Ty->isAggregateType())
     return nullptr;
 
+  // Turn any possible snans into quiet if we can.
+  if (Mask == fcNan && IsCanonicalizing)
+    return ConstantFP::getQNaN(Ty);
+
   switch (Mask) {
   case fcNegZero:
     return ConstantFP::getZero(Ty, true);
   case fcPosInf:
     return ConstantFP::getInfinity(Ty);
   case fcNegInf:
     return ConstantFP::getInfinity(Ty, true);
+  case fcQNan:
----------------
dtcxzyw wrote:

It is identical to modifying the check `Mask == fcNan` to (Mask & fcQNan) != fcNone. BTW, can we just return a poison when Mask == fcSNan && IsCanonicalizing?

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


More information about the llvm-branch-commits mailing list