[llvm] 8a8d65a - [VPlan] Consistently use MinOrMax* in VPlanConstruction transforms (NFC)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 14 13:19:47 PST 2026


Author: Florian Hahn
Date: 2026-01-14T21:19:24Z
New Revision: 8a8d65a0c59ab4d32eaded05fda0ce2ffdd25c39

URL: https://github.com/llvm/llvm-project/commit/8a8d65a0c59ab4d32eaded05fda0ce2ffdd25c39
DIFF: https://github.com/llvm/llvm-project/commit/8a8d65a0c59ab4d32eaded05fda0ce2ffdd25c39.diff

LOG: [VPlan] Consistently use MinOrMax* in VPlanConstruction transforms (NFC)

Make sure variables/functions consistently use MinOrMax*, as suggested
in https://github.com/llvm/llvm-project/pull/170223. Split off from the
PR.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
index bf8b0461e3b1b..7ee133545eeb9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
@@ -1135,30 +1135,31 @@ template <unsigned Opcode> static VPInstruction *findUserOf(VPValue *V) {
 }
 
 bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
-  auto GetMinMaxCompareValue = [](VPReductionPHIRecipe *RedPhiR) -> VPValue * {
-    auto *MinMaxR =
+  auto GetMinOrMaxCompareValue =
+      [](VPReductionPHIRecipe *RedPhiR) -> VPValue * {
+    auto *MinOrMaxR =
         dyn_cast_or_null<VPRecipeWithIRFlags>(RedPhiR->getBackedgeValue());
-    if (!MinMaxR)
+    if (!MinOrMaxR)
       return nullptr;
 
-    // Check that MinMaxR is a VPWidenIntrinsicRecipe or VPReplicateRecipe
+    // Check that MinOrMaxR is a VPWidenIntrinsicRecipe or VPReplicateRecipe
     // with an intrinsic that matches the reduction kind.
     Intrinsic::ID ExpectedIntrinsicID =
         getMinMaxReductionIntrinsicOp(RedPhiR->getRecurrenceKind());
-    if (!match(MinMaxR, m_Intrinsic(ExpectedIntrinsicID)))
+    if (!match(MinOrMaxR, m_Intrinsic(ExpectedIntrinsicID)))
       return nullptr;
 
-    if (MinMaxR->getOperand(0) == RedPhiR)
-      return MinMaxR->getOperand(1);
+    if (MinOrMaxR->getOperand(0) == RedPhiR)
+      return MinOrMaxR->getOperand(1);
 
-    assert(MinMaxR->getOperand(1) == RedPhiR &&
+    assert(MinOrMaxR->getOperand(1) == RedPhiR &&
            "Reduction phi operand expected");
-    return MinMaxR->getOperand(0);
+    return MinOrMaxR->getOperand(0);
   };
 
   VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
   SmallVector<std::pair<VPReductionPHIRecipe *, VPValue *>>
-      MinMaxNumReductionsToHandle;
+      MinOrMaxNumReductionsToHandle;
   bool HasUnsupportedPhi = false;
   for (auto &R : LoopRegion->getEntryBasicBlock()->phis()) {
     if (isa<VPCanonicalIVPHIRecipe, VPWidenIntOrFpInductionRecipe>(&R))
@@ -1175,14 +1176,14 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
       continue;
     }
 
-    VPValue *MinMaxOp = GetMinMaxCompareValue(Cur);
-    if (!MinMaxOp)
+    VPValue *MinOrMaxOp = GetMinOrMaxCompareValue(Cur);
+    if (!MinOrMaxOp)
       return false;
 
-    MinMaxNumReductionsToHandle.emplace_back(Cur, MinMaxOp);
+    MinOrMaxNumReductionsToHandle.emplace_back(Cur, MinOrMaxOp);
   }
 
-  if (MinMaxNumReductionsToHandle.empty())
+  if (MinOrMaxNumReductionsToHandle.empty())
     return true;
 
   // We won't be able to resume execution in the scalar tail, if there are
@@ -1210,9 +1211,9 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
   VPBuilder LatchBuilder(LatchVPBB->getTerminator());
   VPValue *AllNaNLanes = nullptr;
   SmallPtrSet<VPValue *, 2> RdxResults;
-  for (const auto &[_, MinMaxOp] : MinMaxNumReductionsToHandle) {
+  for (const auto &[_, MinOrMaxOp] : MinOrMaxNumReductionsToHandle) {
     VPValue *RedNaNLanes =
-        LatchBuilder.createFCmp(CmpInst::FCMP_UNO, MinMaxOp, MinMaxOp);
+        LatchBuilder.createFCmp(CmpInst::FCMP_UNO, MinOrMaxOp, MinOrMaxOp);
     AllNaNLanes = AllNaNLanes ? LatchBuilder.createOr(AllNaNLanes, RedNaNLanes)
                               : RedNaNLanes;
   }
@@ -1221,7 +1222,7 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
       LatchBuilder.createNaryOp(VPInstruction::AnyOf, {AllNaNLanes});
   VPBasicBlock *MiddleVPBB = Plan.getMiddleBlock();
   VPBuilder MiddleBuilder(MiddleVPBB, MiddleVPBB->begin());
-  for (const auto &[RedPhiR, _] : MinMaxNumReductionsToHandle) {
+  for (const auto &[RedPhiR, _] : MinOrMaxNumReductionsToHandle) {
     assert(RecurrenceDescriptor::isFPMinMaxNumRecurrenceKind(
                RedPhiR->getRecurrenceKind()) &&
            "unsupported reduction");
@@ -1376,65 +1377,67 @@ bool VPlanTransforms::handleFindLastReductions(VPlan &Plan) {
 bool VPlanTransforms::handleMultiUseReductions(VPlan &Plan) {
   for (auto &PhiR : make_early_inc_range(
            Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis())) {
-    auto *MinMaxPhiR = dyn_cast<VPReductionPHIRecipe>(&PhiR);
+    auto *MinOrMaxPhiR = dyn_cast<VPReductionPHIRecipe>(&PhiR);
     // TODO: check for multi-uses in VPlan directly.
-    if (!MinMaxPhiR || !MinMaxPhiR->hasUsesOutsideReductionChain())
+    if (!MinOrMaxPhiR || !MinOrMaxPhiR->hasUsesOutsideReductionChain())
       continue;
 
-    // MinMaxPhiR has users outside the reduction cycle in the loop. Check if
-    // the only other user is a FindLastIV reduction. MinMaxPhiR must have
+    // MinOrMaxPhiR has users outside the reduction cycle in the loop. Check if
+    // the only other user is a FindLastIV reduction. MinOrMaxPhiR must have
     // exactly 2 users:
     // 1) the min/max operation of the reduction cycle, and
     // 2) the compare of a FindLastIV reduction cycle. This compare must match
-    // the min/max operation - comparing MinMaxPhiR with the operand of the
+    // the min/max operation - comparing MinOrMaxPhiR with the operand of the
     // min/max operation, and be used only by the select of the FindLastIV
     // reduction cycle.
-    RecurKind RdxKind = MinMaxPhiR->getRecurrenceKind();
+    RecurKind RdxKind = MinOrMaxPhiR->getRecurrenceKind();
     assert(
         RecurrenceDescriptor::isIntMinMaxRecurrenceKind(RdxKind) &&
         "only min/max recurrences support users outside the reduction chain");
 
-    auto *MinMaxOp =
-        dyn_cast<VPRecipeWithIRFlags>(MinMaxPhiR->getBackedgeValue());
-    if (!MinMaxOp)
+    auto *MinOrMaxOp =
+        dyn_cast<VPRecipeWithIRFlags>(MinOrMaxPhiR->getBackedgeValue());
+    if (!MinOrMaxOp)
       return false;
 
-    // Check that MinMaxOp is a VPWidenIntrinsicRecipe or VPReplicateRecipe
+    // Check that MinOrMaxOp is a VPWidenIntrinsicRecipe or VPReplicateRecipe
     // with an intrinsic that matches the reduction kind.
     Intrinsic::ID ExpectedIntrinsicID = getMinMaxReductionIntrinsicOp(RdxKind);
-    if (!match(MinMaxOp, m_Intrinsic(ExpectedIntrinsicID)))
+    if (!match(MinOrMaxOp, m_Intrinsic(ExpectedIntrinsicID)))
       return false;
 
-    // MinMaxOp must have 2 users: 1) MinMaxPhiR and 2) ComputeReductionResult.
-    assert(MinMaxOp->getNumUsers() == 2 &&
-           "MinMaxOp must have exactly 2 users");
-    VPValue *MinMaxOpValue = MinMaxOp->getOperand(0);
-    if (MinMaxOpValue == MinMaxPhiR)
-      MinMaxOpValue = MinMaxOp->getOperand(1);
+    // MinOrMaxOp must have 2 users: 1) MinOrMaxPhiR and 2)
+    // ComputeReductionResult.
+    assert(MinOrMaxOp->getNumUsers() == 2 &&
+           "MinOrMaxOp must have exactly 2 users");
+    VPValue *MinOrMaxOpValue = MinOrMaxOp->getOperand(0);
+    if (MinOrMaxOpValue == MinOrMaxPhiR)
+      MinOrMaxOpValue = MinOrMaxOp->getOperand(1);
 
     VPValue *CmpOpA;
     VPValue *CmpOpB;
     CmpPredicate Pred;
     auto *Cmp = dyn_cast_or_null<VPRecipeWithIRFlags>(findUserOf(
-        MinMaxPhiR, m_Cmp(Pred, m_VPValue(CmpOpA), m_VPValue(CmpOpB))));
+        MinOrMaxPhiR, m_Cmp(Pred, m_VPValue(CmpOpA), m_VPValue(CmpOpB))));
     if (!Cmp || Cmp->getNumUsers() != 1 ||
-        (CmpOpA != MinMaxOpValue && CmpOpB != MinMaxOpValue))
+        (CmpOpA != MinOrMaxOpValue && CmpOpB != MinOrMaxOpValue))
       return false;
 
-    if (MinMaxOpValue != CmpOpB)
+    if (MinOrMaxOpValue != CmpOpB)
       Pred = CmpInst::getSwappedPredicate(Pred);
 
-    // MinMaxPhiR must have exactly 2 users:
-    // * MinMaxOp,
+    // MinOrMaxPhiR must have exactly 2 users:
+    // * MinOrMaxOp,
     // * Cmp (that's part of a FindLastIV chain).
-    if (MinMaxPhiR->getNumUsers() != 2)
+    if (MinOrMaxPhiR->getNumUsers() != 2)
       return false;
 
-    VPInstruction *MinMaxResult =
-        findUserOf<VPInstruction::ComputeReductionResult>(MinMaxOp);
-    assert(is_contained(MinMaxPhiR->users(), MinMaxOp) &&
-           "one user must be MinMaxOp");
-    assert(MinMaxResult && "MinMaxOp must have a ComputeReductionResult user");
+    VPInstruction *MinOrMaxResult =
+        findUserOf<VPInstruction::ComputeReductionResult>(MinOrMaxOp);
+    assert(is_contained(MinOrMaxPhiR->users(), MinOrMaxOp) &&
+           "one user must be MinOrMaxOp");
+    assert(MinOrMaxResult &&
+           "MinOrMaxOp must have a ComputeReductionResult user");
 
     // Cmp must be used by the select of a FindLastIV chain.
     VPValue *Sel = dyn_cast<VPSingleDefRecipe>(Cmp->getSingleUser());
@@ -1482,7 +1485,7 @@ bool VPlanTransforms::handleMultiUseReductions(VPlan &Plan) {
     assert(!FindIVPhiR->isInLoop() && !FindIVPhiR->isOrdered() &&
            "cannot handle inloop/ordered reductions yet");
 
-    // The reduction using MinMaxPhiR needs adjusting to compute the correct
+    // The reduction using MinOrMaxPhiR needs adjusting to compute the correct
     // result:
     //  1. We need to find the last IV for which the condition based on the
     //     min/max recurrence is true,
@@ -1504,19 +1507,19 @@ bool VPlanTransforms::handleMultiUseReductions(VPlan &Plan) {
     //                                             SENTINEL, vp<%final.iv>
     VPInstruction *FindIVResult =
         findUserOf<VPInstruction::ComputeFindIVResult>(FindIVPhiR);
-    assert(FindIVResult->getParent() == MinMaxResult->getParent() &&
+    assert(FindIVResult->getParent() == MinOrMaxResult->getParent() &&
            "both results must be computed in the same block");
-    MinMaxResult->moveBefore(*FindIVResult->getParent(),
-                             FindIVResult->getIterator());
+    MinOrMaxResult->moveBefore(*FindIVResult->getParent(),
+                               FindIVResult->getIterator());
 
     VPBuilder B(FindIVResult);
-    VPValue *MinMaxExiting = MinMaxResult->getOperand(0);
-    auto *FinalMinMaxCmp =
-        B.createICmp(CmpInst::ICMP_EQ, MinMaxExiting, MinMaxResult);
+    VPValue *MinOrMaxExiting = MinOrMaxResult->getOperand(0);
+    auto *FinalMinOrMaxCmp =
+        B.createICmp(CmpInst::ICMP_EQ, MinOrMaxExiting, MinOrMaxResult);
     VPValue *Sentinel = FindIVResult->getOperand(2);
     VPValue *LastIVExiting = FindIVResult->getOperand(3);
     auto *FinalIVSelect =
-        B.createSelect(FinalMinMaxCmp, LastIVExiting, Sentinel);
+        B.createSelect(FinalMinOrMaxCmp, LastIVExiting, Sentinel);
     FindIVResult->setOperand(3, FinalIVSelect);
   }
   return true;


        


More information about the llvm-commits mailing list