[llvm] [AMDGPU] Cost of i8 vector insert/extract is free in some cases (PR #194991)
Brendon Cahoon via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 06:57:37 PDT 2026
https://github.com/bcahoon updated https://github.com/llvm/llvm-project/pull/194991
>From 21f5c884062cf045552d6af95838ca8559e1bbd5 Mon Sep 17 00:00:00 2001
From: Brendon Cahoon <brendon.cahoon at amd.com>
Date: Wed, 29 Apr 2026 18:32:51 -0500
Subject: [PATCH 1/5] [AMDGPU] Cost of i8 vector insert/extract is free in some
cases
Reduce the cost of i8 vector insert and extract elements to avoid
scalarization in VectorCombine.
---
.../AMDGPU/AMDGPUTargetTransformInfo.cpp | 19 +-
llvm/test/Analysis/CostModel/AMDGPU/div.ll | 84 ++--
.../CostModel/AMDGPU/extractelement.ll | 66 +--
.../CostModel/AMDGPU/insertelement.ll | 188 ++++----
llvm/test/Analysis/CostModel/AMDGPU/rem.ll | 84 ++--
.../test/CodeGen/AMDGPU/extract-i8-codegen.ll | 150 +++++++
.../AMDGPU/i8-extract-cost-comparison.ll | 422 ++++++++++++++++++
.../SLPVectorizer/AMDGPU/vectorize-i8.ll | 12 +-
.../extract-insert-chain-to-shuffles.ll | 11 +-
.../VectorCombine/AMDGPU/extract-insert-i8.ll | 46 +-
.../AMDGPU/no-scalarize-vector-extract.ll | 150 +++++++
11 files changed, 1013 insertions(+), 219 deletions(-)
create mode 100644 llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll
create mode 100644 llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll
create mode 100644 llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
index a087fd2590a6c..c11581cfabe71 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
@@ -1012,9 +1012,24 @@ InstructionCost GCNTTIImpl::getVectorInstrCost(
case Instruction::InsertElement: {
unsigned EltSize
= DL.getTypeSizeInBits(cast<VectorType>(ValTy)->getElementType());
+ // Dynamic indexing isn't free and is best avoided.
+ if (Index == ~0u)
+ return 2;
if (EltSize < 32) {
if (EltSize == 16 && Index == 0 && ST->has16BitInsts())
return 0;
+ // Some i8 inserts and extracts are free so we want to reduce the
+ // cost to avoid scalarization. We limit the zero cost cases to avoid
+ // adversely impacting all i8 vectorizing.
+ if (EltSize == 8) {
+ unsigned NumElts = cast<FixedVectorType>(ValTy)->getNumElements();
+ if (NumElts >= 4 && isPowerOf2_32(NumElts)) {
+ // Extracts at indices aligned to 32-bit boundaries (0, 4, 8, 12 for
+ // v16i8) are free as they access the low byte of each VGPR. Other
+ // indices require bit manipulation (shifts/byte selects) and cost 1.
+ return Index % 4 == 0 ? 0 : 1;
+ }
+ }
return BaseT::getVectorInstrCost(Opcode, ValTy, CostKind, Index, Op0, Op1,
VIC);
}
@@ -1022,9 +1037,7 @@ InstructionCost GCNTTIImpl::getVectorInstrCost(
// Extracts are just reads of a subregister, so are free. Inserts are
// considered free because we don't want to have any cost for scalarizing
// operations, and we don't have to copy into a different register class.
-
- // Dynamic indexing isn't free and is best avoided.
- return Index == ~0u ? 2 : 0;
+ return 0;
}
default:
return BaseT::getVectorInstrCost(Opcode, ValTy, CostKind, Index, Op0, Op1,
diff --git a/llvm/test/Analysis/CostModel/AMDGPU/div.ll b/llvm/test/Analysis/CostModel/AMDGPU/div.ll
index e3cc8386f23aa..bcb05e1f92503 100644
--- a/llvm/test/Analysis/CostModel/AMDGPU/div.ll
+++ b/llvm/test/Analysis/CostModel/AMDGPU/div.ll
@@ -44,9 +44,9 @@ define i32 @sdiv() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = sdiv <16 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = sdiv <32 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = sdiv i8 poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = sdiv <16 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = sdiv <32 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = sdiv <64 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = sdiv <16 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = sdiv <32 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = sdiv <64 x i8> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'sdiv'
@@ -125,9 +125,9 @@ define i32 @udiv() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = udiv <16 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = udiv <32 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = udiv i8 poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = udiv <16 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = udiv <32 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = udiv <64 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = udiv <16 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = udiv <32 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = udiv <64 x i8> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'udiv'
@@ -206,9 +206,9 @@ define i32 @sdiv_const() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = sdiv <16 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = sdiv <32 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19, i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = sdiv i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = sdiv <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = sdiv <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = sdiv <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = sdiv <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = sdiv <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = sdiv <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'sdiv_const'
@@ -287,9 +287,9 @@ define i32 @udiv_const() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = udiv <16 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = udiv <32 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19, i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = udiv i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = udiv <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = udiv <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = udiv <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = udiv <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = udiv <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = udiv <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'udiv_const'
@@ -368,9 +368,9 @@ define i32 @sdiv_uniformconst() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = sdiv <16 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = sdiv <32 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = sdiv i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = sdiv <16 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = sdiv <32 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = sdiv <64 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = sdiv <16 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = sdiv <32 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = sdiv <64 x i8> poison, splat (i8 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'sdiv_uniformconst'
@@ -449,9 +449,9 @@ define i32 @udiv_uniformconst() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = udiv <16 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = udiv <32 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = udiv i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = udiv <16 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = udiv <32 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = udiv <64 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = udiv <16 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = udiv <32 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = udiv <64 x i8> poison, splat (i8 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'udiv_uniformconst'
@@ -530,9 +530,9 @@ define i32 @sdiv_constpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = sdiv <16 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = sdiv <32 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = sdiv i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = sdiv <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = sdiv <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = sdiv <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = sdiv <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = sdiv <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = sdiv <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'sdiv_constpow2'
@@ -611,9 +611,9 @@ define i32 @udiv_constpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = udiv <16 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = udiv <32 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = udiv i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = udiv <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = udiv <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = udiv <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = udiv <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = udiv <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = udiv <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'udiv_constpow2'
@@ -692,9 +692,9 @@ define i32 @sdiv_uniformconstpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = sdiv <16 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = sdiv <32 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = sdiv i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = sdiv <16 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = sdiv <32 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = sdiv <64 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = sdiv <16 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = sdiv <32 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = sdiv <64 x i8> poison, splat (i8 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'sdiv_uniformconstpow2'
@@ -773,9 +773,9 @@ define i32 @udiv_uniformconstpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = udiv <16 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = udiv <32 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = udiv i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = udiv <16 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = udiv <32 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = udiv <64 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = udiv <16 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = udiv <32 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = udiv <64 x i8> poison, splat (i8 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'udiv_uniformconstpow2'
@@ -854,9 +854,9 @@ define i32 @sdiv_constnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = sdiv <16 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = sdiv <32 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = sdiv i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = sdiv <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = sdiv <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = sdiv <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = sdiv <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = sdiv <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = sdiv <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'sdiv_constnegpow2'
@@ -935,9 +935,9 @@ define i32 @udiv_constnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = udiv <16 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = udiv <32 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = udiv i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = udiv <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = udiv <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = udiv <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = udiv <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = udiv <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = udiv <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'udiv_constnegpow2'
@@ -1016,9 +1016,9 @@ define i32 @sdiv_uniformconstnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = sdiv <16 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = sdiv <32 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = sdiv i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = sdiv <16 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = sdiv <32 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = sdiv <64 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = sdiv <16 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = sdiv <32 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = sdiv <64 x i8> poison, splat (i8 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'sdiv_uniformconstnegpow2'
@@ -1097,9 +1097,9 @@ define i32 @udiv_uniformconstnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i16 = udiv <16 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i16 = udiv <32 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %I8 = udiv i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 32 for instruction: %V16i8 = udiv <16 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 64 for instruction: %V32i8 = udiv <32 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V64i8 = udiv <64 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 28 for instruction: %V16i8 = udiv <16 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 56 for instruction: %V32i8 = udiv <32 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 112 for instruction: %V64i8 = udiv <64 x i8> poison, splat (i8 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'udiv_uniformconstnegpow2'
diff --git a/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll b/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll
index 0085ae144f0cc..bba63cc6e9deb 100644
--- a/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll
+++ b/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll
@@ -171,9 +171,9 @@ define amdgpu_kernel void @extractelement_8(i32 %arg) {
; GCN-LABEL: 'extractelement_8'
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_0 = extractelement <2 x i8> poison, i32 0
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_0 = extractelement <3 x i8> poison, i32 0
-; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_0 = extractelement <4 x i8> poison, i32 0
+; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i8_0 = extractelement <4 x i8> poison, i32 0
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_0 = extractelement <5 x i8> poison, i32 0
-; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_0 = extractelement <8 x i8> poison, i32 0
+; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v8i8_0 = extractelement <8 x i8> poison, i32 0
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_1 = extractelement <2 x i8> poison, i32 1
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_1 = extractelement <3 x i8> poison, i32 1
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_1 = extractelement <4 x i8> poison, i32 1
@@ -186,17 +186,22 @@ define amdgpu_kernel void @extractelement_8(i32 %arg) {
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_3 = extractelement <4 x i8> poison, i32 3
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_3 = extractelement <5 x i8> poison, i32 3
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_3 = extractelement <8 x i8> poison, i32 3
-; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_a = extractelement <2 x i8> poison, i32 %arg
-; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_a = extractelement <4 x i8> poison, i32 %arg
-; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_a = extractelement <8 x i8> poison, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = extractelement <2 x i8> undef, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = extractelement <4 x i8> undef, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = extractelement <8 x i8> undef, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = extractelement <16 x i8> undef, i32 0
+; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_1 = extractelement <16 x i8> undef, i32 1
+; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = extractelement <16 x i8> undef, i32 8
+; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = extractelement <16 x i8> undef, i32 15
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = extractelement <16 x i8> undef, i32 %arg
; GCN-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; GCN-SIZE-LABEL: 'extractelement_8'
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_0 = extractelement <2 x i8> poison, i32 0
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_0 = extractelement <3 x i8> poison, i32 0
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_0 = extractelement <4 x i8> poison, i32 0
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i8_0 = extractelement <4 x i8> poison, i32 0
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_0 = extractelement <5 x i8> poison, i32 0
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_0 = extractelement <8 x i8> poison, i32 0
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v8i8_0 = extractelement <8 x i8> poison, i32 0
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_1 = extractelement <2 x i8> poison, i32 1
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_1 = extractelement <3 x i8> poison, i32 1
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_1 = extractelement <4 x i8> poison, i32 1
@@ -209,9 +214,14 @@ define amdgpu_kernel void @extractelement_8(i32 %arg) {
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_3 = extractelement <4 x i8> poison, i32 3
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_3 = extractelement <5 x i8> poison, i32 3
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_3 = extractelement <8 x i8> poison, i32 3
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_a = extractelement <2 x i8> poison, i32 %arg
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_a = extractelement <4 x i8> poison, i32 %arg
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_a = extractelement <8 x i8> poison, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = extractelement <2 x i8> undef, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = extractelement <4 x i8> undef, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = extractelement <8 x i8> undef, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = extractelement <16 x i8> undef, i32 0
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_1 = extractelement <16 x i8> undef, i32 1
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = extractelement <16 x i8> undef, i32 8
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = extractelement <16 x i8> undef, i32 15
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = extractelement <16 x i8> undef, i32 %arg
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
%v2i8_0 = extractelement <2 x i8> poison, i32 0
@@ -235,9 +245,15 @@ define amdgpu_kernel void @extractelement_8(i32 %arg) {
%v5i8_3 = extractelement <5 x i8> poison, i32 3
%v8i8_3 = extractelement <8 x i8> poison, i32 3
- %v2i8_a = extractelement <2 x i8> poison, i32 %arg
- %v4i8_a = extractelement <4 x i8> poison, i32 %arg
- %v8i8_a = extractelement <8 x i8> poison, i32 %arg
+ %v2i8_a = extractelement <2 x i8> undef, i32 %arg
+ %v4i8_a = extractelement <4 x i8> undef, i32 %arg
+ %v8i8_a = extractelement <8 x i8> undef, i32 %arg
+
+ %v16i8_0 = extractelement <16 x i8> undef, i32 0
+ %v16i8_1 = extractelement <16 x i8> undef, i32 1
+ %v16i8_8 = extractelement <16 x i8> undef, i32 8
+ %v16i8_15 = extractelement <16 x i8> undef, i32 15
+ %v16i8_a = extractelement <16 x i8> undef, i32 %arg
ret void
}
@@ -262,9 +278,9 @@ define amdgpu_kernel void @extractelement_16(i32 %arg) {
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = extractelement <4 x i16> poison, i32 3
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_3 = extractelement <5 x i16> poison, i32 3
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_3 = extractelement <8 x i16> poison, i32 3
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
; CI-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; GFX89-LABEL: 'extractelement_16'
@@ -287,9 +303,9 @@ define amdgpu_kernel void @extractelement_16(i32 %arg) {
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = extractelement <4 x i16> poison, i32 3
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_3 = extractelement <5 x i16> poison, i32 3
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_3 = extractelement <8 x i16> poison, i32 3
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
; GFX89-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; CI-SIZE-LABEL: 'extractelement_16'
@@ -312,9 +328,9 @@ define amdgpu_kernel void @extractelement_16(i32 %arg) {
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = extractelement <4 x i16> poison, i32 3
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_3 = extractelement <5 x i16> poison, i32 3
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_3 = extractelement <8 x i16> poison, i32 3
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
; GFX89-SIZE-LABEL: 'extractelement_16'
@@ -337,9 +353,9 @@ define amdgpu_kernel void @extractelement_16(i32 %arg) {
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = extractelement <4 x i16> poison, i32 3
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_3 = extractelement <5 x i16> poison, i32 3
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_3 = extractelement <8 x i16> poison, i32 3
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = extractelement <2 x i16> poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = extractelement <4 x i16> poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = extractelement <8 x i16> poison, i32 %arg
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
%v2i16_0 = extractelement <2 x i16> poison, i32 0
diff --git a/llvm/test/Analysis/CostModel/AMDGPU/insertelement.ll b/llvm/test/Analysis/CostModel/AMDGPU/insertelement.ll
index 41eb654a022d3..c8c1fe0cdf35a 100644
--- a/llvm/test/Analysis/CostModel/AMDGPU/insertelement.ll
+++ b/llvm/test/Analysis/CostModel/AMDGPU/insertelement.ll
@@ -11,31 +11,31 @@ define amdgpu_kernel void @insertelement_i8(i32 %arg) {
; ALL-LABEL: 'insertelement_i8'
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_0 = insertelement <2 x i8> poison, i8 42, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_0 = insertelement <3 x i8> poison, i8 42, i32 0
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 42, i32 0
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 42, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_0 = insertelement <5 x i8> poison, i8 42, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_1 = insertelement <2 x i8> poison, i8 42, i32 1
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_1 = insertelement <3 x i8> poison, i8 42, i32 1
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_1 = insertelement <4 x i8> poison, i8 42, i32 1
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_1 = insertelement <5 x i8> poison, i8 42, i32 1
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 42, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_a = insertelement <3 x i8> poison, i8 42, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 42, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_a = insertelement <5 x i8> poison, i8 42, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 42, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v3i8_a = insertelement <3 x i8> poison, i8 42, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 42, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v5i8_a = insertelement <5 x i8> poison, i8 42, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; ALL-SIZE-LABEL: 'insertelement_i8'
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_0 = insertelement <2 x i8> poison, i8 42, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_0 = insertelement <3 x i8> poison, i8 42, i32 0
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 42, i32 0
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 42, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_0 = insertelement <5 x i8> poison, i8 42, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_1 = insertelement <2 x i8> poison, i8 42, i32 1
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_1 = insertelement <3 x i8> poison, i8 42, i32 1
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_1 = insertelement <4 x i8> poison, i8 42, i32 1
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_1 = insertelement <5 x i8> poison, i8 42, i32 1
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 42, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i8_a = insertelement <3 x i8> poison, i8 42, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 42, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_a = insertelement <5 x i8> poison, i8 42, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 42, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v3i8_a = insertelement <3 x i8> poison, i8 42, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 42, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v5i8_a = insertelement <5 x i8> poison, i8 42, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
%v2i8_0 = insertelement <2 x i8> poison, i8 42, i32 0
@@ -63,10 +63,10 @@ define amdgpu_kernel void @insertelement_i16(i32 %arg) {
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_1 = insertelement <3 x i16> poison, i16 42, i32 1
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_1 = insertelement <4 x i16> poison, i16 42, i32 1
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_1 = insertelement <5 x i16> poison, i16 42, i32 1
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
; CI-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; GFX89-LABEL: 'insertelement_i16'
@@ -78,10 +78,10 @@ define amdgpu_kernel void @insertelement_i16(i32 %arg) {
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_1 = insertelement <3 x i16> poison, i16 42, i32 1
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_1 = insertelement <4 x i16> poison, i16 42, i32 1
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_1 = insertelement <5 x i16> poison, i16 42, i32 1
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
; GFX89-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; CI-SIZE-LABEL: 'insertelement_i16'
@@ -93,10 +93,10 @@ define amdgpu_kernel void @insertelement_i16(i32 %arg) {
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_1 = insertelement <3 x i16> poison, i16 42, i32 1
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_1 = insertelement <4 x i16> poison, i16 42, i32 1
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_1 = insertelement <5 x i16> poison, i16 42, i32 1
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
; GFX89-SIZE-LABEL: 'insertelement_i16'
@@ -108,10 +108,10 @@ define amdgpu_kernel void @insertelement_i16(i32 %arg) {
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_1 = insertelement <3 x i16> poison, i16 42, i32 1
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_1 = insertelement <4 x i16> poison, i16 42, i32 1
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_1 = insertelement <5 x i16> poison, i16 42, i32 1
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 42, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v3i16_a = insertelement <3 x i16> poison, i16 42, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 42, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v5i16_a = insertelement <5 x i16> poison, i16 42, i32 %arg
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
%v2i16_0 = insertelement <2 x i16> poison, i16 42, i32 0
@@ -439,21 +439,21 @@ define i32 @insert_i32_poison(i32 %arg) {
define i32 @insert_i16_poison(i32 %arg) {
; CI-LABEL: 'insert_i16_poison'
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_0 = insertelement <2 x i16> poison, i16 poison, i32 0
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_1 = insertelement <2 x i16> poison, i16 poison, i32 1
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_0 = insertelement <4 x i16> poison, i16 poison, i32 0
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = insertelement <4 x i16> poison, i16 poison, i32 3
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_0 = insertelement <8 x i16> poison, i16 poison, i32 0
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_7 = insertelement <8 x i16> poison, i16 poison, i32 7
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_0 = insertelement <16 x i16> poison, i16 poison, i32 0
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_7 = insertelement <16 x i16> poison, i16 poison, i32 7
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_8 = insertelement <16 x i16> poison, i16 poison, i32 8
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_15 = insertelement <16 x i16> poison, i16 poison, i32 15
-; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
+; CI-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_0 = insertelement <32 x i16> poison, i16 poison, i32 0
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_7 = insertelement <32 x i16> poison, i16 poison, i32 7
; CI-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_8 = insertelement <32 x i16> poison, i16 poison, i32 8
@@ -464,21 +464,21 @@ define i32 @insert_i16_poison(i32 %arg) {
; CI-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; GFX89-LABEL: 'insert_i16_poison'
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
; GFX89-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v2i16_0 = insertelement <2 x i16> poison, i16 poison, i32 0
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_1 = insertelement <2 x i16> poison, i16 poison, i32 1
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
; GFX89-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i16_0 = insertelement <4 x i16> poison, i16 poison, i32 0
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = insertelement <4 x i16> poison, i16 poison, i32 3
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
; GFX89-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v8i16_0 = insertelement <8 x i16> poison, i16 poison, i32 0
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_7 = insertelement <8 x i16> poison, i16 poison, i32 7
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
; GFX89-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i16_0 = insertelement <16 x i16> poison, i16 poison, i32 0
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_7 = insertelement <16 x i16> poison, i16 poison, i32 7
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_8 = insertelement <16 x i16> poison, i16 poison, i32 8
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_15 = insertelement <16 x i16> poison, i16 poison, i32 15
-; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
+; GFX89-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
; GFX89-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i16_0 = insertelement <32 x i16> poison, i16 poison, i32 0
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_7 = insertelement <32 x i16> poison, i16 poison, i32 7
; GFX89-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_8 = insertelement <32 x i16> poison, i16 poison, i32 8
@@ -489,21 +489,21 @@ define i32 @insert_i16_poison(i32 %arg) {
; GFX89-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; CI-SIZE-LABEL: 'insert_i16_poison'
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_0 = insertelement <2 x i16> poison, i16 poison, i32 0
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_1 = insertelement <2 x i16> poison, i16 poison, i32 1
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_0 = insertelement <4 x i16> poison, i16 poison, i32 0
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = insertelement <4 x i16> poison, i16 poison, i32 3
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_0 = insertelement <8 x i16> poison, i16 poison, i32 0
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_7 = insertelement <8 x i16> poison, i16 poison, i32 7
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_0 = insertelement <16 x i16> poison, i16 poison, i32 0
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_7 = insertelement <16 x i16> poison, i16 poison, i32 7
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_8 = insertelement <16 x i16> poison, i16 poison, i32 8
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_15 = insertelement <16 x i16> poison, i16 poison, i32 15
-; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
+; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_0 = insertelement <32 x i16> poison, i16 poison, i32 0
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_7 = insertelement <32 x i16> poison, i16 poison, i32 7
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_8 = insertelement <32 x i16> poison, i16 poison, i32 8
@@ -514,21 +514,21 @@ define i32 @insert_i16_poison(i32 %arg) {
; CI-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 poison
;
; GFX89-SIZE-LABEL: 'insert_i16_poison'
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i16_a = insertelement <2 x i16> poison, i16 poison, i32 %arg
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v2i16_0 = insertelement <2 x i16> poison, i16 poison, i32 0
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i16_1 = insertelement <2 x i16> poison, i16 poison, i32 1
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i16_a = insertelement <4 x i16> poison, i16 poison, i32 %arg
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i16_0 = insertelement <4 x i16> poison, i16 poison, i32 0
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i16_3 = insertelement <4 x i16> poison, i16 poison, i32 3
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i16_a = insertelement <8 x i16> poison, i16 poison, i32 %arg
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v8i16_0 = insertelement <8 x i16> poison, i16 poison, i32 0
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i16_7 = insertelement <8 x i16> poison, i16 poison, i32 7
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i16_a = insertelement <16 x i16> poison, i16 poison, i32 %arg
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i16_0 = insertelement <16 x i16> poison, i16 poison, i32 0
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_7 = insertelement <16 x i16> poison, i16 poison, i32 7
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_8 = insertelement <16 x i16> poison, i16 poison, i32 8
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i16_15 = insertelement <16 x i16> poison, i16 poison, i32 15
-; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
+; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i16_a = insertelement <32 x i16> poison, i16 poison, i32 %arg
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i16_0 = insertelement <32 x i16> poison, i16 poison, i32 0
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_7 = insertelement <32 x i16> poison, i16 poison, i32 7
; GFX89-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i16_8 = insertelement <32 x i16> poison, i16 poison, i32 8
@@ -570,68 +570,68 @@ define i32 @insert_i16_poison(i32 %arg) {
define i32 @insert_i8_poison(i32 %arg) {
; ALL-LABEL: 'insert_i8_poison'
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 poison, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_0 = insertelement <2 x i8> poison, i8 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_3 = insertelement <2 x i8> poison, i8 poison, i32 1
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 poison, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 poison, i32 0
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_3 = insertelement <4 x i8> poison, i8 poison, i32 3
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_a = insertelement <8 x i8> poison, i8 poison, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_0 = insertelement <8 x i8> poison, i8 poison, i32 0
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = insertelement <8 x i8> poison, i8 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v8i8_0 = insertelement <8 x i8> poison, i8 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_7 = insertelement <8 x i8> poison, i8 poison, i32 7
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_a = insertelement <16 x i8> poison, i8 poison, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_0 = insertelement <16 x i8> poison, i8 poison, i32 0
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_8 = insertelement <16 x i8> poison, i8 poison, i32 8
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = insertelement <16 x i8> poison, i8 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = insertelement <16 x i8> poison, i8 poison, i32 0
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = insertelement <16 x i8> poison, i8 poison, i32 8
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = insertelement <16 x i8> poison, i8 poison, i32 15
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_a = insertelement <32 x i8> poison, i8 poison, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_0 = insertelement <32 x i8> poison, i8 poison, i32 0
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i8_a = insertelement <32 x i8> poison, i8 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i8_0 = insertelement <32 x i8> poison, i8 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_7 = insertelement <32 x i8> poison, i8 poison, i32 7
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_8 = insertelement <32 x i8> poison, i8 poison, i32 8
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i8_8 = insertelement <32 x i8> poison, i8 poison, i32 8
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_15 = insertelement <32 x i8> poison, i8 poison, i32 15
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_24 = insertelement <32 x i8> poison, i8 poison, i32 24
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i8_24 = insertelement <32 x i8> poison, i8 poison, i32 24
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_31 = insertelement <32 x i8> poison, i8 poison, i32 31
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_a = insertelement <64 x i8> poison, i8 poison, i32 %arg
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_0 = insertelement <64 x i8> poison, i8 poison, i32 0
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v64i8_a = insertelement <64 x i8> poison, i8 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_0 = insertelement <64 x i8> poison, i8 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_7 = insertelement <64 x i8> poison, i8 poison, i32 7
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_8 = insertelement <64 x i8> poison, i8 poison, i32 8
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_8 = insertelement <64 x i8> poison, i8 poison, i32 8
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_15 = insertelement <64 x i8> poison, i8 poison, i32 15
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_24 = insertelement <64 x i8> poison, i8 poison, i32 24
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_24 = insertelement <64 x i8> poison, i8 poison, i32 24
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_31 = insertelement <64 x i8> poison, i8 poison, i32 31
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_32 = insertelement <64 x i8> poison, i8 poison, i32 32
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_48 = insertelement <64 x i8> poison, i8 poison, i32 48
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_32 = insertelement <64 x i8> poison, i8 poison, i32 32
+; ALL-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_48 = insertelement <64 x i8> poison, i8 poison, i32 48
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_63 = insertelement <64 x i8> poison, i8 poison, i32 63
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'insert_i8_poison'
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = insertelement <2 x i8> poison, i8 poison, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_0 = insertelement <2 x i8> poison, i8 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i8_3 = insertelement <2 x i8> poison, i8 poison, i32 1
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 poison, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 poison, i32 0
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = insertelement <4 x i8> poison, i8 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v4i8_0 = insertelement <4 x i8> poison, i8 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_3 = insertelement <4 x i8> poison, i8 poison, i32 3
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_a = insertelement <8 x i8> poison, i8 poison, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_0 = insertelement <8 x i8> poison, i8 poison, i32 0
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = insertelement <8 x i8> poison, i8 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v8i8_0 = insertelement <8 x i8> poison, i8 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_7 = insertelement <8 x i8> poison, i8 poison, i32 7
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_a = insertelement <16 x i8> poison, i8 poison, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_0 = insertelement <16 x i8> poison, i8 poison, i32 0
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_8 = insertelement <16 x i8> poison, i8 poison, i32 8
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = insertelement <16 x i8> poison, i8 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = insertelement <16 x i8> poison, i8 poison, i32 0
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = insertelement <16 x i8> poison, i8 poison, i32 8
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = insertelement <16 x i8> poison, i8 poison, i32 15
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_a = insertelement <32 x i8> poison, i8 poison, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_0 = insertelement <32 x i8> poison, i8 poison, i32 0
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i8_a = insertelement <32 x i8> poison, i8 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i8_0 = insertelement <32 x i8> poison, i8 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_7 = insertelement <32 x i8> poison, i8 poison, i32 7
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_8 = insertelement <32 x i8> poison, i8 poison, i32 8
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i8_8 = insertelement <32 x i8> poison, i8 poison, i32 8
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_15 = insertelement <32 x i8> poison, i8 poison, i32 15
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_24 = insertelement <32 x i8> poison, i8 poison, i32 24
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v32i8_24 = insertelement <32 x i8> poison, i8 poison, i32 24
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i8_31 = insertelement <32 x i8> poison, i8 poison, i32 31
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_a = insertelement <64 x i8> poison, i8 poison, i32 %arg
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_0 = insertelement <64 x i8> poison, i8 poison, i32 0
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v64i8_a = insertelement <64 x i8> poison, i8 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_0 = insertelement <64 x i8> poison, i8 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_7 = insertelement <64 x i8> poison, i8 poison, i32 7
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_8 = insertelement <64 x i8> poison, i8 poison, i32 8
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_8 = insertelement <64 x i8> poison, i8 poison, i32 8
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_15 = insertelement <64 x i8> poison, i8 poison, i32 15
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_24 = insertelement <64 x i8> poison, i8 poison, i32 24
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_24 = insertelement <64 x i8> poison, i8 poison, i32 24
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_31 = insertelement <64 x i8> poison, i8 poison, i32 31
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_32 = insertelement <64 x i8> poison, i8 poison, i32 32
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_48 = insertelement <64 x i8> poison, i8 poison, i32 48
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_32 = insertelement <64 x i8> poison, i8 poison, i32 32
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v64i8_48 = insertelement <64 x i8> poison, i8 poison, i32 48
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i8_63 = insertelement <64 x i8> poison, i8 poison, i32 63
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i32 poison
;
@@ -676,27 +676,27 @@ define i32 @insert_i8_poison(i32 %arg) {
define i32 @insert_i1_poison(i32 %arg) {
; ALL-LABEL: 'insert_i1_poison'
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i1_a = insertelement <2 x i1> poison, i1 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i1_a = insertelement <2 x i1> poison, i1 poison, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i1_0 = insertelement <2 x i1> poison, i1 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i1_1 = insertelement <2 x i1> poison, i1 poison, i32 1
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i1_a = insertelement <4 x i1> poison, i1 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i1_a = insertelement <4 x i1> poison, i1 poison, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i1_0 = insertelement <4 x i1> poison, i1 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i1_2 = insertelement <4 x i1> poison, i1 poison, i32 2
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i1_a = insertelement <8 x i1> poison, i1 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i1_a = insertelement <8 x i1> poison, i1 poison, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i1_0 = insertelement <8 x i1> poison, i1 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i1_4 = insertelement <8 x i1> poison, i1 poison, i32 4
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_a = insertelement <16 x i1> poison, i1 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i1_a = insertelement <16 x i1> poison, i1 poison, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_0 = insertelement <16 x i1> poison, i1 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_8 = insertelement <16 x i1> poison, i1 poison, i32 8
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_15 = insertelement <16 x i1> poison, i1 poison, i32 15
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_a = insertelement <32 x i1> poison, i1 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i1_a = insertelement <32 x i1> poison, i1 poison, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_0 = insertelement <32 x i1> poison, i1 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_7 = insertelement <32 x i1> poison, i1 poison, i32 7
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_8 = insertelement <32 x i1> poison, i1 poison, i32 8
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_15 = insertelement <32 x i1> poison, i1 poison, i32 15
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_24 = insertelement <32 x i1> poison, i1 poison, i32 24
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_31 = insertelement <32 x i1> poison, i1 poison, i32 31
-; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_a = insertelement <64 x i1> poison, i1 poison, i32 %arg
+; ALL-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v64i1_a = insertelement <64 x i1> poison, i1 poison, i32 %arg
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_0 = insertelement <64 x i1> poison, i1 poison, i32 0
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_7 = insertelement <64 x i1> poison, i1 poison, i32 7
; ALL-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_8 = insertelement <64 x i1> poison, i1 poison, i32 8
@@ -709,27 +709,27 @@ define i32 @insert_i1_poison(i32 %arg) {
; ALL-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'insert_i1_poison'
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i1_a = insertelement <2 x i1> poison, i1 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i1_a = insertelement <2 x i1> poison, i1 poison, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i1_0 = insertelement <2 x i1> poison, i1 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v2i1_1 = insertelement <2 x i1> poison, i1 poison, i32 1
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i1_a = insertelement <4 x i1> poison, i1 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i1_a = insertelement <4 x i1> poison, i1 poison, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i1_0 = insertelement <4 x i1> poison, i1 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i1_2 = insertelement <4 x i1> poison, i1 poison, i32 2
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i1_a = insertelement <8 x i1> poison, i1 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i1_a = insertelement <8 x i1> poison, i1 poison, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i1_0 = insertelement <8 x i1> poison, i1 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i1_4 = insertelement <8 x i1> poison, i1 poison, i32 4
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_a = insertelement <16 x i1> poison, i1 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i1_a = insertelement <16 x i1> poison, i1 poison, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_0 = insertelement <16 x i1> poison, i1 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_8 = insertelement <16 x i1> poison, i1 poison, i32 8
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i1_15 = insertelement <16 x i1> poison, i1 poison, i32 15
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_a = insertelement <32 x i1> poison, i1 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v32i1_a = insertelement <32 x i1> poison, i1 poison, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_0 = insertelement <32 x i1> poison, i1 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_7 = insertelement <32 x i1> poison, i1 poison, i32 7
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_8 = insertelement <32 x i1> poison, i1 poison, i32 8
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_15 = insertelement <32 x i1> poison, i1 poison, i32 15
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_24 = insertelement <32 x i1> poison, i1 poison, i32 24
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v32i1_31 = insertelement <32 x i1> poison, i1 poison, i32 31
-; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_a = insertelement <64 x i1> poison, i1 poison, i32 %arg
+; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v64i1_a = insertelement <64 x i1> poison, i1 poison, i32 %arg
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_0 = insertelement <64 x i1> poison, i1 poison, i32 0
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_7 = insertelement <64 x i1> poison, i1 poison, i32 7
; ALL-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v64i1_8 = insertelement <64 x i1> poison, i1 poison, i32 8
diff --git a/llvm/test/Analysis/CostModel/AMDGPU/rem.ll b/llvm/test/Analysis/CostModel/AMDGPU/rem.ll
index 006b008afdc8d..d3e7e78128044 100644
--- a/llvm/test/Analysis/CostModel/AMDGPU/rem.ll
+++ b/llvm/test/Analysis/CostModel/AMDGPU/rem.ll
@@ -44,9 +44,9 @@ define i32 @srem() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = srem <16 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = srem <32 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = srem i8 poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = srem <16 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = srem <32 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = srem <64 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = srem <16 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = srem <32 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = srem <64 x i8> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'srem'
@@ -125,9 +125,9 @@ define i32 @urem() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = urem <16 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = urem <32 x i16> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = urem i8 poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = urem <16 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = urem <32 x i8> poison, poison
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = urem <64 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = urem <16 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = urem <32 x i8> poison, poison
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = urem <64 x i8> poison, poison
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'urem'
@@ -206,9 +206,9 @@ define i32 @srem_const() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = srem <16 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = srem <32 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19, i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = srem i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = srem <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = srem <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = srem <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = srem <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = srem <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = srem <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'srem_const'
@@ -287,9 +287,9 @@ define i32 @urem_const() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = urem <16 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = urem <32 x i16> poison, <i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19, i16 4, i16 5, i16 6, i16 7, i16 8, i16 9, i16 10, i16 11, i16 12, i16 13, i16 14, i16 15, i16 16, i16 17, i16 18, i16 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = urem i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = urem <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = urem <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = urem <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = urem <16 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = urem <32 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = urem <64 x i8> poison, <i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16, i8 17, i8 18, i8 19>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'urem_const'
@@ -368,9 +368,9 @@ define i32 @srem_uniformconst() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = srem <16 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = srem <32 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = srem i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = srem <16 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = srem <32 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = srem <64 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = srem <16 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = srem <32 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = srem <64 x i8> poison, splat (i8 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'srem_uniformconst'
@@ -449,9 +449,9 @@ define i32 @urem_uniformconst() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = urem <16 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = urem <32 x i16> poison, splat (i16 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = urem i8 poison, 7
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = urem <16 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = urem <32 x i8> poison, splat (i8 7)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = urem <64 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = urem <16 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = urem <32 x i8> poison, splat (i8 7)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = urem <64 x i8> poison, splat (i8 7)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'urem_uniformconst'
@@ -530,9 +530,9 @@ define i32 @srem_constpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = srem <16 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = srem <32 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = srem i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = srem <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = srem <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = srem <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = srem <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = srem <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = srem <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'srem_constpow2'
@@ -611,9 +611,9 @@ define i32 @urem_constpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = urem <16 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = urem <32 x i16> poison, <i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256, i16 2, i16 4, i16 8, i16 16, i16 32, i16 64, i16 128, i16 256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = urem i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = urem <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = urem <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = urem <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = urem <16 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = urem <32 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = urem <64 x i8> poison, <i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16, i8 2, i8 4, i8 8, i8 16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'urem_constpow2'
@@ -692,9 +692,9 @@ define i32 @srem_uniformconstpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = srem <16 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = srem <32 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = srem i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = srem <16 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = srem <32 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = srem <64 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = srem <16 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = srem <32 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = srem <64 x i8> poison, splat (i8 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'srem_uniformconstpow2'
@@ -773,9 +773,9 @@ define i32 @urem_uniformconstpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = urem <16 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = urem <32 x i16> poison, splat (i16 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = urem i8 poison, 16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = urem <16 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = urem <32 x i8> poison, splat (i8 16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = urem <64 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = urem <16 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = urem <32 x i8> poison, splat (i8 16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = urem <64 x i8> poison, splat (i8 16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'urem_uniformconstpow2'
@@ -854,9 +854,9 @@ define i32 @srem_constnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = srem <16 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = srem <32 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = srem i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = srem <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = srem <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = srem <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = srem <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = srem <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = srem <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'srem_constnegpow2'
@@ -935,9 +935,9 @@ define i32 @urem_constnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = urem <16 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = urem <32 x i16> poison, <i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256, i16 -2, i16 -4, i16 -8, i16 -16, i16 -32, i16 -64, i16 -128, i16 -256>
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = urem i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = urem <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = urem <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = urem <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = urem <16 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = urem <32 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = urem <64 x i8> poison, <i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16, i8 -2, i8 -4, i8 -8, i8 -16>
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'urem_constnegpow2'
@@ -1016,9 +1016,9 @@ define i32 @srem_uniformconstnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = srem <16 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = srem <32 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = srem i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = srem <16 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = srem <32 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = srem <64 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = srem <16 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = srem <32 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = srem <64 x i8> poison, splat (i8 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'srem_uniformconstnegpow2'
@@ -1097,9 +1097,9 @@ define i32 @urem_uniformconstnegpow2() {
; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i16 = urem <16 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 266 for instruction: %V32i16 = urem <32 x i16> poison, splat (i16 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 6 for instruction: %I8 = urem i8 poison, -16
-; SLOW-NEXT: Cost Model: Found an estimated cost of 128 for instruction: %V16i8 = urem <16 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 256 for instruction: %V32i8 = urem <32 x i8> poison, splat (i8 -16)
-; SLOW-NEXT: Cost Model: Found an estimated cost of 522 for instruction: %V64i8 = urem <64 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 120 for instruction: %V16i8 = urem <16 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 240 for instruction: %V32i8 = urem <32 x i8> poison, splat (i8 -16)
+; SLOW-NEXT: Cost Model: Found an estimated cost of 490 for instruction: %V64i8 = urem <64 x i8> poison, splat (i8 -16)
; SLOW-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret i32 poison
;
; ALL-SIZE-LABEL: 'urem_uniformconstnegpow2'
diff --git a/llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll b/llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll
new file mode 100644
index 0000000000000..2ec357ebded53
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll
@@ -0,0 +1,150 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck -check-prefix=GFX9 %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 < %s | FileCheck -check-prefix=GFX12 %s
+
+; Test that extractelement and shufflevector operations on v16i8 loads get
+; optimized away by DAGCombiner, showing that these operations are "free"
+; in terms of generated instructions.
+
+ at lds = external addrspace(3) global [0 x i8], align 16
+
+; Multiple extract elements keep the full ds_read_b128.
+define void @extract_multiple_v16i8(ptr addrspace(1) %out) {
+; GFX9-LABEL: extract_multiple_v16i8:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v2, 0
+; GFX9-NEXT: ds_read_b128 v[2:5], v2
+; GFX9-NEXT: s_mov_b32 s0, 0xc0c0004
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_perm_b32 v2, v2, v3, s0
+; GFX9-NEXT: v_perm_b32 v3, v4, v5, s0
+; GFX9-NEXT: v_lshlrev_b32_e32 v3, 16, v3
+; GFX9-NEXT: v_or_b32_e32 v2, v2, v3
+; GFX9-NEXT: global_store_dword v[0:1], v2, off
+; GFX9-NEXT: s_waitcnt vmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: extract_multiple_v16i8:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v2, 0
+; GFX12-NEXT: ds_load_b128 v[2:5], v2
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_perm_b32 v4, v4, v5, 0xc0c0004
+; GFX12-NEXT: v_perm_b32 v2, v2, v3, 0xc0c0004
+; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
+; GFX12-NEXT: v_lshlrev_b32_e32 v3, 16, v4
+; GFX12-NEXT: v_or_b32_e32 v2, v2, v3
+; GFX12-NEXT: global_store_b32 v[0:1], v2, off
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e0 = extractelement <16 x i8> %val, i32 0
+ %e4 = extractelement <16 x i8> %val, i32 4
+ %e8 = extractelement <16 x i8> %val, i32 8
+ %e12 = extractelement <16 x i8> %val, i32 12
+ %out0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
+ store i8 %e0, ptr addrspace(1) %out0, align 1
+ %out1 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 1
+ store i8 %e4, ptr addrspace(1) %out1, align 1
+ %out2 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 2
+ store i8 %e8, ptr addrspace(1) %out2, align 1
+ %out3 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 3
+ store i8 %e12, ptr addrspace(1) %out3, align 1
+ ret void
+}
+
+; Multiple extract elements to keep the full ds_read_b64.
+define void @extract_multiple_v8i8(ptr addrspace(1) %out) {
+; GFX9-LABEL: extract_multiple_v8i8:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v2, 0
+; GFX9-NEXT: ds_read_b64 v[2:3], v2
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_readfirstlane_b32 s0, v3
+; GFX9-NEXT: s_and_b32 s1, s0, 0xff
+; GFX9-NEXT: s_lshr_b32 s0, s0, 24
+; GFX9-NEXT: s_lshl_b32 s0, s0, 8
+; GFX9-NEXT: s_or_b32 s0, s1, s0
+; GFX9-NEXT: s_lshl_b32 s0, s0, 16
+; GFX9-NEXT: v_or_b32_sdwa v2, v2, s0 dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_0 src1_sel:DWORD
+; GFX9-NEXT: global_store_dword v[0:1], v2, off
+; GFX9-NEXT: s_waitcnt vmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: extract_multiple_v8i8:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v2, 0
+; GFX12-NEXT: ds_load_b64 v[2:3], v2
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_readfirstlane_b32 s0, v3
+; GFX12-NEXT: v_and_b32_e32 v2, 0xffff, v2
+; GFX12-NEXT: s_lshr_b32 s1, s0, 16
+; GFX12-NEXT: s_and_b32 s0, s0, 0xff
+; GFX12-NEXT: s_and_b32 s1, s1, 0xff00
+; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
+; GFX12-NEXT: s_or_b32 s0, s0, s1
+; GFX12-NEXT: s_lshl_b32 s0, s0, 16
+; GFX12-NEXT: s_delay_alu instid0(SALU_CYCLE_1)
+; GFX12-NEXT: v_or_b32_e32 v2, s0, v2
+; GFX12-NEXT: global_store_b32 v[0:1], v2, off
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <8 x i8>, ptr addrspace(3) %ptr, align 16
+ %e0 = extractelement <8 x i8> %val, i32 0
+ %e4 = extractelement <8 x i8> %val, i32 1
+ %e8 = extractelement <8 x i8> %val, i32 4
+ %e12 = extractelement <8 x i8> %val, i32 7
+ %out0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
+ store i8 %e0, ptr addrspace(1) %out0, align 1
+ %out1 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 1
+ store i8 %e4, ptr addrspace(1) %out1, align 1
+ %out2 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 2
+ store i8 %e8, ptr addrspace(1) %out2, align 1
+ %out3 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 3
+ store i8 %e12, ptr addrspace(1) %out3, align 1
+ ret void
+}
+
+; Multiple extract elements keep the 32-bit load.
+define void @extract_multiple_v4i8(ptr addrspace(1) %out) {
+; GFX9-LABEL: extract_multiple_v4i8:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v2, 0
+; GFX9-NEXT: ds_read_b32 v2, v2
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: global_store_byte_d16_hi v[0:1], v2, off offset:2
+; GFX9-NEXT: global_store_short v[0:1], v2, off
+; GFX9-NEXT: s_waitcnt vmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: extract_multiple_v4i8:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v2, 0
+; GFX12-NEXT: ds_load_b32 v2, v2
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_clause 0x1
+; GFX12-NEXT: global_store_d16_hi_b8 v[0:1], v2, off offset:2
+; GFX12-NEXT: global_store_b16 v[0:1], v2, off
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <4 x i8>, ptr addrspace(3) %ptr, align 4
+ %e0 = extractelement <4 x i8> %val, i32 0
+ %e1 = extractelement <4 x i8> %val, i32 1
+ %e2 = extractelement <4 x i8> %val, i32 2
+ %out0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
+ store i8 %e0, ptr addrspace(1) %out0, align 1
+ %out1 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 1
+ store i8 %e1, ptr addrspace(1) %out1, align 1
+ %out2 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 2
+ store i8 %e2, ptr addrspace(1) %out2, align 1
+ ret void
+}
diff --git a/llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll b/llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll
new file mode 100644
index 0000000000000..a49e3c384715f
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll
@@ -0,0 +1,422 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck -check-prefixes=GFX9 %s
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 < %s | FileCheck -check-prefixes=GFX12 %s
+
+; Test showing when extractelement from v16i8/v8i8/v4i8 is free (no instructions)
+; versus when it generates shift instructions (cost > 0).
+
+ at lds = external addrspace(3) global [0 x i8], align 16
+
+; =============================================================================
+; v16i8 extracts - comparing free (aligned) vs non-free (shifts required)
+; =============================================================================
+
+; FREE: Extract at index 0 - low byte of first i32, no shift
+define i8 @v16i8_extract_index_0() {
+; GFX9-LABEL: v16i8_extract_index_0:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_0:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 0
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 1 - requires shift right by 8 bits
+define i8 @v16i8_extract_index_1() {
+; GFX9-LABEL: v16i8_extract_index_1:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_1:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 1
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 2 - requires shift right by 16 bits
+define i8 @v16i8_extract_index_2() {
+; GFX9-LABEL: v16i8_extract_index_2:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 16, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_2:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 16, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 2
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 3 - requires shift right by 24 bits
+define i8 @v16i8_extract_index_3() {
+; GFX9-LABEL: v16i8_extract_index_3:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_3:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 3
+ ret i8 %e
+}
+
+; FREE: Extract at index 4 - low byte of second i32, no shift
+define i8 @v16i8_extract_index_4() {
+; GFX9-LABEL: v16i8_extract_index_4:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0 offset:4
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_4:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0 offset:4
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 4
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 5 - requires shift right by 8 bits from second i32
+define i8 @v16i8_extract_index_5() {
+; GFX9-LABEL: v16i8_extract_index_5:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0 offset:4
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_5:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0 offset:4
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 5
+ ret i8 %e
+}
+
+; FREE: Extract at index 8 - low byte of third i32, no shift
+define i8 @v16i8_extract_index_8() {
+; GFX9-LABEL: v16i8_extract_index_8:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0 offset:8
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_8:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0 offset:8
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 8
+ ret i8 %e
+}
+
+; FREE: Extract at index 12 - low byte of fourth i32, no shift
+define i8 @v16i8_extract_index_12() {
+; GFX9-LABEL: v16i8_extract_index_12:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0 offset:12
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_12:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0 offset:12
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 12
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 15 - requires shift right by 24 bits from fourth i32
+define i8 @v16i8_extract_index_15() {
+; GFX9-LABEL: v16i8_extract_index_15:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0 offset:12
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v16i8_extract_index_15:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0 offset:12
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e = extractelement <16 x i8> %val, i32 15
+ ret i8 %e
+}
+
+; =============================================================================
+; v8i8 extracts - comparing free (aligned) vs non-free (shifts required)
+; =============================================================================
+
+; FREE: Extract at index 0 from v8i8 - low byte of first i32, no shift
+define i8 @v8i8_extract_index_0() {
+; GFX9-LABEL: v8i8_extract_index_0:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v8i8_extract_index_0:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <8 x i8>, ptr addrspace(3) %ptr, align 8
+ %e = extractelement <8 x i8> %val, i32 0
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 1 from v8i8 - requires shift
+define i8 @v8i8_extract_index_1() {
+; GFX9-LABEL: v8i8_extract_index_1:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v8i8_extract_index_1:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <8 x i8>, ptr addrspace(3) %ptr, align 8
+ %e = extractelement <8 x i8> %val, i32 1
+ ret i8 %e
+}
+
+; FREE: Extract at index 4 from v8i8 - low byte of second i32, no shift
+define i8 @v8i8_extract_index_4() {
+; GFX9-LABEL: v8i8_extract_index_4:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0 offset:4
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v8i8_extract_index_4:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0 offset:4
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <8 x i8>, ptr addrspace(3) %ptr, align 8
+ %e = extractelement <8 x i8> %val, i32 4
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 7 from v8i8 - requires shift
+define i8 @v8i8_extract_index_7() {
+; GFX9-LABEL: v8i8_extract_index_7:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0 offset:4
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v8i8_extract_index_7:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0 offset:4
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <8 x i8>, ptr addrspace(3) %ptr, align 8
+ %e = extractelement <8 x i8> %val, i32 7
+ ret i8 %e
+}
+
+; =============================================================================
+; v4i8 extracts - index 0 is free, others require shifts
+; =============================================================================
+
+; FREE: Extract at index 0 from v4i8 - low byte, no shift
+define i8 @v4i8_extract_index_0() {
+; GFX9-LABEL: v4i8_extract_index_0:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v4i8_extract_index_0:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <4 x i8>, ptr addrspace(3) %ptr, align 4
+ %e = extractelement <4 x i8> %val, i32 0
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 1 from v4i8 - requires shift
+define i8 @v4i8_extract_index_1() {
+; GFX9-LABEL: v4i8_extract_index_1:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v4i8_extract_index_1:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 8, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <4 x i8>, ptr addrspace(3) %ptr, align 4
+ %e = extractelement <4 x i8> %val, i32 1
+ ret i8 %e
+}
+
+; NOT FREE: Extract at index 3 from v4i8 - requires shift
+define i8 @v4i8_extract_index_3() {
+; GFX9-LABEL: v4i8_extract_index_3:
+; GFX9: ; %bb.0:
+; GFX9-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX9-NEXT: v_mov_b32_e32 v0, 0
+; GFX9-NEXT: ds_read_b32 v0, v0
+; GFX9-NEXT: s_waitcnt lgkmcnt(0)
+; GFX9-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX9-NEXT: s_setpc_b64 s[30:31]
+;
+; GFX12-LABEL: v4i8_extract_index_3:
+; GFX12: ; %bb.0:
+; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
+; GFX12-NEXT: s_wait_kmcnt 0x0
+; GFX12-NEXT: v_mov_b32_e32 v0, 0
+; GFX12-NEXT: ds_load_b32 v0, v0
+; GFX12-NEXT: s_wait_dscnt 0x0
+; GFX12-NEXT: v_lshrrev_b32_e32 v0, 24, v0
+; GFX12-NEXT: s_set_pc_i64 s[30:31]
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <4 x i8>, ptr addrspace(3) %ptr, align 4
+ %e = extractelement <4 x i8> %val, i32 3
+ ret i8 %e
+}
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/vectorize-i8.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/vectorize-i8.ll
index 605eccf26cd3c..179d1fb150de5 100644
--- a/llvm/test/Transforms/SLPVectorizer/AMDGPU/vectorize-i8.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/vectorize-i8.ll
@@ -74,12 +74,12 @@ define protected amdgpu_kernel void @arith_3(<16 x i8> %invec, ptr %out, i32 %fl
; GFX8-SAME: <16 x i8> [[INVEC:%.*]], ptr [[OUT:%.*]], i32 [[FLAG:%.*]]) #[[ATTR0]] {
; GFX8-NEXT: [[ENTRY:.*:]]
; GFX8-NEXT: [[EL0:%.*]] = extractelement <16 x i8> [[INVEC]], i64 0
-; GFX8-NEXT: [[MUL3:%.*]] = mul i8 [[EL0]], 1
-; GFX8-NEXT: [[ADD3:%.*]] = add i8 [[MUL3]], 1
+; GFX8-NEXT: [[MUL2:%.*]] = mul i8 [[EL0]], 1
+; GFX8-NEXT: [[ADD2:%.*]] = add i8 [[MUL2]], 1
; GFX8-NEXT: [[TMP0:%.*]] = shufflevector <16 x i8> [[INVEC]], <16 x i8> poison, <2 x i32> <i32 1, i32 2>
; GFX8-NEXT: [[TMP1:%.*]] = mul <2 x i8> [[TMP0]], splat (i8 1)
; GFX8-NEXT: [[TMP2:%.*]] = add <2 x i8> [[TMP1]], splat (i8 1)
-; GFX8-NEXT: [[VECINS0:%.*]] = insertelement <16 x i8> poison, i8 [[ADD3]], i64 0
+; GFX8-NEXT: [[VECINS0:%.*]] = insertelement <16 x i8> poison, i8 [[ADD2]], i64 0
; GFX8-NEXT: [[TMP3:%.*]] = shufflevector <2 x i8> [[TMP2]], <2 x i8> poison, <16 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
; GFX8-NEXT: [[VECINS2:%.*]] = shufflevector <16 x i8> [[VECINS0]], <16 x i8> [[TMP3]], <16 x i32> <i32 0, i32 16, i32 17, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
; GFX8-NEXT: store <16 x i8> [[VECINS2]], ptr [[OUT]], align 16
@@ -89,12 +89,12 @@ define protected amdgpu_kernel void @arith_3(<16 x i8> %invec, ptr %out, i32 %fl
; GFX9-SAME: <16 x i8> [[INVEC:%.*]], ptr [[OUT:%.*]], i32 [[FLAG:%.*]]) #[[ATTR0]] {
; GFX9-NEXT: [[ENTRY:.*:]]
; GFX9-NEXT: [[EL0:%.*]] = extractelement <16 x i8> [[INVEC]], i64 0
-; GFX9-NEXT: [[MUL3:%.*]] = mul i8 [[EL0]], 1
-; GFX9-NEXT: [[ADD3:%.*]] = add i8 [[MUL3]], 1
+; GFX9-NEXT: [[MUL2:%.*]] = mul i8 [[EL0]], 1
+; GFX9-NEXT: [[ADD2:%.*]] = add i8 [[MUL2]], 1
; GFX9-NEXT: [[TMP0:%.*]] = shufflevector <16 x i8> [[INVEC]], <16 x i8> poison, <2 x i32> <i32 1, i32 2>
; GFX9-NEXT: [[TMP1:%.*]] = mul <2 x i8> [[TMP0]], splat (i8 1)
; GFX9-NEXT: [[TMP2:%.*]] = add <2 x i8> [[TMP1]], splat (i8 1)
-; GFX9-NEXT: [[VECINS0:%.*]] = insertelement <16 x i8> poison, i8 [[ADD3]], i64 0
+; GFX9-NEXT: [[VECINS0:%.*]] = insertelement <16 x i8> poison, i8 [[ADD2]], i64 0
; GFX9-NEXT: [[TMP3:%.*]] = shufflevector <2 x i8> [[TMP2]], <2 x i8> poison, <16 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
; GFX9-NEXT: [[VECINS2:%.*]] = shufflevector <16 x i8> [[VECINS0]], <16 x i8> [[TMP3]], <16 x i32> <i32 0, i32 16, i32 17, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
; GFX9-NEXT: store <16 x i8> [[VECINS2]], ptr [[OUT]], align 16
diff --git a/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-chain-to-shuffles.ll b/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-chain-to-shuffles.ll
index b6ba6eb984c85..467ad37357e0f 100644
--- a/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-chain-to-shuffles.ll
+++ b/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-chain-to-shuffles.ll
@@ -8,7 +8,16 @@ define amdgpu_kernel void @extract_insert_chain_to_shuffles(<16 x i8> %in, <16 x
; OPT-LABEL: define amdgpu_kernel void @extract_insert_chain_to_shuffles(
; OPT-SAME: <16 x i8> [[IN:%.*]], <16 x i8> [[ADD:%.*]], ptr addrspace(3) [[OUT:%.*]]) #[[ATTR0:[0-9]+]] {
; OPT-NEXT: [[ENTRY:.*:]]
-; OPT-NEXT: [[SUM:%.*]] = add <16 x i8> [[IN]], [[ADD]]
+; OPT-NEXT: [[I168:%.*]] = extractelement <16 x i8> [[IN]], i64 4
+; OPT-NEXT: [[I176:%.*]] = extractelement <16 x i8> [[IN]], i64 8
+; OPT-NEXT: [[I184:%.*]] = extractelement <16 x i8> [[IN]], i64 12
+; OPT-NEXT: [[I260:%.*]] = insertelement <16 x i8> [[IN]], i8 [[I168]], i64 4
+; OPT-NEXT: [[I263:%.*]] = shufflevector <16 x i8> [[I260]], <16 x i8> [[IN]], <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 21, i32 22, i32 23, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
+; OPT-NEXT: [[I264:%.*]] = insertelement <16 x i8> [[I263]], i8 [[I176]], i64 8
+; OPT-NEXT: [[I267:%.*]] = shufflevector <16 x i8> [[I264]], <16 x i8> [[IN]], <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 25, i32 26, i32 27, i32 12, i32 13, i32 14, i32 15>
+; OPT-NEXT: [[I268:%.*]] = insertelement <16 x i8> [[I267]], i8 [[I184]], i64 12
+; OPT-NEXT: [[I271:%.*]] = shufflevector <16 x i8> [[I268]], <16 x i8> [[IN]], <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[SUM:%.*]] = add <16 x i8> [[I271]], [[ADD]]
; OPT-NEXT: store <16 x i8> [[SUM]], ptr addrspace(3) [[OUT]], align 16
; OPT-NEXT: ret void
;
diff --git a/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-i8.ll b/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-i8.ll
index 6c92892949175..15ead774a4270 100644
--- a/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-i8.ll
+++ b/llvm/test/Transforms/VectorCombine/AMDGPU/extract-insert-i8.ll
@@ -5,11 +5,38 @@ define <32 x i8> @extract_insert_chain(<8 x i8> %in0, <8 x i8> %in1, <8 x i8> %i
; OPT-LABEL: define <32 x i8> @extract_insert_chain(
; OPT-SAME: <8 x i8> [[IN0:%.*]], <8 x i8> [[IN1:%.*]], <8 x i8> [[IN2:%.*]], <8 x i8> [[IN3:%.*]]) #[[ATTR0:[0-9]+]] {
; OPT-NEXT: [[ENTRY:.*:]]
-; OPT-NEXT: [[O_1_7:%.*]] = shufflevector <8 x i8> [[IN0]], <8 x i8> [[IN1]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; OPT-NEXT: [[TMP2:%.*]] = shufflevector <8 x i8> [[IN2]], <8 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; OPT-NEXT: [[O_2_7:%.*]] = shufflevector <32 x i8> [[O_1_7]], <32 x i8> [[TMP2]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
-; OPT-NEXT: [[TMP3:%.*]] = shufflevector <8 x i8> [[IN3]], <8 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
-; OPT-NEXT: [[O_3_7:%.*]] = shufflevector <32 x i8> [[O_2_7]], <32 x i8> [[TMP3]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39>
+; OPT-NEXT: [[I_0_0:%.*]] = extractelement <8 x i8> [[IN0]], i64 0
+; OPT-NEXT: [[I_0_4:%.*]] = extractelement <8 x i8> [[IN0]], i64 4
+; OPT-NEXT: [[I_1_0:%.*]] = extractelement <8 x i8> [[IN1]], i64 0
+; OPT-NEXT: [[I_1_4:%.*]] = extractelement <8 x i8> [[IN1]], i64 4
+; OPT-NEXT: [[I_2_0:%.*]] = extractelement <8 x i8> [[IN2]], i64 0
+; OPT-NEXT: [[I_2_4:%.*]] = extractelement <8 x i8> [[IN2]], i64 4
+; OPT-NEXT: [[I_3_0:%.*]] = extractelement <8 x i8> [[IN3]], i64 0
+; OPT-NEXT: [[I_3_4:%.*]] = extractelement <8 x i8> [[IN3]], i64 4
+; OPT-NEXT: [[O_0_0:%.*]] = insertelement <32 x i8> poison, i8 [[I_0_0]], i32 0
+; OPT-NEXT: [[TMP0:%.*]] = shufflevector <8 x i8> [[IN0]], <8 x i8> poison, <32 x i32> <i32 poison, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_0_3:%.*]] = shufflevector <32 x i8> [[O_0_0]], <32 x i8> [[TMP0]], <32 x i32> <i32 0, i32 33, i32 34, i32 35, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[O_0_4:%.*]] = insertelement <32 x i8> [[O_0_3]], i8 [[I_0_4]], i32 4
+; OPT-NEXT: [[TMP1:%.*]] = shufflevector <8 x i8> [[IN0]], <8 x i8> poison, <32 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_0_7:%.*]] = shufflevector <32 x i8> [[O_0_4]], <32 x i8> [[TMP1]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 37, i32 38, i32 39, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[O_1_0:%.*]] = insertelement <32 x i8> [[O_0_7]], i8 [[I_1_0]], i32 8
+; OPT-NEXT: [[TMP2:%.*]] = shufflevector <8 x i8> [[IN1]], <8 x i8> poison, <32 x i32> <i32 poison, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_1_3:%.*]] = shufflevector <32 x i8> [[O_1_0]], <32 x i8> [[TMP2]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 33, i32 34, i32 35, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[O_1_4:%.*]] = insertelement <32 x i8> [[O_1_3]], i8 [[I_1_4]], i32 12
+; OPT-NEXT: [[TMP3:%.*]] = shufflevector <8 x i8> [[IN1]], <8 x i8> poison, <32 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_1_7:%.*]] = shufflevector <32 x i8> [[O_1_4]], <32 x i8> [[TMP3]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 37, i32 38, i32 39, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[O_2_0:%.*]] = insertelement <32 x i8> [[O_1_7]], i8 [[I_2_0]], i32 16
+; OPT-NEXT: [[TMP4:%.*]] = shufflevector <8 x i8> [[IN2]], <8 x i8> poison, <32 x i32> <i32 poison, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_2_3:%.*]] = shufflevector <32 x i8> [[O_2_0]], <32 x i8> [[TMP4]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 33, i32 34, i32 35, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[O_2_4:%.*]] = insertelement <32 x i8> [[O_2_3]], i8 [[I_2_4]], i32 20
+; OPT-NEXT: [[TMP5:%.*]] = shufflevector <8 x i8> [[IN2]], <8 x i8> poison, <32 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_2_7:%.*]] = shufflevector <32 x i8> [[O_2_4]], <32 x i8> [[TMP5]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 37, i32 38, i32 39, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[O_3_0:%.*]] = insertelement <32 x i8> [[O_2_7]], i8 [[I_3_0]], i32 24
+; OPT-NEXT: [[TMP6:%.*]] = shufflevector <8 x i8> [[IN3]], <8 x i8> poison, <32 x i32> <i32 poison, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_3_3:%.*]] = shufflevector <32 x i8> [[O_3_0]], <32 x i8> [[TMP6]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 33, i32 34, i32 35, i32 28, i32 29, i32 30, i32 31>
+; OPT-NEXT: [[O_3_4:%.*]] = insertelement <32 x i8> [[O_3_3]], i8 [[I_3_4]], i32 28
+; OPT-NEXT: [[TMP7:%.*]] = shufflevector <8 x i8> [[IN3]], <8 x i8> poison, <32 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_3_7:%.*]] = shufflevector <32 x i8> [[O_3_4]], <32 x i8> [[TMP7]], <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 37, i32 38, i32 39>
; OPT-NEXT: ret <32 x i8> [[O_3_7]]
;
entry:
@@ -88,7 +115,14 @@ entry:
define <8 x i8> @extract_insert_chain_shortening(<32 x i8> %in) {
; OPT-LABEL: define <8 x i8> @extract_insert_chain_shortening(
; OPT-SAME: <32 x i8> [[IN:%.*]]) #[[ATTR0]] {
-; OPT-NEXT: [[TMP1:%.*]] = shufflevector <32 x i8> [[IN]], <32 x i8> poison, <8 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23>
+; OPT-NEXT: [[I_0:%.*]] = extractelement <32 x i8> [[IN]], i64 16
+; OPT-NEXT: [[I_4:%.*]] = extractelement <32 x i8> [[IN]], i64 20
+; OPT-NEXT: [[O_0:%.*]] = insertelement <8 x i8> poison, i8 [[I_0]], i32 0
+; OPT-NEXT: [[TMP3:%.*]] = shufflevector <32 x i8> [[IN]], <32 x i8> poison, <8 x i32> <i32 poison, i32 17, i32 18, i32 19, i32 poison, i32 poison, i32 poison, i32 poison>
+; OPT-NEXT: [[O_3:%.*]] = shufflevector <8 x i8> [[O_0]], <8 x i8> [[TMP3]], <8 x i32> <i32 0, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
+; OPT-NEXT: [[O_4:%.*]] = insertelement <8 x i8> [[O_3]], i8 [[I_4]], i32 4
+; OPT-NEXT: [[TMP2:%.*]] = shufflevector <32 x i8> [[IN]], <32 x i8> poison, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 21, i32 22, i32 23>
+; OPT-NEXT: [[TMP1:%.*]] = shufflevector <8 x i8> [[O_4]], <8 x i8> [[TMP2]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 13, i32 14, i32 15>
; OPT-NEXT: ret <8 x i8> [[TMP1]]
;
%i.0 = extractelement <32 x i8> %in, i64 16
diff --git a/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll b/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
new file mode 100644
index 0000000000000..f8bb00ab78f48
--- /dev/null
+++ b/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
@@ -0,0 +1,150 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -passes=vector-combine < %s | FileCheck -check-prefix=GFX9 %s
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 -passes=vector-combine < %s | FileCheck -check-prefix=GFX12 %s
+
+; Test that VectorCombine does not scalarize v16i8/v8i8/v4i8 loads from LDS.
+; Vector loads can be efficiently lowered to ds_read_b128/b64/b32 instructions,
+; so scalarization would be a pessimization.
+
+ at lds = external addrspace(3) global [0 x i8], align 16
+
+define void @test_v16i8_load_with_extracts_no_scalarize(ptr addrspace(1) %out) {
+; GFX9-LABEL: @test_v16i8_load_with_extracts_no_scalarize(
+; GFX9-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX9-NEXT: [[VAL:%.*]] = load <16 x i8>, ptr addrspace(3) [[PTR]], align 16
+; GFX9-NEXT: [[E0:%.*]] = extractelement <16 x i8> [[VAL]], i64 0
+; GFX9-NEXT: [[E1:%.*]] = extractelement <16 x i8> [[VAL]], i64 1
+; GFX9-NEXT: [[E3:%.*]] = extractelement <16 x i8> [[VAL]], i64 3
+; GFX9-NEXT: [[E12:%.*]] = extractelement <16 x i8> [[VAL]], i64 12
+; GFX9-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX9-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX9-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 4
+; GFX9-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
+; GFX9-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
+; GFX9-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
+; GFX9-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 12
+; GFX9-NEXT: store i8 [[E12]], ptr addrspace(1) [[P12]], align 1
+; GFX9-NEXT: ret void
+;
+; GFX12-LABEL: @test_v16i8_load_with_extracts_no_scalarize(
+; GFX12-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX12-NEXT: [[VAL:%.*]] = load <16 x i8>, ptr addrspace(3) [[PTR]], align 16
+; GFX12-NEXT: [[E0:%.*]] = extractelement <16 x i8> [[VAL]], i64 0
+; GFX12-NEXT: [[E1:%.*]] = extractelement <16 x i8> [[VAL]], i64 1
+; GFX12-NEXT: [[E3:%.*]] = extractelement <16 x i8> [[VAL]], i64 3
+; GFX12-NEXT: [[E12:%.*]] = extractelement <16 x i8> [[VAL]], i64 12
+; GFX12-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX12-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX12-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 4
+; GFX12-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
+; GFX12-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
+; GFX12-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
+; GFX12-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 12
+; GFX12-NEXT: store i8 [[E12]], ptr addrspace(1) [[P12]], align 1
+; GFX12-NEXT: ret void
+;
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e0 = extractelement <16 x i8> %val, i64 0
+ %e1 = extractelement <16 x i8> %val, i64 1
+ %e3 = extractelement <16 x i8> %val, i64 3
+ %e12 = extractelement <16 x i8> %val, i64 12
+ %p0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
+ store i8 %e0, ptr addrspace(1) %p0, align 1
+ %p4 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 4
+ store i8 %e1, ptr addrspace(1) %p4, align 1
+ %p8 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 8
+ store i8 %e3, ptr addrspace(1) %p8, align 1
+ %p12 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 12
+ store i8 %e12, ptr addrspace(1) %p12, align 1
+ ret void
+}
+
+define void @test_v8i8_load_with_extracts_no_scalarize(ptr addrspace(1) %out) {
+; GFX9-LABEL: @test_v8i8_load_with_extracts_no_scalarize(
+; GFX9-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX9-NEXT: [[VAL:%.*]] = load <8 x i8>, ptr addrspace(3) [[PTR]], align 16
+; GFX9-NEXT: [[E0:%.*]] = extractelement <8 x i8> [[VAL]], i64 1
+; GFX9-NEXT: [[E3:%.*]] = extractelement <8 x i8> [[VAL]], i64 3
+; GFX9-NEXT: [[E4:%.*]] = extractelement <8 x i8> [[VAL]], i64 4
+; GFX9-NEXT: [[E6:%.*]] = extractelement <8 x i8> [[VAL]], i64 6
+; GFX9-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX9-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX9-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 2
+; GFX9-NEXT: store i8 [[E3]], ptr addrspace(1) [[P4]], align 1
+; GFX9-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 6
+; GFX9-NEXT: store i8 [[E4]], ptr addrspace(1) [[P8]], align 1
+; GFX9-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 7
+; GFX9-NEXT: store i8 [[E6]], ptr addrspace(1) [[P12]], align 1
+; GFX9-NEXT: ret void
+;
+; GFX12-LABEL: @test_v8i8_load_with_extracts_no_scalarize(
+; GFX12-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX12-NEXT: [[VAL:%.*]] = load <8 x i8>, ptr addrspace(3) [[PTR]], align 16
+; GFX12-NEXT: [[E0:%.*]] = extractelement <8 x i8> [[VAL]], i64 1
+; GFX12-NEXT: [[E3:%.*]] = extractelement <8 x i8> [[VAL]], i64 3
+; GFX12-NEXT: [[E4:%.*]] = extractelement <8 x i8> [[VAL]], i64 4
+; GFX12-NEXT: [[E6:%.*]] = extractelement <8 x i8> [[VAL]], i64 6
+; GFX12-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX12-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX12-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 2
+; GFX12-NEXT: store i8 [[E3]], ptr addrspace(1) [[P4]], align 1
+; GFX12-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 6
+; GFX12-NEXT: store i8 [[E4]], ptr addrspace(1) [[P8]], align 1
+; GFX12-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 7
+; GFX12-NEXT: store i8 [[E6]], ptr addrspace(1) [[P12]], align 1
+; GFX12-NEXT: ret void
+;
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <8 x i8>, ptr addrspace(3) %ptr, align 16
+ %e0 = extractelement <8 x i8> %val, i64 1
+ %e3 = extractelement <8 x i8> %val, i64 3
+ %e4 = extractelement <8 x i8> %val, i64 4
+ %e6 = extractelement <8x i8> %val, i64 6
+ %p0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
+ store i8 %e0, ptr addrspace(1) %p0, align 1
+ %p4 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 2
+ store i8 %e3, ptr addrspace(1) %p4, align 1
+ %p8 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 6
+ store i8 %e4, ptr addrspace(1) %p8, align 1
+ %p12 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 7
+ store i8 %e6, ptr addrspace(1) %p12, align 1
+ ret void
+}
+
+define void @test_v4i8_load_with_extracts_no_scalarize(ptr addrspace(1) %out) {
+; GFX9-LABEL: @test_v4i8_load_with_extracts_no_scalarize(
+; GFX9-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX9-NEXT: [[TMP1:%.*]] = getelementptr inbounds <4 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 1
+; GFX9-NEXT: [[E0:%.*]] = load i8, ptr addrspace(3) [[TMP1]], align 1
+; GFX9-NEXT: [[TMP2:%.*]] = getelementptr inbounds <4 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 3
+; GFX9-NEXT: [[E3:%.*]] = load i8, ptr addrspace(3) [[TMP2]], align 1
+; GFX9-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX9-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX9-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 2
+; GFX9-NEXT: store i8 [[E3]], ptr addrspace(1) [[P4]], align 1
+; GFX9-NEXT: ret void
+;
+; GFX12-LABEL: @test_v4i8_load_with_extracts_no_scalarize(
+; GFX12-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX12-NEXT: [[TMP1:%.*]] = getelementptr inbounds <4 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 1
+; GFX12-NEXT: [[E0:%.*]] = load i8, ptr addrspace(3) [[TMP1]], align 1
+; GFX12-NEXT: [[TMP2:%.*]] = getelementptr inbounds <4 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 3
+; GFX12-NEXT: [[E3:%.*]] = load i8, ptr addrspace(3) [[TMP2]], align 1
+; GFX12-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX12-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX12-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 2
+; GFX12-NEXT: store i8 [[E3]], ptr addrspace(1) [[P4]], align 1
+; GFX12-NEXT: ret void
+;
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <4 x i8>, ptr addrspace(3) %ptr, align 16
+ %e0 = extractelement <4 x i8> %val, i64 1
+ %e3 = extractelement <4 x i8> %val, i64 3
+ %p0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
+ store i8 %e0, ptr addrspace(1) %p0, align 1
+ %p4 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 2
+ store i8 %e3, ptr addrspace(1) %p4, align 1
+ ret void
+}
+
>From a8a301bf537aeb5318031690a6bc9b0556b43d87 Mon Sep 17 00:00:00 2001
From: Brendon Cahoon <brendon.cahoon at amd.com>
Date: Thu, 30 Apr 2026 10:05:43 -0500
Subject: [PATCH 2/5] Use latest version number for update_llc_test_checks.py
---
llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll | 2 +-
llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll b/llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll
index 2ec357ebded53..217868d5b7b59 100644
--- a/llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll
+++ b/llvm/test/CodeGen/AMDGPU/extract-i8-codegen.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck -check-prefix=GFX9 %s
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 < %s | FileCheck -check-prefix=GFX12 %s
diff --git a/llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll b/llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll
index a49e3c384715f..bb75a6fbd0c77 100644
--- a/llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll
+++ b/llvm/test/CodeGen/AMDGPU/i8-extract-cost-comparison.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 < %s | FileCheck -check-prefixes=GFX9 %s
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 < %s | FileCheck -check-prefixes=GFX12 %s
>From 3b7ecaef8a48826078160d16de3836330ead070e Mon Sep 17 00:00:00 2001
From: Brendon Cahoon <brendon.cahoon at amd.com>
Date: Fri, 1 May 2026 14:02:16 -0500
Subject: [PATCH 3/5] Add a negative test that does scalarization and one with
dynamic index
The negative shows that VectorCombine many scalarize vector loads if
all the extract elements have a cost, which happens when the index is
not aligned.
VectorCombine does not scalarize extract elements with dynamic indices.
---
.../AMDGPU/no-scalarize-vector-extract.ll | 117 ++++++++++++++++--
1 file changed, 110 insertions(+), 7 deletions(-)
diff --git a/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll b/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
index f8bb00ab78f48..68745af71b8a8 100644
--- a/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
+++ b/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
@@ -15,14 +15,14 @@ define void @test_v16i8_load_with_extracts_no_scalarize(ptr addrspace(1) %out) {
; GFX9-NEXT: [[E0:%.*]] = extractelement <16 x i8> [[VAL]], i64 0
; GFX9-NEXT: [[E1:%.*]] = extractelement <16 x i8> [[VAL]], i64 1
; GFX9-NEXT: [[E3:%.*]] = extractelement <16 x i8> [[VAL]], i64 3
-; GFX9-NEXT: [[E12:%.*]] = extractelement <16 x i8> [[VAL]], i64 12
+; GFX9-NEXT: [[E12:%.*]] = extractelement <16 x i8> [[VAL]], i64 8
; GFX9-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
; GFX9-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
; GFX9-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 4
; GFX9-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
; GFX9-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
; GFX9-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
-; GFX9-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 12
+; GFX9-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 11
; GFX9-NEXT: store i8 [[E12]], ptr addrspace(1) [[P12]], align 1
; GFX9-NEXT: ret void
;
@@ -32,14 +32,14 @@ define void @test_v16i8_load_with_extracts_no_scalarize(ptr addrspace(1) %out) {
; GFX12-NEXT: [[E0:%.*]] = extractelement <16 x i8> [[VAL]], i64 0
; GFX12-NEXT: [[E1:%.*]] = extractelement <16 x i8> [[VAL]], i64 1
; GFX12-NEXT: [[E3:%.*]] = extractelement <16 x i8> [[VAL]], i64 3
-; GFX12-NEXT: [[E12:%.*]] = extractelement <16 x i8> [[VAL]], i64 12
+; GFX12-NEXT: [[E12:%.*]] = extractelement <16 x i8> [[VAL]], i64 8
; GFX12-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
; GFX12-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
; GFX12-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 4
; GFX12-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
; GFX12-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
; GFX12-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
-; GFX12-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 12
+; GFX12-NEXT: [[P12:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 11
; GFX12-NEXT: store i8 [[E12]], ptr addrspace(1) [[P12]], align 1
; GFX12-NEXT: ret void
;
@@ -48,15 +48,118 @@ define void @test_v16i8_load_with_extracts_no_scalarize(ptr addrspace(1) %out) {
%e0 = extractelement <16 x i8> %val, i64 0
%e1 = extractelement <16 x i8> %val, i64 1
%e3 = extractelement <16 x i8> %val, i64 3
- %e12 = extractelement <16 x i8> %val, i64 12
+ %e8 = extractelement <16 x i8> %val, i64 8
%p0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
store i8 %e0, ptr addrspace(1) %p0, align 1
%p4 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 4
store i8 %e1, ptr addrspace(1) %p4, align 1
%p8 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 8
store i8 %e3, ptr addrspace(1) %p8, align 1
- %p12 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 12
- store i8 %e12, ptr addrspace(1) %p12, align 1
+ %p11 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 11
+ store i8 %e8, ptr addrspace(1) %p11, align 1
+ ret void
+}
+
+; VectorCombine will scalarize when the cost model assigns a cost to
+; extract elements, which occurs when the index values are no aligned.
+define void @test_v16i8_load_with_extracts_scalarize(ptr addrspace(1) %out) {
+; GFX9-LABEL: @test_v16i8_load_with_extracts_scalarize(
+; GFX9-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX9-NEXT: [[TMP1:%.*]] = getelementptr inbounds <16 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 1
+; GFX9-NEXT: [[E1:%.*]] = load i8, ptr addrspace(3) [[TMP1]], align 1
+; GFX9-NEXT: [[TMP2:%.*]] = getelementptr inbounds <16 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 3
+; GFX9-NEXT: [[E3:%.*]] = load i8, ptr addrspace(3) [[TMP2]], align 1
+; GFX9-NEXT: [[TMP3:%.*]] = getelementptr inbounds <16 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 5
+; GFX9-NEXT: [[E5:%.*]] = load i8, ptr addrspace(3) [[TMP3]], align 1
+; GFX9-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 3
+; GFX9-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
+; GFX9-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
+; GFX9-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
+; GFX9-NEXT: [[P11:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 11
+; GFX9-NEXT: store i8 [[E5]], ptr addrspace(1) [[P11]], align 1
+; GFX9-NEXT: ret void
+;
+; GFX12-LABEL: @test_v16i8_load_with_extracts_scalarize(
+; GFX12-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX12-NEXT: [[TMP1:%.*]] = getelementptr inbounds <16 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 1
+; GFX12-NEXT: [[E1:%.*]] = load i8, ptr addrspace(3) [[TMP1]], align 1
+; GFX12-NEXT: [[TMP2:%.*]] = getelementptr inbounds <16 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 3
+; GFX12-NEXT: [[E3:%.*]] = load i8, ptr addrspace(3) [[TMP2]], align 1
+; GFX12-NEXT: [[TMP3:%.*]] = getelementptr inbounds <16 x i8>, ptr addrspace(3) [[PTR]], i32 0, i64 5
+; GFX12-NEXT: [[E5:%.*]] = load i8, ptr addrspace(3) [[TMP3]], align 1
+; GFX12-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 3
+; GFX12-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
+; GFX12-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
+; GFX12-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
+; GFX12-NEXT: [[P11:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 11
+; GFX12-NEXT: store i8 [[E5]], ptr addrspace(1) [[P11]], align 1
+; GFX12-NEXT: ret void
+;
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e1 = extractelement <16 x i8> %val, i64 1
+ %e3 = extractelement <16 x i8> %val, i64 3
+ %e5 = extractelement <16 x i8> %val, i64 5
+ %p4 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 3
+ store i8 %e1, ptr addrspace(1) %p4, align 1
+ %p8 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 8
+ store i8 %e3, ptr addrspace(1) %p8, align 1
+ %p11 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 11
+ store i8 %e5, ptr addrspace(1) %p11, align 1
+ ret void
+}
+
+; VectorCombine does not attempt to scalarize loads with extracts of dynamic
+; indices.
+define void @test_v16i8_load_with_dynamic_index_extracts(ptr addrspace(1) %out, i64 %arg) {
+; GFX9-LABEL: @test_v16i8_load_with_dynamic_index_extracts(
+; GFX9-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX9-NEXT: [[VAL:%.*]] = load <16 x i8>, ptr addrspace(3) [[PTR]], align 16
+; GFX9-NEXT: [[E0:%.*]] = extractelement <16 x i8> [[VAL]], i64 [[ARG:%.*]]
+; GFX9-NEXT: [[E1:%.*]] = extractelement <16 x i8> [[VAL]], i64 1
+; GFX9-NEXT: [[E3:%.*]] = extractelement <16 x i8> [[VAL]], i64 3
+; GFX9-NEXT: [[E8:%.*]] = extractelement <16 x i8> [[VAL]], i64 8
+; GFX9-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX9-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX9-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 4
+; GFX9-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
+; GFX9-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
+; GFX9-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
+; GFX9-NEXT: [[P11:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 11
+; GFX9-NEXT: store i8 [[E8]], ptr addrspace(1) [[P11]], align 1
+; GFX9-NEXT: ret void
+;
+; GFX12-LABEL: @test_v16i8_load_with_dynamic_index_extracts(
+; GFX12-NEXT: [[PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+; GFX12-NEXT: [[VAL:%.*]] = load <16 x i8>, ptr addrspace(3) [[PTR]], align 16
+; GFX12-NEXT: [[E0:%.*]] = extractelement <16 x i8> [[VAL]], i64 [[ARG:%.*]]
+; GFX12-NEXT: [[E1:%.*]] = extractelement <16 x i8> [[VAL]], i64 1
+; GFX12-NEXT: [[E3:%.*]] = extractelement <16 x i8> [[VAL]], i64 3
+; GFX12-NEXT: [[E8:%.*]] = extractelement <16 x i8> [[VAL]], i64 8
+; GFX12-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT:%.*]], i64 0
+; GFX12-NEXT: store i8 [[E0]], ptr addrspace(1) [[P0]], align 1
+; GFX12-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 4
+; GFX12-NEXT: store i8 [[E1]], ptr addrspace(1) [[P4]], align 1
+; GFX12-NEXT: [[P8:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 8
+; GFX12-NEXT: store i8 [[E3]], ptr addrspace(1) [[P8]], align 1
+; GFX12-NEXT: [[P11:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[OUT]], i64 11
+; GFX12-NEXT: store i8 [[E8]], ptr addrspace(1) [[P11]], align 1
+; GFX12-NEXT: ret void
+;
+ %ptr = getelementptr inbounds i8, ptr addrspace(3) @lds, i32 0
+ %val = load <16 x i8>, ptr addrspace(3) %ptr, align 16
+ %e0 = extractelement <16 x i8> %val, i64 %arg
+ %e1 = extractelement <16 x i8> %val, i64 1
+ %e3 = extractelement <16 x i8> %val, i64 3
+ %e8 = extractelement <16 x i8> %val, i64 8
+ %p0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
+ store i8 %e0, ptr addrspace(1) %p0, align 1
+ %p4 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 4
+ store i8 %e1, ptr addrspace(1) %p4, align 1
+ %p8 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 8
+ store i8 %e3, ptr addrspace(1) %p8, align 1
+ %p11 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 11
+ store i8 %e8, ptr addrspace(1) %p11, align 1
ret void
}
>From dfcb10c45aa77f63fce0272b8b05b3544005f1d3 Mon Sep 17 00:00:00 2001
From: Brendon Cahoon <brendon.cahoon at amd.com>
Date: Tue, 5 May 2026 11:28:14 -0500
Subject: [PATCH 4/5] Fix typo in lit test
---
.../VectorCombine/AMDGPU/no-scalarize-vector-extract.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll b/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
index 68745af71b8a8..8623ea46314da 100644
--- a/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
+++ b/llvm/test/Transforms/VectorCombine/AMDGPU/no-scalarize-vector-extract.ll
@@ -203,7 +203,7 @@ define void @test_v8i8_load_with_extracts_no_scalarize(ptr addrspace(1) %out) {
%e0 = extractelement <8 x i8> %val, i64 1
%e3 = extractelement <8 x i8> %val, i64 3
%e4 = extractelement <8 x i8> %val, i64 4
- %e6 = extractelement <8x i8> %val, i64 6
+ %e6 = extractelement <8 x i8> %val, i64 6
%p0 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 0
store i8 %e0, ptr addrspace(1) %p0, align 1
%p4 = getelementptr inbounds i8, ptr addrspace(1) %out, i64 2
>From 7f1c9b039dfcc43af0d756de1127cc44edb17395 Mon Sep 17 00:00:00 2001
From: Brendon Cahoon <brendon.cahoon at amd.com>
Date: Thu, 7 May 2026 08:56:46 -0500
Subject: [PATCH 5/5] Fix rebase with undef to poison changes
---
.../CostModel/AMDGPU/extractelement.ll | 48 +++++++++----------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll b/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll
index bba63cc6e9deb..80b3287de03f4 100644
--- a/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll
+++ b/llvm/test/Analysis/CostModel/AMDGPU/extractelement.ll
@@ -186,14 +186,14 @@ define amdgpu_kernel void @extractelement_8(i32 %arg) {
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_3 = extractelement <4 x i8> poison, i32 3
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_3 = extractelement <5 x i8> poison, i32 3
; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_3 = extractelement <8 x i8> poison, i32 3
-; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = extractelement <2 x i8> undef, i32 %arg
-; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = extractelement <4 x i8> undef, i32 %arg
-; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = extractelement <8 x i8> undef, i32 %arg
-; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = extractelement <16 x i8> undef, i32 0
-; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_1 = extractelement <16 x i8> undef, i32 1
-; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = extractelement <16 x i8> undef, i32 8
-; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = extractelement <16 x i8> undef, i32 15
-; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = extractelement <16 x i8> undef, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = extractelement <2 x i8> poison, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = extractelement <4 x i8> poison, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = extractelement <8 x i8> poison, i32 %arg
+; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = extractelement <16 x i8> poison, i32 0
+; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_1 = extractelement <16 x i8> poison, i32 1
+; GCN-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = extractelement <16 x i8> poison, i32 8
+; GCN-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = extractelement <16 x i8> poison, i32 15
+; GCN-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = extractelement <16 x i8> poison, i32 %arg
; GCN-NEXT: Cost Model: Found an estimated cost of 10 for instruction: ret void
;
; GCN-SIZE-LABEL: 'extractelement_8'
@@ -214,14 +214,14 @@ define amdgpu_kernel void @extractelement_8(i32 %arg) {
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v4i8_3 = extractelement <4 x i8> poison, i32 3
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v5i8_3 = extractelement <5 x i8> poison, i32 3
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v8i8_3 = extractelement <8 x i8> poison, i32 3
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = extractelement <2 x i8> undef, i32 %arg
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = extractelement <4 x i8> undef, i32 %arg
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = extractelement <8 x i8> undef, i32 %arg
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = extractelement <16 x i8> undef, i32 0
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_1 = extractelement <16 x i8> undef, i32 1
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = extractelement <16 x i8> undef, i32 8
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = extractelement <16 x i8> undef, i32 15
-; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = extractelement <16 x i8> undef, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v2i8_a = extractelement <2 x i8> poison, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v4i8_a = extractelement <4 x i8> poison, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v8i8_a = extractelement <8 x i8> poison, i32 %arg
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_0 = extractelement <16 x i8> poison, i32 0
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_1 = extractelement <16 x i8> poison, i32 1
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %v16i8_8 = extractelement <16 x i8> poison, i32 8
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %v16i8_15 = extractelement <16 x i8> poison, i32 15
+; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %v16i8_a = extractelement <16 x i8> poison, i32 %arg
; GCN-SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret void
;
%v2i8_0 = extractelement <2 x i8> poison, i32 0
@@ -245,15 +245,15 @@ define amdgpu_kernel void @extractelement_8(i32 %arg) {
%v5i8_3 = extractelement <5 x i8> poison, i32 3
%v8i8_3 = extractelement <8 x i8> poison, i32 3
- %v2i8_a = extractelement <2 x i8> undef, i32 %arg
- %v4i8_a = extractelement <4 x i8> undef, i32 %arg
- %v8i8_a = extractelement <8 x i8> undef, i32 %arg
+ %v2i8_a = extractelement <2 x i8> poison, i32 %arg
+ %v4i8_a = extractelement <4 x i8> poison, i32 %arg
+ %v8i8_a = extractelement <8 x i8> poison, i32 %arg
- %v16i8_0 = extractelement <16 x i8> undef, i32 0
- %v16i8_1 = extractelement <16 x i8> undef, i32 1
- %v16i8_8 = extractelement <16 x i8> undef, i32 8
- %v16i8_15 = extractelement <16 x i8> undef, i32 15
- %v16i8_a = extractelement <16 x i8> undef, i32 %arg
+ %v16i8_0 = extractelement <16 x i8> poison, i32 0
+ %v16i8_1 = extractelement <16 x i8> poison, i32 1
+ %v16i8_8 = extractelement <16 x i8> poison, i32 8
+ %v16i8_15 = extractelement <16 x i8> poison, i32 15
+ %v16i8_a = extractelement <16 x i8> poison, i32 %arg
ret void
}
More information about the llvm-commits
mailing list