-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
93dfdaf
[VPlan] Compute cost of replicating calls in VPlan. (NFCI)
fhahn d71ccb2
Merge remote-tracking branch 'origin/main' into vplan-compute-scalar-…
fhahn 5fdb4e5
!fixup use clear instead of new smallvector.
fhahn 69f32c9
Merge remote-tracking branch 'origin/main' into vplan-compute-scalar-…
fhahn ddc132b
!fixup use to_vector to fix stack-use-after-free.
fhahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3047,13 +3047,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()) | ||
|
@@ -3063,7 +3056,42 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF, | |
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); | ||
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 : | ||
to_vector(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. | ||
SmallPtrSet<const VPValue *, 4> UniqueOperands; | ||
Tys.clear(); | ||
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: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wonder if the old code was even correct? It looks like in the legacy cost model (
LoopVectorizationCostModel::getVectorCallCost
) we selected the min ofgetVectorIntrinsicCost
andTTI.getCallInstrCost
if we're invoking an intrinsic.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.
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
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.
Ah yes, sorry I missed that! OK great and thanks for doing this.