[llvm] a323090 - [VPlan] Add VPReplicateRecipe::getNumOperandsWithoutMask (NFC) (#205004)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 21 12:16:02 PDT 2026


Author: Florian Hahn
Date: 2026-06-21T19:15:57Z
New Revision: a3230900a8809a45ac3952af186cf03d87183cfb

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

LOG: [VPlan] Add VPReplicateRecipe::getNumOperandsWithoutMask (NFC) (#205004)

Add a getNumOperandsWithoutMask helper to VPReplicateRecipe, mirroring
the existing VPInstruction::getNumOperandsWithoutMask, and use it to
replace some hand-rolled code.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlan.h
    llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
    llvm/lib/Transforms/Vectorize/VPlanUtils.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index cc2ff96b05be7..26c528a323969 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -3482,6 +3482,12 @@ class LLVM_ABI_FOR_TEST VPReplicateRecipe : public VPRecipeWithIRFlags,
     return isPredicated() ? drop_end(operands()) : operands();
   }
 
+  /// Returns the number of operands, excluding the mask if the recipe is
+  /// predicated.
+  unsigned getNumOperandsWithoutMask() const {
+    return getNumOperands() - isPredicated();
+  }
+
   unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
 
 protected:

diff  --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 0fab9cfe48dbe..354cdd1e2ffed 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -252,7 +252,7 @@ struct Recipe_match {
       assert(((isa<VPInstruction>(R) &&
                cast<VPInstruction>(R)->getNumOperandsForOpcode() == -1u) ||
               (RepR && std::tuple_size_v<Ops_t> ==
-                           RepR->getNumOperands() - RepR->isPredicated())) &&
+                           RepR->getNumOperandsWithoutMask())) &&
              "non-variadic recipe with matched opcode does not have the "
              "expected number of operands");
       return false;

diff  --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
index bc6c425378109..3ebf8e63d5b36 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
@@ -92,9 +92,9 @@ template <typename Ty> Intrinsic::ID getIntrinsicID(const Ty *R) {
   };
   if (const auto *Rep = dyn_cast<VPReplicateRecipe>(R))
     if (Rep->getOpcode() == Instruction::Call)
-      // The mask is always the last operand if predicated.
+      // The callee is the last operand, excluding the mask if predicated.
       return GetCalleeIntrinsic(
-          Rep->getOperand(Rep->getNumOperands() - 1 - Rep->isPredicated()));
+          Rep->getOperand(Rep->getNumOperandsWithoutMask() - 1));
   if (const auto *VPI = dyn_cast<VPInstruction>(R))
     if (VPI->getOpcode() == Instruction::Call)
       return GetCalleeIntrinsic(VPI->getOperand(VPI->getNumOperands() - 1));


        


More information about the llvm-commits mailing list