Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISCV][CostModel] Add cost for @llvm.experimental.vp.splice #122223

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

LiqinWeng
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2025

@llvm/pr-subscribers-llvm-analysis

Author: LiqinWeng (LiqinWeng)

Changes

Patch is 67.15 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/122223.diff

3 Files Affected:

  • (modified) llvm/lib/Analysis/CostModel.cpp (+1)
  • (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+27)
  • (modified) llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll (+329)
diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp
index ee6622516a5ac0..af3e69f854a86a 100644
--- a/llvm/lib/Analysis/CostModel.cpp
+++ b/llvm/lib/Analysis/CostModel.cpp
@@ -54,6 +54,7 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
       // TODO: Use a pass parameter instead of cl::opt CostKind to determine
       // which cost kind to print.
       InstructionCost Cost;
+      SmallVector<Value *, 6> Args;
       auto *II = dyn_cast<IntrinsicInst>(&Inst);
       if (II && TypeBasedIntrinsicCost) {
         IntrinsicCostAttributes ICA(II->getIntrinsicID(), *II,
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 850d6244affa50..6789944d9c6cab 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1189,6 +1189,33 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
                                                   : RISCV::VMV_V_X,
                                               LT.second, CostKind);
   }
+  case Intrinsic::experimental_vp_splice: {
+    auto LT = getTypeLegalizationCost(RetTy);
+    SmallVector<unsigned, 3> Opcodes;
+    Value *ImmValue = *(ICA.getInst()->arg_begin() + 2);
+    auto *Imm = dyn_cast<ConstantInt>(ImmValue);
+    if (Imm->isNegative())
+      Opcodes = {RISCV::VSLIDEDOWN_VI, RISCV::VSLIDEUP_VX};
+    else
+      Opcodes = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VI};
+
+    if (!ST->hasVInstructions())
+      return InstructionCost::getInvalid();
+
+    if (LT.second.getScalarType() == MVT::i1) {
+      SmallVector<unsigned, 8> AddOpcodes = {
+          RISCV::VMV1R_V, RISCV::VMV1R_V, RISCV::VMV_V_I,    RISCV::VMERGE_VIM,
+          RISCV::VMV_V_I, RISCV::VMV1R_V, RISCV::VMERGE_VIM, RISCV::VMSNE_VI};
+      return LT.first *
+                 (getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
+                  getRISCVInstructionCost(AddOpcodes, LT.second, CostKind)) +
+             1;
+    } else {
+      return LT.first * getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
+             1;
+    }
+    break;
+  }
   }
 
   if (ST->hasVInstructions() && RetTy->isVectorTy()) {
diff --git a/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll b/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
index 5126a6a0a3cbcd..d118f49f7cac8b 100644
--- a/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
@@ -2351,6 +2351,335 @@ define void @splat() {
   ret void
 }
 
+define void @splice() {
+; CHECK-LABEL: 'splice'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %1 = call <2 x i1> @llvm.experimental.vp.splice.v2i1(<2 x i1> poison, <2 x i1> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %2 = call <4 x i1> @llvm.experimental.vp.splice.v4i1(<4 x i1> poison, <4 x i1> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %3 = call <8 x i1> @llvm.experimental.vp.splice.v8i1(<8 x i1> poison, <8 x i1> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %4 = call <16 x i1> @llvm.experimental.vp.splice.v16i1(<16 x i1> poison, <16 x i1> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %5 = call <2 x i1> @llvm.experimental.vp.splice.v2i1(<2 x i1> poison, <2 x i1> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %6 = call <4 x i1> @llvm.experimental.vp.splice.v4i1(<4 x i1> poison, <4 x i1> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %7 = call <8 x i1> @llvm.experimental.vp.splice.v8i1(<8 x i1> poison, <8 x i1> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %8 = call <16 x i1> @llvm.experimental.vp.splice.v16i1(<16 x i1> poison, <16 x i1> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %9 = call <2 x i8> @llvm.experimental.vp.splice.v2i8(<2 x i8> poison, <2 x i8> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %10 = call <4 x i8> @llvm.experimental.vp.splice.v4i8(<4 x i8> poison, <4 x i8> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %11 = call <8 x i8> @llvm.experimental.vp.splice.v8i8(<8 x i8> poison, <8 x i8> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %12 = call <16 x i8> @llvm.experimental.vp.splice.v16i8(<16 x i8> poison, <16 x i8> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %13 = call <vscale x 2 x i8> @llvm.experimental.vp.splice.nxv2i8(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %14 = call <vscale x 4 x i8> @llvm.experimental.vp.splice.nxv4i8(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %15 = call <vscale x 8 x i8> @llvm.experimental.vp.splice.nxv8i8(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %16 = call <vscale x 16 x i8> @llvm.experimental.vp.splice.nxv16i8(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %17 = call <2 x i8> @llvm.experimental.vp.splice.v2i8(<2 x i8> poison, <2 x i8> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %18 = call <4 x i8> @llvm.experimental.vp.splice.v4i8(<4 x i8> poison, <4 x i8> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %19 = call <8 x i8> @llvm.experimental.vp.splice.v8i8(<8 x i8> poison, <8 x i8> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %20 = call <16 x i8> @llvm.experimental.vp.splice.v16i8(<16 x i8> poison, <16 x i8> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %21 = call <vscale x 2 x i8> @llvm.experimental.vp.splice.nxv2i8(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %22 = call <vscale x 4 x i8> @llvm.experimental.vp.splice.nxv4i8(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %23 = call <vscale x 8 x i8> @llvm.experimental.vp.splice.nxv8i8(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %24 = call <vscale x 16 x i8> @llvm.experimental.vp.splice.nxv16i8(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %25 = call <2 x i16> @llvm.experimental.vp.splice.v2i16(<2 x i16> poison, <2 x i16> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %26 = call <4 x i16> @llvm.experimental.vp.splice.v4i16(<4 x i16> poison, <4 x i16> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %27 = call <8 x i16> @llvm.experimental.vp.splice.v8i16(<8 x i16> poison, <8 x i16> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %28 = call <16 x i16> @llvm.experimental.vp.splice.v16i16(<16 x i16> poison, <16 x i16> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %29 = call <vscale x 2 x i16> @llvm.experimental.vp.splice.nxv2i16(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %30 = call <vscale x 4 x i16> @llvm.experimental.vp.splice.nxv4i16(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %31 = call <vscale x 8 x i16> @llvm.experimental.vp.splice.nxv8i16(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %32 = call <vscale x 16 x i16> @llvm.experimental.vp.splice.nxv16i16(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %33 = call <2 x i16> @llvm.experimental.vp.splice.v2i16(<2 x i16> poison, <2 x i16> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %34 = call <4 x i16> @llvm.experimental.vp.splice.v4i16(<4 x i16> poison, <4 x i16> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %35 = call <8 x i16> @llvm.experimental.vp.splice.v8i16(<8 x i16> poison, <8 x i16> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %36 = call <16 x i16> @llvm.experimental.vp.splice.v16i16(<16 x i16> poison, <16 x i16> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %37 = call <vscale x 2 x i16> @llvm.experimental.vp.splice.nxv2i16(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %38 = call <vscale x 4 x i16> @llvm.experimental.vp.splice.nxv4i16(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %39 = call <vscale x 8 x i16> @llvm.experimental.vp.splice.nxv8i16(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %40 = call <vscale x 16 x i16> @llvm.experimental.vp.splice.nxv16i16(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %41 = call <2 x i32> @llvm.experimental.vp.splice.v2i32(<2 x i32> poison, <2 x i32> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %42 = call <4 x i32> @llvm.experimental.vp.splice.v4i32(<4 x i32> poison, <4 x i32> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %43 = call <8 x i32> @llvm.experimental.vp.splice.v8i32(<8 x i32> poison, <8 x i32> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %44 = call <16 x i32> @llvm.experimental.vp.splice.v16i32(<16 x i32> poison, <16 x i32> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %45 = call <vscale x 2 x i32> @llvm.experimental.vp.splice.nxv2i32(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %46 = call <vscale x 4 x i32> @llvm.experimental.vp.splice.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %47 = call <vscale x 8 x i32> @llvm.experimental.vp.splice.nxv8i32(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %48 = call <vscale x 16 x i32> @llvm.experimental.vp.splice.nxv16i32(<vscale x 16 x i32> poison, <vscale x 16 x i32> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %49 = call <2 x i32> @llvm.experimental.vp.splice.v2i32(<2 x i32> poison, <2 x i32> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %50 = call <4 x i32> @llvm.experimental.vp.splice.v4i32(<4 x i32> poison, <4 x i32> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %51 = call <8 x i32> @llvm.experimental.vp.splice.v8i32(<8 x i32> poison, <8 x i32> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %52 = call <16 x i32> @llvm.experimental.vp.splice.v16i32(<16 x i32> poison, <16 x i32> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %53 = call <vscale x 2 x i32> @llvm.experimental.vp.splice.nxv2i32(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %54 = call <vscale x 4 x i32> @llvm.experimental.vp.splice.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %55 = call <vscale x 8 x i32> @llvm.experimental.vp.splice.nxv8i32(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %56 = call <vscale x 16 x i32> @llvm.experimental.vp.splice.nxv16i32(<vscale x 16 x i32> poison, <vscale x 16 x i32> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %57 = call <2 x i64> @llvm.experimental.vp.splice.v2i64(<2 x i64> poison, <2 x i64> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %58 = call <4 x i64> @llvm.experimental.vp.splice.v4i64(<4 x i64> poison, <4 x i64> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %59 = call <8 x i64> @llvm.experimental.vp.splice.v8i64(<8 x i64> poison, <8 x i64> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %60 = call <16 x i64> @llvm.experimental.vp.splice.v16i64(<16 x i64> poison, <16 x i64> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %61 = call <vscale x 2 x i64> @llvm.experimental.vp.splice.nxv2i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %62 = call <vscale x 4 x i64> @llvm.experimental.vp.splice.nxv4i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %63 = call <vscale x 8 x i64> @llvm.experimental.vp.splice.nxv8i64(<vscale x 8 x i64> poison, <vscale x 8 x i64> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %64 = call <vscale x 16 x i64> @llvm.experimental.vp.splice.nxv16i64(<vscale x 16 x i64> poison, <vscale x 16 x i64> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %65 = call <2 x i64> @llvm.experimental.vp.splice.v2i64(<2 x i64> poison, <2 x i64> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %66 = call <4 x i64> @llvm.experimental.vp.splice.v4i64(<4 x i64> poison, <4 x i64> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %67 = call <8 x i64> @llvm.experimental.vp.splice.v8i64(<8 x i64> poison, <8 x i64> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %68 = call <16 x i64> @llvm.experimental.vp.splice.v16i64(<16 x i64> poison, <16 x i64> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %69 = call <vscale x 2 x i64> @llvm.experimental.vp.splice.nxv2i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %70 = call <vscale x 4 x i64> @llvm.experimental.vp.splice.nxv4i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %71 = call <vscale x 8 x i64> @llvm.experimental.vp.splice.nxv8i64(<vscale x 8 x i64> poison, <vscale x 8 x i64> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %72 = call <vscale x 16 x i64> @llvm.experimental.vp.splice.nxv16i64(<vscale x 16 x i64> poison, <vscale x 16 x i64> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %73 = call <2 x float> @llvm.experimental.vp.splice.v2f32(<2 x float> poison, <2 x float> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %74 = call <4 x float> @llvm.experimental.vp.splice.v4f32(<4 x float> poison, <4 x float> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %75 = call <8 x float> @llvm.experimental.vp.splice.v8f32(<8 x float> poison, <8 x float> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %76 = call <16 x float> @llvm.experimental.vp.splice.v16f32(<16 x float> poison, <16 x float> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %77 = call <vscale x 2 x float> @llvm.experimental.vp.splice.nxv2f32(<vscale x 2 x float> poison, <vscale x 2 x float> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Mode...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2025

@llvm/pr-subscribers-backend-risc-v

Author: LiqinWeng (LiqinWeng)

Changes

Patch is 67.15 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/122223.diff

3 Files Affected:

  • (modified) llvm/lib/Analysis/CostModel.cpp (+1)
  • (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+27)
  • (modified) llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll (+329)
diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp
index ee6622516a5ac0..af3e69f854a86a 100644
--- a/llvm/lib/Analysis/CostModel.cpp
+++ b/llvm/lib/Analysis/CostModel.cpp
@@ -54,6 +54,7 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
       // TODO: Use a pass parameter instead of cl::opt CostKind to determine
       // which cost kind to print.
       InstructionCost Cost;
+      SmallVector<Value *, 6> Args;
       auto *II = dyn_cast<IntrinsicInst>(&Inst);
       if (II && TypeBasedIntrinsicCost) {
         IntrinsicCostAttributes ICA(II->getIntrinsicID(), *II,
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 850d6244affa50..6789944d9c6cab 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1189,6 +1189,33 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
                                                   : RISCV::VMV_V_X,
                                               LT.second, CostKind);
   }
+  case Intrinsic::experimental_vp_splice: {
+    auto LT = getTypeLegalizationCost(RetTy);
+    SmallVector<unsigned, 3> Opcodes;
+    Value *ImmValue = *(ICA.getInst()->arg_begin() + 2);
+    auto *Imm = dyn_cast<ConstantInt>(ImmValue);
+    if (Imm->isNegative())
+      Opcodes = {RISCV::VSLIDEDOWN_VI, RISCV::VSLIDEUP_VX};
+    else
+      Opcodes = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VI};
+
+    if (!ST->hasVInstructions())
+      return InstructionCost::getInvalid();
+
+    if (LT.second.getScalarType() == MVT::i1) {
+      SmallVector<unsigned, 8> AddOpcodes = {
+          RISCV::VMV1R_V, RISCV::VMV1R_V, RISCV::VMV_V_I,    RISCV::VMERGE_VIM,
+          RISCV::VMV_V_I, RISCV::VMV1R_V, RISCV::VMERGE_VIM, RISCV::VMSNE_VI};
+      return LT.first *
+                 (getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
+                  getRISCVInstructionCost(AddOpcodes, LT.second, CostKind)) +
+             1;
+    } else {
+      return LT.first * getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
+             1;
+    }
+    break;
+  }
   }
 
   if (ST->hasVInstructions() && RetTy->isVectorTy()) {
diff --git a/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll b/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
index 5126a6a0a3cbcd..d118f49f7cac8b 100644
--- a/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/vp-intrinsics.ll
@@ -2351,6 +2351,335 @@ define void @splat() {
   ret void
 }
 
+define void @splice() {
+; CHECK-LABEL: 'splice'
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %1 = call <2 x i1> @llvm.experimental.vp.splice.v2i1(<2 x i1> poison, <2 x i1> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %2 = call <4 x i1> @llvm.experimental.vp.splice.v4i1(<4 x i1> poison, <4 x i1> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %3 = call <8 x i1> @llvm.experimental.vp.splice.v8i1(<8 x i1> poison, <8 x i1> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %4 = call <16 x i1> @llvm.experimental.vp.splice.v16i1(<16 x i1> poison, <16 x i1> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %5 = call <2 x i1> @llvm.experimental.vp.splice.v2i1(<2 x i1> poison, <2 x i1> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %6 = call <4 x i1> @llvm.experimental.vp.splice.v4i1(<4 x i1> poison, <4 x i1> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %7 = call <8 x i1> @llvm.experimental.vp.splice.v8i1(<8 x i1> poison, <8 x i1> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 11 for instruction: %8 = call <16 x i1> @llvm.experimental.vp.splice.v16i1(<16 x i1> poison, <16 x i1> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %9 = call <2 x i8> @llvm.experimental.vp.splice.v2i8(<2 x i8> poison, <2 x i8> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %10 = call <4 x i8> @llvm.experimental.vp.splice.v4i8(<4 x i8> poison, <4 x i8> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %11 = call <8 x i8> @llvm.experimental.vp.splice.v8i8(<8 x i8> poison, <8 x i8> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %12 = call <16 x i8> @llvm.experimental.vp.splice.v16i8(<16 x i8> poison, <16 x i8> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %13 = call <vscale x 2 x i8> @llvm.experimental.vp.splice.nxv2i8(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %14 = call <vscale x 4 x i8> @llvm.experimental.vp.splice.nxv4i8(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %15 = call <vscale x 8 x i8> @llvm.experimental.vp.splice.nxv8i8(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %16 = call <vscale x 16 x i8> @llvm.experimental.vp.splice.nxv16i8(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %17 = call <2 x i8> @llvm.experimental.vp.splice.v2i8(<2 x i8> poison, <2 x i8> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %18 = call <4 x i8> @llvm.experimental.vp.splice.v4i8(<4 x i8> poison, <4 x i8> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %19 = call <8 x i8> @llvm.experimental.vp.splice.v8i8(<8 x i8> poison, <8 x i8> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %20 = call <16 x i8> @llvm.experimental.vp.splice.v16i8(<16 x i8> poison, <16 x i8> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %21 = call <vscale x 2 x i8> @llvm.experimental.vp.splice.nxv2i8(<vscale x 2 x i8> poison, <vscale x 2 x i8> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %22 = call <vscale x 4 x i8> @llvm.experimental.vp.splice.nxv4i8(<vscale x 4 x i8> poison, <vscale x 4 x i8> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %23 = call <vscale x 8 x i8> @llvm.experimental.vp.splice.nxv8i8(<vscale x 8 x i8> poison, <vscale x 8 x i8> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %24 = call <vscale x 16 x i8> @llvm.experimental.vp.splice.nxv16i8(<vscale x 16 x i8> poison, <vscale x 16 x i8> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %25 = call <2 x i16> @llvm.experimental.vp.splice.v2i16(<2 x i16> poison, <2 x i16> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %26 = call <4 x i16> @llvm.experimental.vp.splice.v4i16(<4 x i16> poison, <4 x i16> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %27 = call <8 x i16> @llvm.experimental.vp.splice.v8i16(<8 x i16> poison, <8 x i16> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %28 = call <16 x i16> @llvm.experimental.vp.splice.v16i16(<16 x i16> poison, <16 x i16> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %29 = call <vscale x 2 x i16> @llvm.experimental.vp.splice.nxv2i16(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %30 = call <vscale x 4 x i16> @llvm.experimental.vp.splice.nxv4i16(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %31 = call <vscale x 8 x i16> @llvm.experimental.vp.splice.nxv8i16(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %32 = call <vscale x 16 x i16> @llvm.experimental.vp.splice.nxv16i16(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %33 = call <2 x i16> @llvm.experimental.vp.splice.v2i16(<2 x i16> poison, <2 x i16> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %34 = call <4 x i16> @llvm.experimental.vp.splice.v4i16(<4 x i16> poison, <4 x i16> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %35 = call <8 x i16> @llvm.experimental.vp.splice.v8i16(<8 x i16> poison, <8 x i16> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %36 = call <16 x i16> @llvm.experimental.vp.splice.v16i16(<16 x i16> poison, <16 x i16> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %37 = call <vscale x 2 x i16> @llvm.experimental.vp.splice.nxv2i16(<vscale x 2 x i16> poison, <vscale x 2 x i16> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %38 = call <vscale x 4 x i16> @llvm.experimental.vp.splice.nxv4i16(<vscale x 4 x i16> poison, <vscale x 4 x i16> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %39 = call <vscale x 8 x i16> @llvm.experimental.vp.splice.nxv8i16(<vscale x 8 x i16> poison, <vscale x 8 x i16> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %40 = call <vscale x 16 x i16> @llvm.experimental.vp.splice.nxv16i16(<vscale x 16 x i16> poison, <vscale x 16 x i16> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %41 = call <2 x i32> @llvm.experimental.vp.splice.v2i32(<2 x i32> poison, <2 x i32> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %42 = call <4 x i32> @llvm.experimental.vp.splice.v4i32(<4 x i32> poison, <4 x i32> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %43 = call <8 x i32> @llvm.experimental.vp.splice.v8i32(<8 x i32> poison, <8 x i32> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %44 = call <16 x i32> @llvm.experimental.vp.splice.v16i32(<16 x i32> poison, <16 x i32> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %45 = call <vscale x 2 x i32> @llvm.experimental.vp.splice.nxv2i32(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %46 = call <vscale x 4 x i32> @llvm.experimental.vp.splice.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %47 = call <vscale x 8 x i32> @llvm.experimental.vp.splice.nxv8i32(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %48 = call <vscale x 16 x i32> @llvm.experimental.vp.splice.nxv16i32(<vscale x 16 x i32> poison, <vscale x 16 x i32> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %49 = call <2 x i32> @llvm.experimental.vp.splice.v2i32(<2 x i32> poison, <2 x i32> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %50 = call <4 x i32> @llvm.experimental.vp.splice.v4i32(<4 x i32> poison, <4 x i32> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %51 = call <8 x i32> @llvm.experimental.vp.splice.v8i32(<8 x i32> poison, <8 x i32> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %52 = call <16 x i32> @llvm.experimental.vp.splice.v16i32(<16 x i32> poison, <16 x i32> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %53 = call <vscale x 2 x i32> @llvm.experimental.vp.splice.nxv2i32(<vscale x 2 x i32> poison, <vscale x 2 x i32> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %54 = call <vscale x 4 x i32> @llvm.experimental.vp.splice.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %55 = call <vscale x 8 x i32> @llvm.experimental.vp.splice.nxv8i32(<vscale x 8 x i32> poison, <vscale x 8 x i32> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %56 = call <vscale x 16 x i32> @llvm.experimental.vp.splice.nxv16i32(<vscale x 16 x i32> poison, <vscale x 16 x i32> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %57 = call <2 x i64> @llvm.experimental.vp.splice.v2i64(<2 x i64> poison, <2 x i64> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %58 = call <4 x i64> @llvm.experimental.vp.splice.v4i64(<4 x i64> poison, <4 x i64> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %59 = call <8 x i64> @llvm.experimental.vp.splice.v8i64(<8 x i64> poison, <8 x i64> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %60 = call <16 x i64> @llvm.experimental.vp.splice.v16i64(<16 x i64> poison, <16 x i64> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %61 = call <vscale x 2 x i64> @llvm.experimental.vp.splice.nxv2i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %62 = call <vscale x 4 x i64> @llvm.experimental.vp.splice.nxv4i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, i32 1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %63 = call <vscale x 8 x i64> @llvm.experimental.vp.splice.nxv8i64(<vscale x 8 x i64> poison, <vscale x 8 x i64> poison, i32 1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %64 = call <vscale x 16 x i64> @llvm.experimental.vp.splice.nxv16i64(<vscale x 16 x i64> poison, <vscale x 16 x i64> poison, i32 1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %65 = call <2 x i64> @llvm.experimental.vp.splice.v2i64(<2 x i64> poison, <2 x i64> poison, i32 -1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %66 = call <4 x i64> @llvm.experimental.vp.splice.v4i64(<4 x i64> poison, <4 x i64> poison, i32 -1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %67 = call <8 x i64> @llvm.experimental.vp.splice.v8i64(<8 x i64> poison, <8 x i64> poison, i32 -1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %68 = call <16 x i64> @llvm.experimental.vp.splice.v16i64(<16 x i64> poison, <16 x i64> poison, i32 -1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %69 = call <vscale x 2 x i64> @llvm.experimental.vp.splice.nxv2i64(<vscale x 2 x i64> poison, <vscale x 2 x i64> poison, i32 -1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %70 = call <vscale x 4 x i64> @llvm.experimental.vp.splice.nxv4i64(<vscale x 4 x i64> poison, <vscale x 4 x i64> poison, i32 -1, <vscale x 4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %71 = call <vscale x 8 x i64> @llvm.experimental.vp.splice.nxv8i64(<vscale x 8 x i64> poison, <vscale x 8 x i64> poison, i32 -1, <vscale x 8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %72 = call <vscale x 16 x i64> @llvm.experimental.vp.splice.nxv16i64(<vscale x 16 x i64> poison, <vscale x 16 x i64> poison, i32 -1, <vscale x 16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %73 = call <2 x float> @llvm.experimental.vp.splice.v2f32(<2 x float> poison, <2 x float> poison, i32 1, <2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %74 = call <4 x float> @llvm.experimental.vp.splice.v4f32(<4 x float> poison, <4 x float> poison, i32 1, <4 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %75 = call <8 x float> @llvm.experimental.vp.splice.v8f32(<8 x float> poison, <8 x float> poison, i32 1, <8 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %76 = call <16 x float> @llvm.experimental.vp.splice.v16f32(<16 x float> poison, <16 x float> poison, i32 1, <16 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %77 = call <vscale x 2 x float> @llvm.experimental.vp.splice.nxv2f32(<vscale x 2 x float> poison, <vscale x 2 x float> poison, i32 1, <vscale x 2 x i1> poison, i32 poison, i32 poison)
+; CHECK-NEXT:  Cost Mode...
[truncated]

auto LT = getTypeLegalizationCost(RetTy);
SmallVector<unsigned, 3> Opcodes;
Value *ImmValue = *(ICA.getInst()->arg_begin() + 2);
auto *Imm = dyn_cast<ConstantInt>(ImmValue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use dyn_cast, you must check the result for null before dereferencing. If can't be null, use cast.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -1235,6 +1235,33 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
: RISCV::VMV_V_X,
LT.second, CostKind);
}
case Intrinsic::experimental_vp_splice: {
auto LT = getTypeLegalizationCost(RetTy);
SmallVector<unsigned, 3> Opcodes;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3->2. The are only 2 opcodes in your lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return InstructionCost::getInvalid();

if (LT.second.getScalarType() == MVT::i1) {
SmallVector<unsigned, 8> AddOpcodes = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a normal C array here. It doesn't need to be a SmallVector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

case Intrinsic::experimental_vp_splice: {
auto LT = getTypeLegalizationCost(RetTy);
SmallVector<unsigned, 2> Opcodes;
Value *ImmValue = *(ICA.getInst()->arg_begin() + 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getInst()->getArgOperand(2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

(getRISCVInstructionCost(Opcodes, LT.second, CostKind) +
getRISCVInstructionCost(AddOpcodes, LT.second, CostKind)) +
1;
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No else if the if body returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@LiqinWeng
Copy link
Contributor Author

any problem with this patch?@topperc:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants