[llvm] b61cfc9 - [RISCV] Add cost modelling for vector widenning reduction.
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 4 00:32:05 PDT 2022
Author: jacquesguan
Date: 2022-08-04T15:31:31+08:00
New Revision: b61cfc91eac83dec7ded1ef1e6d9f9776751d2c0
URL: https://github.com/llvm/llvm-project/commit/b61cfc91eac83dec7ded1ef1e6d9f9776751d2c0
DIFF: https://github.com/llvm/llvm-project/commit/b61cfc91eac83dec7ded1ef1e6d9f9776751d2c0.diff
LOG: [RISCV] Add cost modelling for vector widenning reduction.
In RVV, we use vwredsum.vs and vwredsumu.vs for vecreduce.add(ext(Ty A)) if the result type's width is twice of the input vector's SEW-width. In this situation, the cost of extended add reduction should be same as single-width add reduction. So as the vector float widenning reduction.
Differential Revision: https://reviews.llvm.org/D129994
Added:
Modified:
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index cea2fb934cf51..d6f5175ee8741 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -377,6 +377,32 @@ RISCVTTIImpl::getArithmeticReductionCost(unsigned Opcode, VectorType *Ty,
return (LT.first - 1) + BaseCost + Log2_32_Ceil(VL);
}
+InstructionCost RISCVTTIImpl::getExtendedReductionCost(
+ unsigned Opcode, bool IsUnsigned, Type *ResTy, VectorType *ValTy,
+ Optional<FastMathFlags> FMF, TTI::TargetCostKind CostKind) {
+ if (isa<FixedVectorType>(ValTy) && !ST->useRVVForFixedLengthVectors())
+ return BaseT::getExtendedReductionCost(Opcode, IsUnsigned, ResTy, ValTy,
+ FMF, CostKind);
+
+ // Skip if scalar size of ResTy is bigger than ELEN.
+ if (ResTy->getScalarSizeInBits() > ST->getELEN())
+ return BaseT::getExtendedReductionCost(Opcode, IsUnsigned, ResTy, ValTy,
+ FMF, CostKind);
+
+ if (Opcode != Instruction::Add && Opcode != Instruction::FAdd)
+ return BaseT::getExtendedReductionCost(Opcode, IsUnsigned, ResTy, ValTy,
+ FMF, CostKind);
+
+ std::pair<InstructionCost, MVT> LT = TLI->getTypeLegalizationCost(DL, ValTy);
+
+ if (ResTy->getScalarSizeInBits() != 2 * LT.second.getScalarSizeInBits())
+ return BaseT::getExtendedReductionCost(Opcode, IsUnsigned, ResTy, ValTy,
+ FMF, CostKind);
+
+ return (LT.first - 1) +
+ getArithmeticReductionCost(Opcode, ValTy, FMF, CostKind);
+}
+
void RISCVTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
TTI::UnrollingPreferences &UP,
OptimizationRemarkEmitter *ORE) {
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
index 9f67dfbbbdf7f..c36d8423ade5d 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
@@ -112,6 +112,11 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
Optional<FastMathFlags> FMF,
TTI::TargetCostKind CostKind);
+ InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned,
+ Type *ResTy, VectorType *ValTy,
+ Optional<FastMathFlags> FMF,
+ TTI::TargetCostKind CostKind);
+
bool isElementTypeLegalForScalableVector(Type *Ty) const {
return TLI->isLegalElementTypeForRVV(Ty);
}
More information about the llvm-commits
mailing list