[llvm] [RISCV][TTI] Improve SiFive7 reduction cost (PR #90951)

Shih-Po Hung via llvm-commits llvm-commits at lists.llvm.org
Sun May 5 20:08:00 PDT 2024


================
@@ -43,11 +91,23 @@ RISCVTTIImpl::getRISCVInstructionCost(ArrayRef<unsigned> OpCodes, MVT VT,
   size_t NumInstr = OpCodes.size();
   if (CostKind == TTI::TCK_CodeSize)
     return NumInstr;
+
+  std::optional<InstructionCost> (*GetTargetCost)(
+      unsigned, MVT, TTI::TargetCostKind) = nullptr;
+  if (ST->getProcFamily() == RISCVSubtarget::SiFive7)
+    GetTargetCost = getSiFiveX280RVVCost;
   InstructionCost LMULCost = TLI->getLMULCost(VT);
   if ((CostKind != TTI::TCK_RecipThroughput) && (CostKind != TTI::TCK_Latency))
     return LMULCost * NumInstr;
   InstructionCost Cost = 0;
   for (auto Op : OpCodes) {
+    std::optional<InstructionCost> OverrideCost =
+        GetTargetCost ? GetTargetCost(Op, VT, CostKind) : std::nullopt;
+    if (OverrideCost) {
+      Cost += *OverrideCost;
+      continue;
----------------
arcbbb wrote:

I refactored `getRISCVInstructionCost`  and move `for (auto Op: OCodes)` into `getSiFiveX280RVVCost`.
Let's see if this approach makes the code look better.

https://github.com/llvm/llvm-project/pull/90951


More information about the llvm-commits mailing list