[PATCH] D129994: [RISCV] Add cost modelling for vector widenning integer reduction.

Jianjian Guan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 02:53:56 PDT 2022


jacquesguan created this revision.
jacquesguan added reviewers: reames, craig.topper, asb, luismarques, frasercrmck, benshi001.
Herald added subscribers: sunshaoce, VincentWu, luke957, StephenFan, vkmr, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
jacquesguan requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129994

Files:
  llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
  llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h


Index: llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
+++ llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h
@@ -111,6 +111,10 @@
                                              Optional<FastMathFlags> FMF,
                                              TTI::TargetCostKind CostKind);
 
+  InstructionCost getExtendedAddReductionCost(bool IsMLA, bool IsUnsigned,
+                                              Type *ResTy, VectorType *ValTy,
+                                              TTI::TargetCostKind CostKind);
+
   bool isElementTypeLegalForScalableVector(Type *Ty) const {
     return TLI->isLegalElementTypeForRVV(Ty);
   }
Index: llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -371,6 +371,20 @@
   return (LT.first - 1) + BaseCost + Log2_32_Ceil(VL);
 }
 
+InstructionCost
+RISCVTTIImpl::getExtendedAddReductionCost(bool IsMLA, bool IsUnsigned,
+                                          Type *ResTy, VectorType *ValTy,
+                                          TTI::TargetCostKind CostKind) {
+  // Now we only use vwredsum and vwredsumu if the result value width is equal
+  // to twice of input SEW-width.
+  if (IsMLA || ResTy->getScalarSizeInBits() != 2 * ValTy->getScalarSizeInBits())
+    return BaseT::getExtendedAddReductionCost(IsMLA, IsUnsigned, ResTy, ValTy,
+                                              CostKind);
+
+  // vwredsum and vwredsumu is same cost with vredsumu.
+  return getArithmeticReductionCost(Instruction::Add, ValTy, {}, CostKind);
+}
+
 void RISCVTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
                                            TTI::UnrollingPreferences &UP,
                                            OptimizationRemarkEmitter *ORE) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129994.445439.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220718/026ee46c/attachment.bin>


More information about the llvm-commits mailing list