Skip to content

Commit 8d0c466

Browse files
committed
[LV][VPlan] Implement VPlan-based cost for exit condition.
This patch tried to model the cost of exit conditions through vplan-based cost model. * `BranchOnCount` will generate icmp + br. The branch instruction is already implemented by the VPRegionBlock so we only need to calculate the cost of icmp. If the VF is same as the trip count of the loop, the cost of the BranchOnCount is free. This patch is not quite NFC for following reasons. * Some of the BranchOnCount could be optimized to BranchOnCond, which is free. * Some of the instructions calculated in the exit condition in legacy cost model will be optimized out.
1 parent c45d230 commit 8d0c466

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7447,8 +7447,10 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan,
74477447
if (isa<VPPartialReductionRecipe>(&R))
74487448
return true;
74497449

7450-
// The legacy cost model will under estimate the cost of BranchOnCount if exit condition were explicit contructed in the vplan.
7451-
if (VPInstruction *VPI = dyn_cast<VPInstruction>(&R); VPI && VPI->getOpcode() == VPInstruction::BranchOnCount)
7450+
// The legacy cost model will under estimate the cost of BranchOnCount if
7451+
// exit condition were explicit contructed in the vplan.
7452+
if (VPInstruction *VPI = dyn_cast<VPInstruction>(&R);
7453+
VPI && VPI->getOpcode() == VPInstruction::BranchOnCount)
74527454
return true;
74537455

74547456
if (Instruction *UI = GetInstructionForCost(&R))

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,6 @@ InstructionCost VPInstruction::computeCost(ElementCount VF,
744744
Instruction::Or, cast<VectorType>(VecTy), std::nullopt, Ctx.CostKind);
745745
}
746746
case VPInstruction::BranchOnCount: {
747-
if (getUnderlyingValue())
748747
// BranchOnCount will genearte icmp_eq + br instructions and the
749748
// cost of branch will be calculated in VPRegionBlock.
750749
// If the vector loop only executed once, ignore the cost of the cmp.

0 commit comments

Comments
 (0)