[llvm] [VPlan] Support multiple F(Max|Min)Num reductions. (PR #161735)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 5 02:04:05 PST 2025


================
@@ -879,52 +867,72 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
   }
 
   VPBasicBlock *LatchVPBB = LoopRegion->getExitingBasicBlock();
+  VPBasicBlock *MiddleVPBB = Plan.getMiddleBlock();
+  VPBuilder MiddleBuilder(MiddleVPBB, MiddleVPBB->begin());
   VPBuilder Builder(LatchVPBB->getTerminator());
-  auto *LatchExitingBranch = cast<VPInstruction>(LatchVPBB->getTerminator());
-  assert(LatchExitingBranch->getOpcode() == VPInstruction::BranchOnCount &&
+  VPValue *AnyNaN = nullptr;
+  SmallPtrSet<VPValue *, 2> RdxResults;
+  for (VPReductionPHIRecipe *RedPhiR : ReductionsToConvert) {
+    assert(RecurrenceDescriptor::isFPMinMaxNumRecurrenceKind(
+               RedPhiR->getRecurrenceKind()) &&
+           "unsupported reduction");
+
+    VPValue *MinMaxOp = GetMinMaxCompareValue(RedPhiR);
+    if (!MinMaxOp)
+      return false;
+
+    VPValue *IsNaN = Builder.createFCmp(CmpInst::FCMP_UNO, MinMaxOp, MinMaxOp);
+    VPValue *HasNaN = Builder.createNaryOp(VPInstruction::AnyOf, {IsNaN});
----------------
ayalz wrote:

The original `AnyNaN` indicates if any lane is NaN, better rename it `AnyNaNLane` rather than `HasNaN`?
The new `AnyNaN` indicates if any (lane of any) MinMaxNum reduction is NaN, better call it `AnyNaNReduction` rather than redefining `AnyNaN`?

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


More information about the llvm-commits mailing list