Skip to content

Commit 1858532

Browse files
committed
[VPlan] Handle predicated UDiv in VPReplicateRecipe::computeCost.
Account for predicated UDiv,SDiv,URem,SRem in VPReplicateRecipe::computeCost: compute costs of extra phis and apply getPredBlockCostDivisor. Fixes #158660
1 parent dbc96f4 commit 1858532

File tree

2 files changed

+468
-3
lines changed

2 files changed

+468
-3
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,9 +3163,22 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
31633163
if (isSingleScalar())
31643164
return ScalarCost;
31653165

3166-
return ScalarCost * VF.getFixedValue() +
3167-
Ctx.getScalarizationOverhead(Ctx.Types.inferScalarType(this),
3168-
to_vector(operands()), VF);
3166+
ScalarCost = ScalarCost * VF.getFixedValue() +
3167+
Ctx.getScalarizationOverhead(Ctx.Types.inferScalarType(this),
3168+
to_vector(operands()), VF);
3169+
// If the recipe is not predicated (i.e. not in a replicate region), return
3170+
// the scalar cost. Otherwise handle predicated cost.
3171+
if (!getParent()->getParent()->isReplicator())
3172+
return ScalarCost;
3173+
3174+
// Account for the phi nodes that we will create.
3175+
ScalarCost += VF.getFixedValue() *
3176+
Ctx.TTI.getCFInstrCost(Instruction::PHI, Ctx.CostKind);
3177+
// Scale the cost by the probability of executing the predicated blocks.
3178+
// This assumes the predicated block for each vector lane is equally
3179+
// likely.
3180+
ScalarCost /= getPredBlockCostDivisor(Ctx.CostKind);
3181+
return ScalarCost;
31693182
}
31703183
case Instruction::Load:
31713184
case Instruction::Store: {

0 commit comments

Comments
 (0)