[llvm] [LV] Vectorize FMax via OrderedFCmpSelect w/o fast-math flags. (PR #146711)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 6 10:06:30 PDT 2025
================
@@ -654,7 +654,105 @@ void VPlanTransforms::attachCheckBlock(VPlan &Plan, Value *Cond,
}
}
-bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
+static bool handleOrderedFCmpSelect(VPlan &Plan,
+ VPReductionPHIRecipe *RedPhiR) {
+ VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
+ VPWidenIntOrFpInductionRecipe *WideIV = nullptr;
+
+ // MaxOp feeding the reduction phi must be a select (either wide or a
+ // replicate recipe), where the phi is the last operand, and the compare
+ // predicate is strict. This ensures NaNs won't get propagated unless the
+ // initial value is NaN
+ auto *MaxOp = dyn_cast<VPRecipeWithIRFlags>(
+ RedPhiR->getBackedgeValue()->getDefiningRecipe());
+ if (!MaxOp)
+ return false;
+ auto *RepR = dyn_cast<VPReplicateRecipe>(MaxOp);
+ if (!isa<VPWidenSelectRecipe>(MaxOp) &&
+ !(RepR && (isa<SelectInst>(RepR->getUnderlyingInstr()))))
+ return false;
+
+ auto *Cmp = cast<VPRecipeWithIRFlags>(MaxOp->getOperand(0));
+ if (MaxOp->getOperand(1) == RedPhiR ||
+ !CmpInst::isStrictPredicate(Cmp->getPredicate()))
----------------
ayalz wrote:
Better also make sure the operands of the strict Cmp are in the expected order - same as in the select MaxOp rather than flipped, and that Cmp isOrdered? I.e., OGT or OLT, excluding UGT and ULT.
https://github.com/llvm/llvm-project/pull/146711
More information about the llvm-commits
mailing list