[llvm] [RISCV][CostModel] Estimate cost of Extract/InsertElement with non-constant index when vector instructions are not available (PR #67334)

Sergey Kachkov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 03:06:03 PDT 2023


https://github.com/skachkov-sc updated https://github.com/llvm/llvm-project/pull/67334

>From bf83e01d0ba4e82c80f95d114dc6359ae0302766 Mon Sep 17 00:00:00 2001
From: Sergey Kachkov <sergey.kachkov at syntacore.com>
Date: Tue, 26 Sep 2023 15:41:35 +0300
Subject: [PATCH 1/2] [RISCV][CostModel] Add pre-commit test

---
 .../CostModel/RISCV/extractelement.ll         | 135 ++++++++++++++++++
 .../Analysis/CostModel/RISCV/insertelement.ll | 135 ++++++++++++++++++
 2 files changed, 270 insertions(+)
 create mode 100644 llvm/test/Analysis/CostModel/RISCV/extractelement.ll
 create mode 100644 llvm/test/Analysis/CostModel/RISCV/insertelement.ll

diff --git a/llvm/test/Analysis/CostModel/RISCV/extractelement.ll b/llvm/test/Analysis/CostModel/RISCV/extractelement.ll
new file mode 100644
index 000000000000000..09a78405f5836cd
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/RISCV/extractelement.ll
@@ -0,0 +1,135 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 3
+; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv32 -mattr=+f,+d,+zfh < %s | FileCheck %s --check-prefixes=RV32
+; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv64 -mattr=+f,+d,+zfh < %s | FileCheck %s --check-prefixes=RV64
+
+define void @extractelement_int(i32 %x) {
+; RV32-LABEL: 'extractelement_int'
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = extractelement <2 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = extractelement <4 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = extractelement <8 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = extractelement <16 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = extractelement <vscale x 16 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = extractelement <2 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = extractelement <4 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = extractelement <8 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = extractelement <16 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = extractelement <vscale x 16 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = extractelement <2 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = extractelement <4 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = extractelement <8 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = extractelement <16 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = extractelement <vscale x 16 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = extractelement <2 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = extractelement <4 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = extractelement <8 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = extractelement <16 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = extractelement <vscale x 16 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; RV64-LABEL: 'extractelement_int'
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = extractelement <2 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = extractelement <4 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = extractelement <8 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = extractelement <16 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = extractelement <vscale x 16 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = extractelement <2 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = extractelement <4 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = extractelement <8 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = extractelement <16 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = extractelement <vscale x 16 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = extractelement <2 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = extractelement <4 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = extractelement <8 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = extractelement <16 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = extractelement <vscale x 16 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = extractelement <2 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = extractelement <4 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = extractelement <8 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = extractelement <16 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = extractelement <vscale x 16 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %v2i8 = extractelement <2 x i8> undef, i32 %x
+  %v4i8 = extractelement <4 x i8> undef, i32 %x
+  %v8i8 = extractelement <8 x i8> undef, i32 %x
+  %v16i8 = extractelement <16 x i8> undef, i32 %x
+  %nxv16i8 = extractelement <vscale x 16 x i8> undef, i32 %x
+
+  %v2i16 = extractelement <2 x i16> undef, i32 %x
+  %v4i16 = extractelement <4 x i16> undef, i32 %x
+  %v8i16 = extractelement <8 x i16> undef, i32 %x
+  %v16i16 = extractelement <16 x i16> undef, i32 %x
+  %nxv16i16 = extractelement <vscale x 16 x i16> undef, i32 %x
+
+  %v2i32 = extractelement <2 x i32> undef, i32 %x
+  %v4i32 = extractelement <4 x i32> undef, i32 %x
+  %v8i32 = extractelement <8 x i32> undef, i32 %x
+  %v16i32 = extractelement <16 x i32> undef, i32 %x
+  %nxv16i32 = extractelement <vscale x 16 x i32> undef, i32 %x
+
+  %v2i64 = extractelement <2 x i64> undef, i32 %x
+  %v4i64 = extractelement <4 x i64> undef, i32 %x
+  %v8i64 = extractelement <8 x i64> undef, i32 %x
+  %v16i64 = extractelement <16 x i64> undef, i32 %x
+  %nxv16i64 = extractelement <vscale x 16 x i64> undef, i32 %x
+
+  ret void
+}
+
+define void @extractelement_fp(i32 %x) {
+; RV32-LABEL: 'extractelement_fp'
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = extractelement <2 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = extractelement <4 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = extractelement <8 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = extractelement <16 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = extractelement <vscale x 16 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = extractelement <2 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = extractelement <4 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = extractelement <8 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = extractelement <16 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = extractelement <vscale x 16 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = extractelement <2 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = extractelement <4 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = extractelement <8 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = extractelement <16 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = extractelement <vscale x 16 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; RV64-LABEL: 'extractelement_fp'
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = extractelement <2 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = extractelement <4 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = extractelement <8 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = extractelement <16 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = extractelement <vscale x 16 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = extractelement <2 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = extractelement <4 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = extractelement <8 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = extractelement <16 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = extractelement <vscale x 16 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = extractelement <2 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = extractelement <4 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = extractelement <8 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = extractelement <16 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = extractelement <vscale x 16 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %v2f16 = extractelement <2 x half> undef, i32 %x
+  %v4f16 = extractelement <4 x half> undef, i32 %x
+  %v8f16 = extractelement <8 x half> undef, i32 %x
+  %v16f16 = extractelement <16 x half> undef, i32 %x
+  %nxv16f16 = extractelement <vscale x 16 x half> undef, i32 %x
+
+  %v2f32 = extractelement <2 x float> undef, i32 %x
+  %v4f32 = extractelement <4 x float> undef, i32 %x
+  %v8f32 = extractelement <8 x float> undef, i32 %x
+  %v16f32 = extractelement <16 x float> undef, i32 %x
+  %nxv16f32 = extractelement <vscale x 16 x float> undef, i32 %x
+
+  %v2f64 = extractelement <2 x double> undef, i32 %x
+  %v4f64 = extractelement <4 x double> undef, i32 %x
+  %v8f64 = extractelement <8 x double> undef, i32 %x
+  %v16f64 = extractelement <16 x double> undef, i32 %x
+  %nxv16f64 = extractelement <vscale x 16 x double> undef, i32 %x
+
+  ret void
+}
diff --git a/llvm/test/Analysis/CostModel/RISCV/insertelement.ll b/llvm/test/Analysis/CostModel/RISCV/insertelement.ll
new file mode 100644
index 000000000000000..5df3b4ee69c123a
--- /dev/null
+++ b/llvm/test/Analysis/CostModel/RISCV/insertelement.ll
@@ -0,0 +1,135 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 3
+; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv32 -mattr=+f,+d,+zfh < %s | FileCheck %s --check-prefixes=RV32
+; RUN: opt -passes="print<cost-model>" 2>&1 -disable-output -mtriple=riscv64 -mattr=+f,+d,+zfh < %s | FileCheck %s --check-prefixes=RV64
+
+define void @insertelement_int(i32 %x) {
+; RV32-LABEL: 'insertelement_int'
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = insertelement <2 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = insertelement <4 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = insertelement <8 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = insertelement <16 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = insertelement <vscale x 16 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = insertelement <2 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = insertelement <4 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = insertelement <8 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = insertelement <16 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = insertelement <vscale x 16 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = insertelement <2 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = insertelement <4 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = insertelement <8 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = insertelement <16 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = insertelement <vscale x 16 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = insertelement <2 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = insertelement <4 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = insertelement <8 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = insertelement <16 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = insertelement <vscale x 16 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; RV64-LABEL: 'insertelement_int'
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = insertelement <2 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = insertelement <4 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = insertelement <8 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = insertelement <16 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = insertelement <vscale x 16 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = insertelement <2 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = insertelement <4 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = insertelement <8 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = insertelement <16 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = insertelement <vscale x 16 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = insertelement <2 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = insertelement <4 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = insertelement <8 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = insertelement <16 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = insertelement <vscale x 16 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = insertelement <2 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = insertelement <4 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = insertelement <8 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = insertelement <16 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = insertelement <vscale x 16 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %v2i8 = insertelement <2 x i8> undef, i8 undef, i32 %x
+  %v4i8 = insertelement <4 x i8> undef, i8 undef, i32 %x
+  %v8i8 = insertelement <8 x i8> undef, i8 undef, i32 %x
+  %v16i8 = insertelement <16 x i8> undef, i8 undef, i32 %x
+  %nxv16i8 = insertelement <vscale x 16 x i8> undef, i8 undef, i32 %x
+
+  %v2i16 = insertelement <2 x i16> undef, i16 undef, i32 %x
+  %v4i16 = insertelement <4 x i16> undef, i16 undef, i32 %x
+  %v8i16 = insertelement <8 x i16> undef, i16 undef, i32 %x
+  %v16i16 = insertelement <16 x i16> undef, i16 undef, i32 %x
+  %nxv16i16 = insertelement <vscale x 16 x i16> undef, i16 undef, i32 %x
+
+  %v2i32 = insertelement <2 x i32> undef, i32 undef, i32 %x
+  %v4i32 = insertelement <4 x i32> undef, i32 undef, i32 %x
+  %v8i32 = insertelement <8 x i32> undef, i32 undef, i32 %x
+  %v16i32 = insertelement <16 x i32> undef, i32 undef, i32 %x
+  %nxv16i32 = insertelement <vscale x 16 x i32> undef, i32 undef, i32 %x
+
+  %v2i64 = insertelement <2 x i64> undef, i64 undef, i32 %x
+  %v4i64 = insertelement <4 x i64> undef, i64 undef, i32 %x
+  %v8i64 = insertelement <8 x i64> undef, i64 undef, i32 %x
+  %v16i64 = insertelement <16 x i64> undef, i64 undef, i32 %x
+  %nxv16i64 = insertelement <vscale x 16 x i64> undef, i64 undef, i32 %x
+
+  ret void
+}
+
+define void @insertelement_fp(i32 %x) {
+; RV32-LABEL: 'insertelement_fp'
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = insertelement <2 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = insertelement <4 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = insertelement <8 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = insertelement <16 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = insertelement <vscale x 16 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = insertelement <2 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = insertelement <4 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = insertelement <8 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = insertelement <16 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = insertelement <vscale x 16 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = insertelement <2 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = insertelement <4 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = insertelement <8 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = insertelement <16 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = insertelement <vscale x 16 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+; RV64-LABEL: 'insertelement_fp'
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = insertelement <2 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = insertelement <4 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = insertelement <8 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = insertelement <16 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = insertelement <vscale x 16 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = insertelement <2 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = insertelement <4 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = insertelement <8 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = insertelement <16 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = insertelement <vscale x 16 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = insertelement <2 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = insertelement <4 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = insertelement <8 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = insertelement <16 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = insertelement <vscale x 16 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  %v2f16 = insertelement <2 x half> undef, half undef, i32 %x
+  %v4f16 = insertelement <4 x half> undef, half undef, i32 %x
+  %v8f16 = insertelement <8 x half> undef, half undef, i32 %x
+  %v16f16 = insertelement <16 x half> undef, half undef, i32 %x
+  %nxv16f16 = insertelement <vscale x 16 x half> undef, half undef, i32 %x
+
+  %v2f32 = insertelement <2 x float> undef, float undef, i32 %x
+  %v4f32 = insertelement <4 x float> undef, float undef, i32 %x
+  %v8f32 = insertelement <8 x float> undef, float undef, i32 %x
+  %v16f32 = insertelement <16 x float> undef, float undef, i32 %x
+  %nxv16f32 = insertelement <vscale x 16 x float> undef, float undef, i32 %x
+
+  %v2f64 = insertelement <2 x double> undef, double undef, i32 %x
+  %v4f64 = insertelement <4 x double> undef, double undef, i32 %x
+  %v8f64 = insertelement <8 x double> undef, double undef, i32 %x
+  %v16f64 = insertelement <16 x double> undef, double undef, i32 %x
+  %nxv16f64 = insertelement <vscale x 16 x double> undef, double undef, i32 %x
+
+  ret void
+}

>From 27394aeb42e7b29ff03ec192d4ba41cfc88cc741 Mon Sep 17 00:00:00 2001
From: Sergey Kachkov <sergey.kachkov at syntacore.com>
Date: Mon, 25 Sep 2023 15:26:09 +0300
Subject: [PATCH 2/2] [RISCV][CostModel] Calculate cost of
 Extract/InsertElement with non-constant index when vector instructions are
 not available

When vector instructions are not available, Extract/InsertElement with N-element
vector types and non-constant indexes are lowered in this way:
ExtractElement: N stores of each element on stack, 1 load of required element
InsertElement: N stores of each element on stack, 1 store to rewrite required
element, N loads of each element back

This patch implements cost calculation of these operations to fix compilation
time of matrix-types-spec test.
---
 .../Target/RISCV/RISCVTargetTransformInfo.cpp |  22 +++-
 .../CostModel/RISCV/extractelement.ll         | 112 +++++++++---------
 .../Analysis/CostModel/RISCV/insertelement.ll | 112 +++++++++---------
 .../CostModel/RISCV/rvv-extractelement.ll     |  60 +++++-----
 .../CostModel/RISCV/rvv-insertelement.ll      |  60 +++++-----
 5 files changed, 192 insertions(+), 174 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 1f069cb9eb514e4..ed7a040dac90c32 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1463,8 +1463,26 @@ InstructionCost RISCVTTIImpl::getVectorInstrCost(unsigned Opcode, Type *Val,
   std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Val);
 
   // This type is legalized to a scalar type.
-  if (!LT.second.isVector())
-    return 0;
+  if (!LT.second.isVector()) {
+    auto *FixedVecTy = cast<FixedVectorType>(Val);
+    // If Index is a known constant, cost is zero.
+    if (Index != -1U)
+      return 0;
+    // Extract/InsertElement with non-constant index is very costly when
+    // scalarized; estimate cost of loads/stores sequence via the stack:
+    // ExtractElement cost: store vector to stack, load scalar;
+    // InsertElement cost: store vector to stack, store scalar, load vector.
+    Type *ElemTy = FixedVecTy->getElementType();
+    auto NumElems = FixedVecTy->getNumElements();
+    auto Align = DL.getPrefTypeAlign(ElemTy);
+    InstructionCost LoadCost =
+        getMemoryOpCost(Instruction::Load, ElemTy, Align, 0, CostKind);
+    InstructionCost StoreCost =
+        getMemoryOpCost(Instruction::Store, ElemTy, Align, 0, CostKind);
+    return Opcode == Instruction::ExtractElement
+               ? StoreCost * NumElems + LoadCost
+               : (StoreCost + LoadCost) * NumElems + StoreCost;
+  }
 
   // For unsupported scalable vector.
   if (LT.second.isScalableVector() && !LT.first.isValid())
diff --git a/llvm/test/Analysis/CostModel/RISCV/extractelement.ll b/llvm/test/Analysis/CostModel/RISCV/extractelement.ll
index 09a78405f5836cd..83d74bf6840c382 100644
--- a/llvm/test/Analysis/CostModel/RISCV/extractelement.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/extractelement.ll
@@ -4,48 +4,48 @@
 
 define void @extractelement_int(i32 %x) {
 ; RV32-LABEL: 'extractelement_int'
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = extractelement <2 x i8> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = extractelement <4 x i8> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = extractelement <8 x i8> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = extractelement <16 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2i8 = extractelement <2 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4i8 = extractelement <4 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8i8 = extractelement <8 x i8> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16i8 = extractelement <16 x i8> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = extractelement <vscale x 16 x i8> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = extractelement <2 x i16> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = extractelement <4 x i16> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = extractelement <8 x i16> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = extractelement <16 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2i16 = extractelement <2 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4i16 = extractelement <4 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8i16 = extractelement <8 x i16> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16i16 = extractelement <16 x i16> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = extractelement <vscale x 16 x i16> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = extractelement <2 x i32> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = extractelement <4 x i32> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = extractelement <8 x i32> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = extractelement <16 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2i32 = extractelement <2 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4i32 = extractelement <4 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8i32 = extractelement <8 x i32> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16i32 = extractelement <16 x i32> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = extractelement <vscale x 16 x i32> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = extractelement <2 x i64> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = extractelement <4 x i64> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = extractelement <8 x i64> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = extractelement <16 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %v2i64 = extractelement <2 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %v4i64 = extractelement <4 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 18 for instruction: %v8i64 = extractelement <8 x i64> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 34 for instruction: %v16i64 = extractelement <16 x i64> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = extractelement <vscale x 16 x i64> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; RV64-LABEL: 'extractelement_int'
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = extractelement <2 x i8> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = extractelement <4 x i8> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = extractelement <8 x i8> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = extractelement <16 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2i8 = extractelement <2 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4i8 = extractelement <4 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8i8 = extractelement <8 x i8> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16i8 = extractelement <16 x i8> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = extractelement <vscale x 16 x i8> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = extractelement <2 x i16> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = extractelement <4 x i16> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = extractelement <8 x i16> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = extractelement <16 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2i16 = extractelement <2 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4i16 = extractelement <4 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8i16 = extractelement <8 x i16> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16i16 = extractelement <16 x i16> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = extractelement <vscale x 16 x i16> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = extractelement <2 x i32> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = extractelement <4 x i32> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = extractelement <8 x i32> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = extractelement <16 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2i32 = extractelement <2 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4i32 = extractelement <4 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8i32 = extractelement <8 x i32> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16i32 = extractelement <16 x i32> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = extractelement <vscale x 16 x i32> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = extractelement <2 x i64> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = extractelement <4 x i64> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = extractelement <8 x i64> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = extractelement <16 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2i64 = extractelement <2 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4i64 = extractelement <4 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8i64 = extractelement <8 x i64> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16i64 = extractelement <16 x i64> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = extractelement <vscale x 16 x i64> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
@@ -78,38 +78,38 @@ define void @extractelement_int(i32 %x) {
 
 define void @extractelement_fp(i32 %x) {
 ; RV32-LABEL: 'extractelement_fp'
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = extractelement <2 x half> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = extractelement <4 x half> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = extractelement <8 x half> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = extractelement <16 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f16 = extractelement <2 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f16 = extractelement <4 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f16 = extractelement <8 x half> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f16 = extractelement <16 x half> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = extractelement <vscale x 16 x half> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = extractelement <2 x float> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = extractelement <4 x float> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = extractelement <8 x float> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = extractelement <16 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f32 = extractelement <2 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f32 = extractelement <4 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f32 = extractelement <8 x float> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f32 = extractelement <16 x float> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = extractelement <vscale x 16 x float> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = extractelement <2 x double> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = extractelement <4 x double> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = extractelement <8 x double> undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = extractelement <16 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f64 = extractelement <2 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f64 = extractelement <4 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f64 = extractelement <8 x double> undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f64 = extractelement <16 x double> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = extractelement <vscale x 16 x double> undef, i32 %x
 ; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; RV64-LABEL: 'extractelement_fp'
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = extractelement <2 x half> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = extractelement <4 x half> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = extractelement <8 x half> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = extractelement <16 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f16 = extractelement <2 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f16 = extractelement <4 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f16 = extractelement <8 x half> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f16 = extractelement <16 x half> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = extractelement <vscale x 16 x half> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = extractelement <2 x float> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = extractelement <4 x float> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = extractelement <8 x float> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = extractelement <16 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f32 = extractelement <2 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f32 = extractelement <4 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f32 = extractelement <8 x float> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f32 = extractelement <16 x float> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = extractelement <vscale x 16 x float> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = extractelement <2 x double> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = extractelement <4 x double> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = extractelement <8 x double> undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = extractelement <16 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f64 = extractelement <2 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f64 = extractelement <4 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f64 = extractelement <8 x double> undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f64 = extractelement <16 x double> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = extractelement <vscale x 16 x double> undef, i32 %x
 ; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
diff --git a/llvm/test/Analysis/CostModel/RISCV/insertelement.ll b/llvm/test/Analysis/CostModel/RISCV/insertelement.ll
index 5df3b4ee69c123a..6a57d1586773362 100644
--- a/llvm/test/Analysis/CostModel/RISCV/insertelement.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/insertelement.ll
@@ -4,48 +4,48 @@
 
 define void @insertelement_int(i32 %x) {
 ; RV32-LABEL: 'insertelement_int'
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = insertelement <2 x i8> undef, i8 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = insertelement <4 x i8> undef, i8 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = insertelement <8 x i8> undef, i8 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = insertelement <16 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2i8 = insertelement <2 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4i8 = insertelement <4 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8i8 = insertelement <8 x i8> undef, i8 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16i8 = insertelement <16 x i8> undef, i8 undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = insertelement <vscale x 16 x i8> undef, i8 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = insertelement <2 x i16> undef, i16 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = insertelement <4 x i16> undef, i16 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = insertelement <8 x i16> undef, i16 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = insertelement <16 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2i16 = insertelement <2 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4i16 = insertelement <4 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8i16 = insertelement <8 x i16> undef, i16 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16i16 = insertelement <16 x i16> undef, i16 undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = insertelement <vscale x 16 x i16> undef, i16 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = insertelement <2 x i32> undef, i32 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = insertelement <4 x i32> undef, i32 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = insertelement <8 x i32> undef, i32 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = insertelement <16 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2i32 = insertelement <2 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4i32 = insertelement <4 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8i32 = insertelement <8 x i32> undef, i32 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16i32 = insertelement <16 x i32> undef, i32 undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = insertelement <vscale x 16 x i32> undef, i32 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = insertelement <2 x i64> undef, i64 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = insertelement <4 x i64> undef, i64 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = insertelement <8 x i64> undef, i64 undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = insertelement <16 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %v2i64 = insertelement <2 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 18 for instruction: %v4i64 = insertelement <4 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 34 for instruction: %v8i64 = insertelement <8 x i64> undef, i64 undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 66 for instruction: %v16i64 = insertelement <16 x i64> undef, i64 undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = insertelement <vscale x 16 x i64> undef, i64 undef, i32 %x
 ; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; RV64-LABEL: 'insertelement_int'
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i8 = insertelement <2 x i8> undef, i8 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i8 = insertelement <4 x i8> undef, i8 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i8 = insertelement <8 x i8> undef, i8 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i8 = insertelement <16 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2i8 = insertelement <2 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4i8 = insertelement <4 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8i8 = insertelement <8 x i8> undef, i8 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16i8 = insertelement <16 x i8> undef, i8 undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i8 = insertelement <vscale x 16 x i8> undef, i8 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i16 = insertelement <2 x i16> undef, i16 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i16 = insertelement <4 x i16> undef, i16 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i16 = insertelement <8 x i16> undef, i16 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i16 = insertelement <16 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2i16 = insertelement <2 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4i16 = insertelement <4 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8i16 = insertelement <8 x i16> undef, i16 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16i16 = insertelement <16 x i16> undef, i16 undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i16 = insertelement <vscale x 16 x i16> undef, i16 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i32 = insertelement <2 x i32> undef, i32 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i32 = insertelement <4 x i32> undef, i32 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i32 = insertelement <8 x i32> undef, i32 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i32 = insertelement <16 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2i32 = insertelement <2 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4i32 = insertelement <4 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8i32 = insertelement <8 x i32> undef, i32 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16i32 = insertelement <16 x i32> undef, i32 undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i32 = insertelement <vscale x 16 x i32> undef, i32 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2i64 = insertelement <2 x i64> undef, i64 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4i64 = insertelement <4 x i64> undef, i64 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8i64 = insertelement <8 x i64> undef, i64 undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16i64 = insertelement <16 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2i64 = insertelement <2 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4i64 = insertelement <4 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8i64 = insertelement <8 x i64> undef, i64 undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16i64 = insertelement <16 x i64> undef, i64 undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16i64 = insertelement <vscale x 16 x i64> undef, i64 undef, i32 %x
 ; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
@@ -78,38 +78,38 @@ define void @insertelement_int(i32 %x) {
 
 define void @insertelement_fp(i32 %x) {
 ; RV32-LABEL: 'insertelement_fp'
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = insertelement <2 x half> undef, half undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = insertelement <4 x half> undef, half undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = insertelement <8 x half> undef, half undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = insertelement <16 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f16 = insertelement <2 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f16 = insertelement <4 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f16 = insertelement <8 x half> undef, half undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f16 = insertelement <16 x half> undef, half undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = insertelement <vscale x 16 x half> undef, half undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = insertelement <2 x float> undef, float undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = insertelement <4 x float> undef, float undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = insertelement <8 x float> undef, float undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = insertelement <16 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f32 = insertelement <2 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f32 = insertelement <4 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f32 = insertelement <8 x float> undef, float undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f32 = insertelement <16 x float> undef, float undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = insertelement <vscale x 16 x float> undef, float undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = insertelement <2 x double> undef, double undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = insertelement <4 x double> undef, double undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = insertelement <8 x double> undef, double undef, i32 %x
-; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = insertelement <16 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f64 = insertelement <2 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f64 = insertelement <4 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f64 = insertelement <8 x double> undef, double undef, i32 %x
+; RV32-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f64 = insertelement <16 x double> undef, double undef, i32 %x
 ; RV32-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = insertelement <vscale x 16 x double> undef, double undef, i32 %x
 ; RV32-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; RV64-LABEL: 'insertelement_fp'
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16 = insertelement <2 x half> undef, half undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16 = insertelement <4 x half> undef, half undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16 = insertelement <8 x half> undef, half undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16 = insertelement <16 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f16 = insertelement <2 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f16 = insertelement <4 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f16 = insertelement <8 x half> undef, half undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f16 = insertelement <16 x half> undef, half undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16 = insertelement <vscale x 16 x half> undef, half undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32 = insertelement <2 x float> undef, float undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32 = insertelement <4 x float> undef, float undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32 = insertelement <8 x float> undef, float undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32 = insertelement <16 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f32 = insertelement <2 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f32 = insertelement <4 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f32 = insertelement <8 x float> undef, float undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f32 = insertelement <16 x float> undef, float undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32 = insertelement <vscale x 16 x float> undef, float undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64 = insertelement <2 x double> undef, double undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64 = insertelement <4 x double> undef, double undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64 = insertelement <8 x double> undef, double undef, i32 %x
-; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64 = insertelement <16 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f64 = insertelement <2 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f64 = insertelement <4 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f64 = insertelement <8 x double> undef, double undef, i32 %x
+; RV64-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f64 = insertelement <16 x double> undef, double undef, i32 %x
 ; RV64-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64 = insertelement <vscale x 16 x double> undef, double undef, i32 %x
 ; RV64-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-extractelement.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-extractelement.ll
index e33beaac4f4219a..225bad6da5915c0 100644
--- a/llvm/test/Analysis/CostModel/RISCV/rvv-extractelement.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/rvv-extractelement.ll
@@ -1202,32 +1202,32 @@ define void @extractelement_fp(i32 %x) {
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_1 = extractelement <vscale x 4 x double> undef, i32 1
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_1 = extractelement <vscale x 8 x double> undef, i32 1
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64_1 = extractelement <vscale x 16 x double> undef, i32 1
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16_x = extractelement <2 x half> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16_x = extractelement <4 x half> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16_x = extractelement <8 x half> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16_x = extractelement <16 x half> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f16_x = extractelement <32 x half> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v64f16_x = extractelement <64 x half> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f16_x = extractelement <2 x half> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f16_x = extractelement <4 x half> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f16_x = extractelement <8 x half> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f16_x = extractelement <16 x half> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v32f16_x = extractelement <32 x half> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 65 for instruction: %v64f16_x = extractelement <64 x half> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f16_x = extractelement <vscale x 2 x half> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f16_x = extractelement <vscale x 4 x half> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f16_x = extractelement <vscale x 8 x half> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16_x = extractelement <vscale x 16 x half> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f16_x = extractelement <vscale x 32 x half> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv64f16_x = extractelement <vscale x 64 x half> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32_x = extractelement <2 x float> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32_x = extractelement <4 x float> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32_x = extractelement <8 x float> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32_x = extractelement <16 x float> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f32_x = extractelement <32 x float> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f32_x = extractelement <2 x float> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f32_x = extractelement <4 x float> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f32_x = extractelement <8 x float> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f32_x = extractelement <16 x float> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v32f32_x = extractelement <32 x float> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f32_x = extractelement <vscale x 2 x float> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f32_x = extractelement <vscale x 4 x float> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f32_x = extractelement <vscale x 8 x float> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32_x = extractelement <vscale x 16 x float> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f32_x = extractelement <vscale x 32 x float> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64_x = extractelement <2 x double> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64_x = extractelement <4 x double> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64_x = extractelement <8 x double> undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64_x = extractelement <16 x double> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %v2f64_x = extractelement <2 x double> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %v4f64_x = extractelement <4 x double> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 18 for instruction: %v8f64_x = extractelement <8 x double> undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 34 for instruction: %v16f64_x = extractelement <16 x double> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f64_x = extractelement <vscale x 2 x double> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_x = extractelement <vscale x 4 x double> undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_x = extractelement <vscale x 8 x double> undef, i32 %x
@@ -1295,32 +1295,32 @@ define void @extractelement_fp(i32 %x) {
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_1 = extractelement <vscale x 4 x double> undef, i32 1
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_1 = extractelement <vscale x 8 x double> undef, i32 1
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64_1 = extractelement <vscale x 16 x double> undef, i32 1
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16_x = extractelement <2 x half> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16_x = extractelement <4 x half> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16_x = extractelement <8 x half> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16_x = extractelement <16 x half> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f16_x = extractelement <32 x half> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v64f16_x = extractelement <64 x half> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f16_x = extractelement <2 x half> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f16_x = extractelement <4 x half> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f16_x = extractelement <8 x half> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f16_x = extractelement <16 x half> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v32f16_x = extractelement <32 x half> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 65 for instruction: %v64f16_x = extractelement <64 x half> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f16_x = extractelement <vscale x 2 x half> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f16_x = extractelement <vscale x 4 x half> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f16_x = extractelement <vscale x 8 x half> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16_x = extractelement <vscale x 16 x half> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f16_x = extractelement <vscale x 32 x half> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv64f16_x = extractelement <vscale x 64 x half> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32_x = extractelement <2 x float> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32_x = extractelement <4 x float> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32_x = extractelement <8 x float> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32_x = extractelement <16 x float> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f32_x = extractelement <32 x float> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f32_x = extractelement <2 x float> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f32_x = extractelement <4 x float> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f32_x = extractelement <8 x float> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f32_x = extractelement <16 x float> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v32f32_x = extractelement <32 x float> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f32_x = extractelement <vscale x 2 x float> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f32_x = extractelement <vscale x 4 x float> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f32_x = extractelement <vscale x 8 x float> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32_x = extractelement <vscale x 16 x float> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f32_x = extractelement <vscale x 32 x float> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64_x = extractelement <2 x double> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64_x = extractelement <4 x double> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64_x = extractelement <8 x double> undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64_x = extractelement <16 x double> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %v2f64_x = extractelement <2 x double> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v4f64_x = extractelement <4 x double> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v8f64_x = extractelement <8 x double> undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v16f64_x = extractelement <16 x double> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f64_x = extractelement <vscale x 2 x double> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_x = extractelement <vscale x 4 x double> undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_x = extractelement <vscale x 8 x double> undef, i32 %x
diff --git a/llvm/test/Analysis/CostModel/RISCV/rvv-insertelement.ll b/llvm/test/Analysis/CostModel/RISCV/rvv-insertelement.ll
index a193857e6e0f89e..5387c8dc35940ea 100644
--- a/llvm/test/Analysis/CostModel/RISCV/rvv-insertelement.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/rvv-insertelement.ll
@@ -1202,32 +1202,32 @@ define void @insertelement_fp(i32 %x) {
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_1 = insertelement <vscale x 4 x double> undef, double undef, i32 1
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_1 = insertelement <vscale x 8 x double> undef, double undef, i32 1
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64_1 = insertelement <vscale x 16 x double> undef, double undef, i32 1
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16_x = insertelement <2 x half> undef, half undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16_x = insertelement <4 x half> undef, half undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16_x = insertelement <8 x half> undef, half undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16_x = insertelement <16 x half> undef, half undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f16_x = insertelement <32 x half> undef, half undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v64f16_x = insertelement <64 x half> undef, half undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f16_x = insertelement <2 x half> undef, half undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f16_x = insertelement <4 x half> undef, half undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f16_x = insertelement <8 x half> undef, half undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f16_x = insertelement <16 x half> undef, half undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 65 for instruction: %v32f16_x = insertelement <32 x half> undef, half undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 129 for instruction: %v64f16_x = insertelement <64 x half> undef, half undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f16_x = insertelement <vscale x 2 x half> undef, half undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f16_x = insertelement <vscale x 4 x half> undef, half undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f16_x = insertelement <vscale x 8 x half> undef, half undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16_x = insertelement <vscale x 16 x half> undef, half undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f16_x = insertelement <vscale x 32 x half> undef, half undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv64f16_x = insertelement <vscale x 64 x half> undef, half undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32_x = insertelement <2 x float> undef, float undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32_x = insertelement <4 x float> undef, float undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32_x = insertelement <8 x float> undef, float undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32_x = insertelement <16 x float> undef, float undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f32_x = insertelement <32 x float> undef, float undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f32_x = insertelement <2 x float> undef, float undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f32_x = insertelement <4 x float> undef, float undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f32_x = insertelement <8 x float> undef, float undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f32_x = insertelement <16 x float> undef, float undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 65 for instruction: %v32f32_x = insertelement <32 x float> undef, float undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f32_x = insertelement <vscale x 2 x float> undef, float undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f32_x = insertelement <vscale x 4 x float> undef, float undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f32_x = insertelement <vscale x 8 x float> undef, float undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32_x = insertelement <vscale x 16 x float> undef, float undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f32_x = insertelement <vscale x 32 x float> undef, float undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64_x = insertelement <2 x double> undef, double undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64_x = insertelement <4 x double> undef, double undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64_x = insertelement <8 x double> undef, double undef, i32 %x
-; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64_x = insertelement <16 x double> undef, double undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 10 for instruction: %v2f64_x = insertelement <2 x double> undef, double undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 18 for instruction: %v4f64_x = insertelement <4 x double> undef, double undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 34 for instruction: %v8f64_x = insertelement <8 x double> undef, double undef, i32 %x
+; RV32ZVE64X-NEXT:  Cost Model: Found an estimated cost of 66 for instruction: %v16f64_x = insertelement <16 x double> undef, double undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f64_x = insertelement <vscale x 2 x double> undef, double undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_x = insertelement <vscale x 4 x double> undef, double undef, i32 %x
 ; RV32ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_x = insertelement <vscale x 8 x double> undef, double undef, i32 %x
@@ -1295,32 +1295,32 @@ define void @insertelement_fp(i32 %x) {
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_1 = insertelement <vscale x 4 x double> undef, double undef, i32 1
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_1 = insertelement <vscale x 8 x double> undef, double undef, i32 1
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f64_1 = insertelement <vscale x 16 x double> undef, double undef, i32 1
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f16_x = insertelement <2 x half> undef, half undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f16_x = insertelement <4 x half> undef, half undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f16_x = insertelement <8 x half> undef, half undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f16_x = insertelement <16 x half> undef, half undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f16_x = insertelement <32 x half> undef, half undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v64f16_x = insertelement <64 x half> undef, half undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f16_x = insertelement <2 x half> undef, half undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f16_x = insertelement <4 x half> undef, half undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f16_x = insertelement <8 x half> undef, half undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f16_x = insertelement <16 x half> undef, half undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 65 for instruction: %v32f16_x = insertelement <32 x half> undef, half undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 129 for instruction: %v64f16_x = insertelement <64 x half> undef, half undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f16_x = insertelement <vscale x 2 x half> undef, half undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f16_x = insertelement <vscale x 4 x half> undef, half undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f16_x = insertelement <vscale x 8 x half> undef, half undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f16_x = insertelement <vscale x 16 x half> undef, half undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f16_x = insertelement <vscale x 32 x half> undef, half undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv64f16_x = insertelement <vscale x 64 x half> undef, half undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f32_x = insertelement <2 x float> undef, float undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f32_x = insertelement <4 x float> undef, float undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f32_x = insertelement <8 x float> undef, float undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f32_x = insertelement <16 x float> undef, float undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v32f32_x = insertelement <32 x float> undef, float undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f32_x = insertelement <2 x float> undef, float undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f32_x = insertelement <4 x float> undef, float undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f32_x = insertelement <8 x float> undef, float undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f32_x = insertelement <16 x float> undef, float undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 65 for instruction: %v32f32_x = insertelement <32 x float> undef, float undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f32_x = insertelement <vscale x 2 x float> undef, float undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f32_x = insertelement <vscale x 4 x float> undef, float undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f32_x = insertelement <vscale x 8 x float> undef, float undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv16f32_x = insertelement <vscale x 16 x float> undef, float undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv32f32_x = insertelement <vscale x 32 x float> undef, float undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v2f64_x = insertelement <2 x double> undef, double undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v4f64_x = insertelement <4 x double> undef, double undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v8f64_x = insertelement <8 x double> undef, double undef, i32 %x
-; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: %v16f64_x = insertelement <16 x double> undef, double undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 5 for instruction: %v2f64_x = insertelement <2 x double> undef, double undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 9 for instruction: %v4f64_x = insertelement <4 x double> undef, double undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 17 for instruction: %v8f64_x = insertelement <8 x double> undef, double undef, i32 %x
+; RV64ZVE64X-NEXT:  Cost Model: Found an estimated cost of 33 for instruction: %v16f64_x = insertelement <16 x double> undef, double undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv2f64_x = insertelement <vscale x 2 x double> undef, double undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv4f64_x = insertelement <vscale x 4 x double> undef, double undef, i32 %x
 ; RV64ZVE64X-NEXT:  Cost Model: Invalid cost for instruction: %nxv8f64_x = insertelement <vscale x 8 x double> undef, double undef, i32 %x



More information about the llvm-commits mailing list