Skip to content

Commit 2cfab8b

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 ecc63e7 commit 2cfab8b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
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
@@ -1364,10 +1364,8 @@ StringRef VPWidenIntrinsicRecipe::getIntrinsicName() const {
13641364

13651365
bool VPWidenIntrinsicRecipe::onlyFirstLaneUsed(const VPValue *Op) const {
13661366
assert(is_contained(operands(), Op) && "Op must be an operand of the recipe");
1367-
// Vector predication intrinsics only demand the the first lane the last
1368-
// operand (the EVL operand).
1369-
return VPIntrinsic::isVPIntrinsic(VectorIntrinsicID) &&
1370-
Op == getOperand(getNumOperands() - 1);
1367+
unsigned Idx = std::distance(op_begin(), find(operands(), Op));
1368+
return isVectorIntrinsicWithScalarOpAtArg(VectorIntrinsicID, Idx, nullptr);
13711369
}
13721370

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

llvm/test/Transforms/LoopVectorize/widen-intrinsic.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ define void @powi(ptr noalias %p, i32 %pow) {
88
; CHECK-NEXT: [[ENTRY:.*]]:
99
; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
1010
; CHECK: [[VECTOR_PH]]:
11-
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[POW]], i64 0
12-
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
1311
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
1412
; CHECK: [[VECTOR_BODY]]:
1513
; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
1614
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr float, ptr [[P]], i32 [[INDEX]]
1715
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr float, ptr [[TMP0]], i32 0
1816
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4
19-
; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x i32> [[BROADCAST_SPLAT]], i32 0
20-
; CHECK-NEXT: [[TMP3:%.*]] = call <4 x float> @llvm.powi.v4f32.i32(<4 x float> [[WIDE_LOAD]], i32 [[TMP2]])
17+
; CHECK-NEXT: [[TMP3:%.*]] = call <4 x float> @llvm.powi.v4f32.i32(<4 x float> [[WIDE_LOAD]], i32 [[POW]])
2118
; CHECK-NEXT: store <4 x float> [[TMP3]], ptr [[TMP1]], align 4
2219
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
2320
; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[INDEX_NEXT]], 1024

0 commit comments

Comments
 (0)