[llvm] [LV] Vectorize fmin/fmax reductions (PR #198300)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 28 08:49:56 PDT 2026


================
@@ -2252,7 +2266,9 @@ bool VPlanTransforms::handleMultiUseReductions(VPlan &Plan,
     VPBuilder B(FindIVRdxResult);
     VPValue *MinOrMaxExiting = MinOrMaxResult->getOperand(0);
     auto *FinalMinOrMaxCmp =
-        B.createICmp(CmpInst::ICMP_EQ, MinOrMaxExiting, MinOrMaxResult);
+        (RecurrenceDescriptor::isIntegerRecurrenceKind(RdxKind))
+            ? B.createICmp(CmpInst::ICMP_EQ, MinOrMaxExiting, MinOrMaxResult)
+            : B.createFCmp(CmpInst::FCMP_OEQ, MinOrMaxExiting, MinOrMaxResult);
----------------
fhahn wrote:

I don't think that will work correctly at least for FMinimum, FMaximum, which propagate NaN. If any input lane is NaN, then `MinOrMaxResult` will be NaN, and `OEQ` will always be false, and we incorrectly select the first lane.

 Not sure if all cases covered in the PR are covered by https://github.com/llvm/llvm-test-suite/blob/main/SingleSource/UnitTests/Vectorizer/argmin-argmax-fp.cpp, but if not it would be good to make sure they are covered first, so it is easier to catch issues

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


More information about the llvm-commits mailing list