Skip to content

Commit a323090

Browse files
authored
[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.
1 parent d3b48cc commit a323090

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,6 +3482,12 @@ class LLVM_ABI_FOR_TEST VPReplicateRecipe : public VPRecipeWithIRFlags,
34823482
return isPredicated() ? drop_end(operands()) : operands();
34833483
}
34843484

3485+
/// Returns the number of operands, excluding the mask if the recipe is
3486+
/// predicated.
3487+
unsigned getNumOperandsWithoutMask() const {
3488+
return getNumOperands() - isPredicated();
3489+
}
3490+
34853491
unsigned getOpcode() const { return getUnderlyingInstr()->getOpcode(); }
34863492

34873493
protected:

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ struct Recipe_match {
252252
assert(((isa<VPInstruction>(R) &&
253253
cast<VPInstruction>(R)->getNumOperandsForOpcode() == -1u) ||
254254
(RepR && std::tuple_size_v<Ops_t> ==
255-
RepR->getNumOperands() - RepR->isPredicated())) &&
255+
RepR->getNumOperandsWithoutMask())) &&
256256
"non-variadic recipe with matched opcode does not have the "
257257
"expected number of operands");
258258
return false;

llvm/lib/Transforms/Vectorize/VPlanUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ template <typename Ty> Intrinsic::ID getIntrinsicID(const Ty *R) {
9292
};
9393
if (const auto *Rep = dyn_cast<VPReplicateRecipe>(R))
9494
if (Rep->getOpcode() == Instruction::Call)
95-
// The mask is always the last operand if predicated.
95+
// The callee is the last operand, excluding the mask if predicated.
9696
return GetCalleeIntrinsic(
97-
Rep->getOperand(Rep->getNumOperands() - 1 - Rep->isPredicated()));
97+
Rep->getOperand(Rep->getNumOperandsWithoutMask() - 1));
9898
if (const auto *VPI = dyn_cast<VPInstruction>(R))
9999
if (VPI->getOpcode() == Instruction::Call)
100100
return GetCalleeIntrinsic(VPI->getOperand(VPI->getNumOperands() - 1));

0 commit comments

Comments
 (0)