Skip to content

Commit a3475ac

Browse files
committed
[VectorUtils][VPlan] Consolidate VPWidenIntrinsicRecipe::onlyFirstLaneUsed and isVectorIntrinsicWithScalarOpAtArg
We can reuse isVectorIntrinsicWithScalarOpAtArg in VectorUtils to determine if only the first lane will be used for a VPWidenIntrinsicRecipe, provided that we also move the VP EVL operand check into it. This was needed by a local patch I was working on that created a VPWidenIntrinsicRecipe with a VP intrinsic, and prevents the need to update the scalar arguments in two places.
1 parent f218cd2 commit a3475ac

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ bool llvm::isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
149149
if (TTI && Intrinsic::isTargetIntrinsic(ID))
150150
return TTI->isTargetIntrinsicWithScalarOpAtArg(ID, ScalarOpdIdx);
151151

152+
// Vector predication intrinsics only demand the the first lane the last
153+
// operand (the EVL operand).
154+
if (VPIntrinsic::getVectorLengthParamPos(ID) == ScalarOpdIdx)
155+
return true;
156+
152157
switch (ID) {
153158
case Intrinsic::abs:
154159
case Intrinsic::vp_abs:
@@ -166,7 +171,7 @@ bool llvm::isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
166171
case Intrinsic::umul_fix_sat:
167172
return (ScalarOpdIdx == 2);
168173
case Intrinsic::experimental_vp_splice:
169-
return ScalarOpdIdx == 2 || ScalarOpdIdx == 4 || ScalarOpdIdx == 5;
174+
return ScalarOpdIdx == 2 || ScalarOpdIdx == 4;
170175
default:
171176
return false;
172177
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,10 +1373,8 @@ StringRef VPWidenIntrinsicRecipe::getIntrinsicName() const {
13731373

13741374
bool VPWidenIntrinsicRecipe::onlyFirstLaneUsed(const VPValue *Op) const {
13751375
assert(is_contained(operands(), Op) && "Op must be an operand of the recipe");
1376-
// Vector predication intrinsics only demand the the first lane the last
1377-
// operand (the EVL operand).
1378-
return VPIntrinsic::isVPIntrinsic(VectorIntrinsicID) &&
1379-
Op == getOperand(getNumOperands() - 1);
1376+
unsigned Idx = std::distance(op_begin(), find(operands(), Op));
1377+
return isVectorIntrinsicWithScalarOpAtArg(VectorIntrinsicID, Idx, nullptr);
13801378
}
13811379

13821380
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

0 commit comments

Comments
 (0)