[llvm] [InstCombine] Add an additional nnan constraint for xfrm fcmp + sel => fmax/fmin (PR #117977)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 29 06:27:54 PST 2024


================
@@ -3864,17 +3864,25 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
   if (SIFPOp) {
     // TODO: Try to forward-propagate FMF from select arms to the select.
 
+    auto *FCmp = dyn_cast<FCmpInst>(CondVal);
+
     // Canonicalize select of FP values where NaN and -0.0 are not valid as
     // minnum/maxnum intrinsics.
     if (SIFPOp->hasNoNaNs() && SIFPOp->hasNoSignedZeros()) {
       Value *X, *Y;
-      if (match(&SI, m_OrdOrUnordFMax(m_Value(X), m_Value(Y))))
-        return replaceInstUsesWith(
-            SI, Builder.CreateBinaryIntrinsic(Intrinsic::maxnum, X, Y, &SI));
+      if (match(&SI, m_OrdOrUnordFMax(m_Value(X), m_Value(Y)))) {
+        Value *BinIntr =
+            Builder.CreateBinaryIntrinsic(Intrinsic::maxnum, X, Y, &SI);
+        cast<Instruction>(BinIntr)->setHasNoNaNs(FCmp->hasNoNaNs());
----------------
dtcxzyw wrote:

`BinIntr` may be folded into a constant by IRBuilder.

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


More information about the llvm-commits mailing list