[llvm] [InstCombine] Enable factorizeMinMaxTree for floating-point values (PR #193195)

Thomas Fry via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 02:56:38 PDT 2026


================
@@ -1481,7 +1481,23 @@ static Instruction *factorizeMinMaxTree(IntrinsicInst *II) {
   Module *Mod = II->getModule();
   Function *MinMax =
       Intrinsic::getOrInsertDeclaration(Mod, MinMaxID, II->getType());
-  return CallInst::Create(MinMax, { MinMaxOp, ThirdOp });
+  Instruction *RetI = CallInst::Create(MinMax, {MinMaxOp, ThirdOp});
+  if (isa<FPMathOperator>(II)) {
+    FastMathFlags IIFMF = II->getFastMathFlags();
+    FastMathFlags FoldedOpFMF =
+        (MinMaxOp == LHS ? RHS : LHS)->getFastMathFlags();
+    FastMathFlags RetFMF = IIFMF & FoldedOpFMF;
+    // Different intrinsics handle NaN propagation differently. For maximum and
----------------
thofry wrote:

Ah, thanks! I hadn't considered that and it in fact does not hold.
Consider `m1(m2(sNaN, 1), m3(2, 1)) -> m4(m2(sNaN, 1), 2)`
We clearly can't copy `nnan` from `m3` to `m4`

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


More information about the llvm-commits mailing list