Skip to content

Commit 0bf2760

Browse files
committed
!fixup address latest comments, thanks!
1 parent f409232 commit 0bf2760

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ void VPRecipeBase::moveBefore(VPBasicBlock &BB,
275275
}
276276

277277
/// Return the underlying instruction to be used for computing \p R's cost via
278-
/// the legacy cost model. Return nullptr if there's no suitable instruction.
278+
/// the legacy cost model. Return nullptr if there's no suitable instruction or
279+
/// computeCost is already implemented for the recipe and there is no need for
280+
/// the underlying instruction, i.e. it does not need to be skipped for cost
281+
/// computations.
279282
static Instruction *getInstructionForCost(const VPRecipeBase *R) {
280283
if (auto *S = dyn_cast<VPSingleDefRecipe>(R))
281284
return dyn_cast_or_null<Instruction>(S->getUnderlyingValue());
@@ -295,7 +298,7 @@ InstructionCost VPRecipeBase::cost(ElementCount VF, VPCostContext &Ctx) {
295298
RecipeCost = InstructionCost(ForceTargetInstructionCost);
296299
// Max cost is used as a sentinel value to detect recipes without underlying
297300
// instructions for which no forced target instruction cost should be applied.
298-
if (RecipeCost == InstructionCost::getMax())
301+
else if (RecipeCost == InstructionCost::getMax())
299302
RecipeCost = 0;
300303

301304
LLVM_DEBUG({
@@ -308,16 +311,18 @@ InstructionCost VPRecipeBase::cost(ElementCount VF, VPCostContext &Ctx) {
308311
InstructionCost VPRecipeBase::computeCost(ElementCount VF,
309312
VPCostContext &Ctx) const {
310313
// Compute the cost for the recipe falling back to the legacy cost model using
311-
// the underlying instruction. If there is no underlying instruction, returns
312-
// 0.
314+
// the underlying instruction. If there is no underlying instruction or the
315+
// cost is computed by the recipe's computeCost, returns
316+
// InstructionCost::getMax. It is used as a sentinel value to detect recipes
317+
// without underlying instructions for which no forced target instruction cost
318+
// should be applied.
319+
313320
Instruction *UI = getInstructionForCost(this);
314321
if (UI && isa<VPReplicateRecipe>(this)) {
315322
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
316323
// transform, avoid computing their cost multiple times for now.
317324
Ctx.SkipCostComputation.insert(UI);
318325
}
319-
// Max cost is used as a sentinel value to detect recipes without underlying
320-
// instructions for which no forced target instruction cost should be applied.
321326
return UI ? Ctx.getLegacyCost(UI, VF) : InstructionCost::getMax();
322327
}
323328

0 commit comments

Comments
 (0)