Skip to content

Commit a323a92

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 llvm#158660 (cherry picked from commit 1858532)
1 parent 151128d commit a323a92

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
@@ -3053,9 +3053,22 @@ InstructionCost VPReplicateRecipe::computeCost(ElementCount VF,
30533053
if (isSingleScalar())
30543054
return ScalarCost;
30553055

3056-
return ScalarCost * VF.getFixedValue() +
3057-
Ctx.getScalarizationOverhead(Ctx.Types.inferScalarType(this),
3058-
to_vector(operands()), VF);
3056+
ScalarCost = ScalarCost * VF.getFixedValue() +
3057+
Ctx.getScalarizationOverhead(Ctx.Types.inferScalarType(this),
3058+
to_vector(operands()), VF);
3059+
// If the recipe is not predicated (i.e. not in a replicate region), return
3060+
// the scalar cost. Otherwise handle predicated cost.
3061+
if (!getParent()->getParent()->isReplicator())
3062+
return ScalarCost;
3063+
3064+
// Account for the phi nodes that we will create.
3065+
ScalarCost += VF.getFixedValue() *
3066+
Ctx.TTI.getCFInstrCost(Instruction::PHI, Ctx.CostKind);
3067+
// Scale the cost by the probability of executing the predicated blocks.
3068+
// This assumes the predicated block for each vector lane is equally
3069+
// likely.
3070+
ScalarCost /= getPredBlockCostDivisor(Ctx.CostKind);
3071+
return ScalarCost;
30593072
}
30603073
case Instruction::Load:
30613074
case Instruction::Store: {

0 commit comments

Comments
 (0)