[llvm] [VPlan] Implement VPReductionRecipe::computeCost(). NFC (PR #107790)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 03:02:23 PDT 2024
================
@@ -2012,6 +2012,41 @@ void VPReductionEVLRecipe::execute(VPTransformState &State) {
State.set(this, NewRed, /*IsScalar*/ true);
}
+InstructionCost VPReductionRecipe::computeCost(ElementCount VF,
+ VPCostContext &Ctx) const {
+ RecurKind RdxKind = RdxDesc.getRecurrenceKind();
+ Type *ElementTy = Ctx.Types.inferScalarType(this);
+ auto *VectorTy = cast<VectorType>(ToVectorTy(ElementTy, VF));
+ TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+ unsigned Opcode = RdxDesc.getOpcode();
+
+ // TODO: Support any-of and in-loop reductions.
+ assert(
+ (!RecurrenceDescriptor::isAnyOfRecurrenceKind(RdxKind) ||
+ ForceTargetInstructionCost.getNumOccurrences() > 0) &&
+ "Any-of reduction not implemented in VPlan-based cost model currently.");
+ auto *ReductionPHIRecipe = dyn_cast<VPReductionPHIRecipe>(getOperand(0));
+ assert(
+ (ReductionPHIRecipe && !ReductionPHIRecipe->isInLoop() ||
----------------
fhahn wrote:
Currently this will result in an unused variable warning when building without asserts.
Perhaps use `cast` (will assert that the argument is non-null) and fold it into the assert
```suggestion
assert(
(!cast<VPReductionPHIRecipe>(getOperand(0))->isInLoop() ||
```
https://github.com/llvm/llvm-project/pull/107790
More information about the llvm-commits
mailing list