Skip to content

Commit 20e90e7

Browse files
committed
Address comments and add isInLoopReduction().
1 parent f154622 commit 20e90e7

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7103,6 +7103,14 @@ bool VPCostContext::skipCostComputation(Instruction *UI, bool IsVector) const {
71037103
SkipCostComputation.contains(UI);
71047104
}
71057105

7106+
bool VPCostContext::isInLoopReduction(const Instruction *UI, ElementCount VF,
7107+
Type *VectorTy) const {
7108+
return CM
7109+
.getReductionPatternCost(const_cast<Instruction *>(UI), VF, VectorTy,
7110+
TTI::TCK_RecipThroughput)
7111+
.has_value();
7112+
}
7113+
71067114
InstructionCost
71077115
LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
71087116
VPCostContext &CostCtx) const {

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ struct VPCostContext {
718718
/// Return true if the cost for \p UI shouldn't be computed, e.g. because it
719719
/// has already been pre-computed.
720720
bool skipCostComputation(Instruction *UI, bool IsVector) const;
721+
722+
/// Return true if the \p UI is part of the in-loop reduction.
723+
bool isInLoopReduction(const Instruction *UI, ElementCount VF,
724+
Type *VectorTy) const;
721725
};
722726

723727
/// VPRecipeBase is a base class modeling a sequence of one or more output IR

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,18 +2015,24 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) {
20152015
InstructionCost VPReductionRecipe::computeCost(ElementCount VF,
20162016
VPCostContext &Ctx) const {
20172017
RecurKind RdxKind = RdxDesc.getRecurrenceKind();
2018-
// TODO: Support any-of reduction and in-loop reduction
2019-
assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(RdxKind) &&
2020-
"Not support any-of reduction in VPlan-based cost model currently.");
2021-
2022-
Type *ElementTy = Ctx.Types.inferScalarType(this->getVPSingleValue());
2023-
assert(ElementTy->getTypeID() == RdxDesc.getRecurrenceType()->getTypeID() &&
2024-
"Infered type and recurrence type mismatch.");
2025-
2018+
Type *ElementTy = Ctx.Types.inferScalarType(this);
20262019
auto *VectorTy = cast<VectorType>(ToVectorTy(ElementTy, VF));
20272020
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
20282021
unsigned Opcode = RdxDesc.getOpcode();
20292022

2023+
// TODO: Support any-of reduction and in-loop reductions.
2024+
assert(
2025+
(!RecurrenceDescriptor::isAnyOfRecurrenceKind(RdxKind) ||
2026+
ForceTargetInstructionCost.getNumOccurrences() > 0) &&
2027+
"Any-of reduction not implemented in VPlan-based cost model currently.");
2028+
assert(
2029+
(!Ctx.isInLoopReduction(getUnderlyingInstr(), VF, VectorTy) ||
2030+
ForceTargetInstructionCost.getNumOccurrences() > 0) &&
2031+
"In-loop reduction not implemented in VPlan-based cost model currently.");
2032+
2033+
assert(ElementTy->getTypeID() == RdxDesc.getRecurrenceType()->getTypeID() &&
2034+
"Infered type and recurrence type mismatch.");
2035+
20302036
// Cost = Reduction cost + BinOp cost
20312037
InstructionCost Cost =
20322038
Ctx.TTI.getArithmeticInstrCost(Opcode, ElementTy, CostKind);

0 commit comments

Comments
 (0)