Skip to content

Commit 672b04b

Browse files
committed
[VPlan] Compute cost of intrinsics directly for VPReplicateRecipe (NFCI).
Handle intrinsic calls in VPReplicateRecipe::computeCost. There are some intrinsics pseudo intrinsics for which the computed cost is known zero, so we handle those up front. Depends on #154291. (included in PR)
1 parent 59dcaf1 commit 672b04b

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,18 +3018,42 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
30183018
case Instruction::Call: {
30193019
auto *CalledFn =
30203020
cast<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue());
3021-
if (CalledFn->isIntrinsic())
3022-
break;
30233021

3022+
SmallVector<const VPValue *> ArgOps(drop_end(operands()));
30243023
SmallVector<Type *, 4> Tys;
3025-
for (VPValue *ArgOp : drop_end(operands()))
3024+
for (const VPValue *ArgOp : ArgOps)
30263025
Tys.push_back(Ctx.Types.inferScalarType(ArgOp));
30273026

3027+
if (CalledFn->isIntrinsic())
3028+
// Various pseudo-intrinsics with costs of 0 are scalarized instead of
3029+
// vectorized via VPWidenIntrinsicRecipe. Return 0 for them early.
3030+
switch (CalledFn->getIntrinsicID()) {
3031+
case Intrinsic::assume:
3032+
case Intrinsic::lifetime_end:
3033+
case Intrinsic::lifetime_start:
3034+
case Intrinsic::sideeffect:
3035+
case Intrinsic::pseudoprobe:
3036+
case Intrinsic::experimental_noalias_scope_decl: {
3037+
assert(getCostForIntrinsics(CalledFn->getIntrinsicID(), ArgOps, *this,
3038+
ElementCount::getFixed(1), Ctx) == 0 &&
3039+
"pseudo-intrinsic must have zero cost");
3040+
return InstructionCost(0);
3041+
}
3042+
default:
3043+
break;
3044+
}
3045+
30283046
Type *ResultTy = Ctx.Types.inferScalarType(this);
30293047
InstructionCost ScalarCallCost =
30303048
Ctx.TTI.getCallInstrCost(CalledFn, ResultTy, Tys, Ctx.CostKind);
3031-
if (isSingleScalar())
3049+
if (isSingleScalar()) {
3050+
if (CalledFn->isIntrinsic())
3051+
ScalarCallCost = std::min(
3052+
ScalarCallCost,
3053+
getCostForIntrinsics(CalledFn->getIntrinsicID(), ArgOps, *this,
3054+
ElementCount::getFixed(1), Ctx));
30323055
return ScalarCallCost;
3056+
}
30333057

30343058
if (VF.isScalable())
30353059
return InstructionCost::getInvalid();
@@ -3049,7 +3073,7 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
30493073
// incur any overhead.
30503074
SmallVector<Type *> Tys;
30513075
SmallPtrSet<const VPValue *, 4> UniqueOperands;
3052-
for (auto *Op : drop_end(operands())) {
3076+
for (auto *Op : ArgOps) {
30533077
if (Op->isLiveIn() || isa<VPReplicateRecipe, VPPredInstPHIRecipe>(Op) ||
30543078
!UniqueOperands.insert(Op).second)
30553079
continue;
@@ -3059,8 +3083,7 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
30593083
Ctx.TTI.getOperandsScalarizationOverhead(Tys, Ctx.CostKind);
30603084
}
30613085

3062-
return ScalarCallCost * (isSingleScalar() ? 1 : VF.getFixedValue()) +
3063-
ScalarizationCost;
3086+
return ScalarCallCost * VF.getFixedValue() + ScalarizationCost;
30643087
}
30653088
case Instruction::Add:
30663089
case Instruction::Sub:

0 commit comments

Comments
 (0)