[llvm] [RISCV][TTI] Implement cost for vp min/max intrinsics (PR #107567)

Elvis Wang via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 20:53:04 PDT 2024


================
@@ -989,6 +989,14 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
       return Cost * LT.first;
     break;
   }
+  case Intrinsic::vp_smax:
+  case Intrinsic::vp_smin:
+  case Intrinsic::vp_umax:
+  case Intrinsic::vp_umin: {
+    auto LT = getTypeLegalizationCost(RetTy);
+    return LT.first *
+           getRISCVInstructionCost(RISCV::VMAXU_VV, LT.second, CostKind);
----------------
ElvisWang123 wrote:

TTI uses different Ops to query the cost of `Intrinsic::umin`, `Intrinsic::umax` etc. in the `getIntrinsicInstrCost()`.
Will we need to use different Ops to query the cost  for different vp-intrinsics here? 
```C++
  case Intrinsic::umin:
  case Intrinsic::umax:
  case Intrinsic::smin:
  case Intrinsic::smax: {
    auto LT = getTypeLegalizationCost(RetTy);
    if (LT.second.isScalarInteger() && ST->hasStdExtZbb())
      return LT.first;
    if (ST->hasVInstructions() && LT.second.isVector()) {
      unsigned Op;
      switch (ICA.getID()) {
      case Intrinsic::umin:
        Op = RISCV::VMINU_VV;
        break;
      case Intrinsic::umax:
        Op = RISCV::VMAXU_VV;
        break;
      case Intrinsic::smin:
        Op = RISCV::VMIN_VV;
        break;
      case Intrinsic::smax:
        Op = RISCV::VMAX_VV;
        break;
      }
      return LT.first * getRISCVInstructionCost(Op, LT.second, CostKind);
    }
    break;
  }
``` 

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


More information about the llvm-commits mailing list