Skip to content

Commit 915c3d4

Browse files
committed
Update comments and testing scalar.
1 parent feff37e commit 915c3d4

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,10 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
746746
case VPInstruction::BranchOnCount: {
747747
Type *ValTy = Ctx.Types.inferScalarType(getOperand(0));
748748

749-
// If the vector loop only executed once, ignore the cost.
749+
// If the vector loop only executed once (VF == original trip count), ignore
750+
// the cost of cmp.
750751
// TODO: We can remove this after hoist `unrollByUF` and
751-
// `optimizeForVFandUF` which will should optimize BranchOnCount out.
752+
// `optimizeForVFandUF` which will optimize BranchOnCount out.
752753
auto TC = dyn_cast_if_present<ConstantInt>(
753754
getParent()->getPlan()->getTripCount()->getUnderlyingValue());
754755
if (TC && VF.isFixed() && TC->getSExtValue() == VF.getFixedValue())
@@ -760,22 +761,19 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
760761
CmpInst::ICMP_EQ, Ctx.CostKind);
761762
}
762763
case VPInstruction::BranchOnCond: {
763-
// BranchOnCond will generate `extractelement` when the condition is vector
764-
// type.
765-
VPValue *Op = getOperand(0);
766-
VPRecipeBase *R = Op->getDefiningRecipe();
767-
if (R &&
768-
any_of(R->operands(), [&](VPValue *V) { return !R->usesScalars(V); }) &&
769-
VF.isVector())
770-
return Ctx.TTI.getVectorInstrCost(
771-
Instruction::ExtractElement,
772-
cast<VectorType>(
773-
toVectorTy(Ctx.Types.inferScalarType(getOperand(0)), VF)),
774-
Ctx.CostKind, 0, nullptr, nullptr);
775-
776-
// Otherwise, BranchOnCond is free since the branch cost is already
764+
765+
// BranchOnCond is free since the branch cost is already
777766
// calculated by VPBB.
778-
return 0;
767+
if (vputils::onlyFirstLaneUsed(getOperand(0)))
768+
return 0;
769+
770+
// Otherwise, BranchOnCond will generate `extractelement` to extract the
771+
// condition from vector type.
772+
return Ctx.TTI.getVectorInstrCost(
773+
Instruction::ExtractElement,
774+
cast<VectorType>(
775+
toVectorTy(Ctx.Types.inferScalarType(getOperand(0)), VF)),
776+
Ctx.CostKind, 0, nullptr, nullptr);
779777
}
780778
default:
781779
// TODO: Compute cost other VPInstructions once the legacy cost model has

0 commit comments

Comments
 (0)