-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[VPlan] Compute cost of replicating calls in VPlan. (NFCI) #154291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
93dfdaf
d71ccb2
5fdb4e5
69f32c9
ddc132b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3002,13 +3002,6 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF, | |
| // instruction cost. | ||
| return 0; | ||
| case Instruction::Call: { | ||
| if (!isSingleScalar()) { | ||
| // TODO: Handle remaining call costs here as well. | ||
| if (VF.isScalable()) | ||
| return InstructionCost::getInvalid(); | ||
| break; | ||
| } | ||
|
|
||
| auto *CalledFn = | ||
| cast<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue()); | ||
| if (CalledFn->isIntrinsic()) | ||
|
|
@@ -3017,8 +3010,43 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF, | |
| SmallVector<Type *, 4> Tys; | ||
| for (VPValue *ArgOp : drop_end(operands())) | ||
| Tys.push_back(Ctx.Types.inferScalarType(ArgOp)); | ||
|
|
||
| Type *ResultTy = Ctx.Types.inferScalarType(this); | ||
| return Ctx.TTI.getCallInstrCost(CalledFn, ResultTy, Tys, Ctx.CostKind); | ||
| InstructionCost ScalarCallCost = | ||
| Ctx.TTI.getCallInstrCost(CalledFn, ResultTy, Tys, Ctx.CostKind); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the old code was even correct? It looks like in the legacy cost model (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current code does not handle intrinsics for now (see bail-out at line 3008). The twist with intrinsics is that if we chose the intrinsic cost, we only create VPReplicateRecipe for various pseudo-intrinsics. I'll add support for intrinsics as follow-up
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes, sorry I missed that! OK great and thanks for doing this. |
||
| if (isSingleScalar()) | ||
| return ScalarCallCost; | ||
|
|
||
| if (VF.isScalable()) | ||
| return InstructionCost::getInvalid(); | ||
|
|
||
| // Compute the cost of scalarizing the result and operands if needed. | ||
| InstructionCost ScalarizationCost = 0; | ||
| if (VF.isVector()) { | ||
| if (!ResultTy->isVoidTy()) { | ||
| for (Type *VectorTy : getContainedTypes(toVectorizedTy(ResultTy, VF))) { | ||
| ScalarizationCost += Ctx.TTI.getScalarizationOverhead( | ||
| cast<VectorType>(VectorTy), APInt::getAllOnes(VF.getFixedValue()), | ||
| /*Insert=*/true, | ||
| /*Extract=*/false, Ctx.CostKind); | ||
| } | ||
| } | ||
| // Skip operands that do not require extraction/scalarization and do not | ||
| // incur any overhead. | ||
| SmallVector<Type *> Tys; | ||
|
||
| SmallPtrSet<const VPValue *, 4> UniqueOperands; | ||
| for (auto *Op : drop_end(operands())) { | ||
| if (Op->isLiveIn() || isa<VPReplicateRecipe, VPPredInstPHIRecipe>(Op) || | ||
| !UniqueOperands.insert(Op).second) | ||
| continue; | ||
| Tys.push_back(toVectorizedTy(Ctx.Types.inferScalarType(Op), VF)); | ||
| } | ||
| ScalarizationCost += | ||
| Ctx.TTI.getOperandsScalarizationOverhead(Tys, Ctx.CostKind); | ||
| } | ||
|
|
||
| return ScalarCallCost * (isSingleScalar() ? 1 : VF.getFixedValue()) + | ||
| ScalarizationCost; | ||
|
||
| } | ||
| case Instruction::Add: | ||
| case Instruction::Sub: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unrelated whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed thanks