[llvm] [RISCV][CostModel] Add cost model for experimental.cttz.elts (PR #91778)

Min-Yih Hsu via llvm-commits llvm-commits at lists.llvm.org
Fri May 10 15:46:46 PDT 2024


================
@@ -901,6 +902,28 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
                  getRISCVInstructionCost(RISCV::VADD_VX, LT.second, CostKind);
     return 1 + (LT.first - 1);
   }
+  case Intrinsic::experimental_cttz_elts: {
+    Type *ArgTy = ICA.getArgTypes()[0];
+    EVT ArgType = TLI->getValueType(DL, ArgTy, true);
+    if (getTLI()->shouldExpandCttzElements(ArgType))
+      break;
+    auto LT = getTypeLegalizationCost(RetTy);
+    InstructionCost Cost =
+        getRISCVInstructionCost(
+            RISCV::VFIRST_M, getTypeLegalizationCost(ArgTy).second, CostKind) +
+        (LT.first - 1);
+
+    // If zero_is_poison is false, then we will generate additional
+    // cmp + select instructions to convert -1 to EVL.
+    Type *BoolTy = Type::getInt1Ty(RetTy->getContext());
+    if (cast<ConstantInt>(ICA.getArgs()[1])->isZero())
----------------
mshockwave wrote:

Yeah some places like partial inliner only query by argument types. I've added a check here.

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


More information about the llvm-commits mailing list