From: jacquesguan Date: Mon, 18 Jul 2022 09:37:37 +0000 (+0800) Subject: [RISCV] Add cost modelling for vector widenning reduction. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b61cfc91eac83dec7ded1ef1e6d9f9776751d2c0;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index cea2fb9..d6f5175 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 FMF, TTI::TargetCostKind CostKind) { + if (isa(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 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 9f67dfb..c36d842 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h @@ -112,6 +112,11 @@ public: Optional FMF, TTI::TargetCostKind CostKind); + InstructionCost getExtendedReductionCost(unsigned Opcode, bool IsUnsigned, + Type *ResTy, VectorType *ValTy, + Optional FMF, + TTI::TargetCostKind CostKind); + bool isElementTypeLegalForScalableVector(Type *Ty) const { return TLI->isLegalElementTypeForRVV(Ty); }