@@ -275,7 +275,10 @@ void VPRecipeBase::moveBefore(VPBasicBlock &BB,
275
275
}
276
276
277
277
// / 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.
279
282
static Instruction *getInstructionForCost (const VPRecipeBase *R) {
280
283
if (auto *S = dyn_cast<VPSingleDefRecipe>(R))
281
284
return dyn_cast_or_null<Instruction>(S->getUnderlyingValue ());
@@ -295,7 +298,7 @@ InstructionCost VPRecipeBase::cost(ElementCount VF, VPCostContext &Ctx) {
295
298
RecipeCost = InstructionCost (ForceTargetInstructionCost);
296
299
// Max cost is used as a sentinel value to detect recipes without underlying
297
300
// instructions for which no forced target instruction cost should be applied.
298
- if (RecipeCost == InstructionCost::getMax ())
301
+ else if (RecipeCost == InstructionCost::getMax ())
299
302
RecipeCost = 0 ;
300
303
301
304
LLVM_DEBUG ({
@@ -308,16 +311,18 @@ InstructionCost VPRecipeBase::cost(ElementCount VF, VPCostContext &Ctx) {
308
311
InstructionCost VPRecipeBase::computeCost (ElementCount VF,
309
312
VPCostContext &Ctx) const {
310
313
// 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
+
313
320
Instruction *UI = getInstructionForCost (this );
314
321
if (UI && isa<VPReplicateRecipe>(this )) {
315
322
// VPReplicateRecipe may be cloned as part of an existing VPlan-to-VPlan
316
323
// transform, avoid computing their cost multiple times for now.
317
324
Ctx.SkipCostComputation .insert (UI);
318
325
}
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.
321
326
return UI ? Ctx.getLegacyCost (UI, VF) : InstructionCost::getMax ();
322
327
}
323
328
0 commit comments