[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
https://github.com/Alexander-Johnston edited https://github.com/llvm/llvm-project/pull/228518 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.6-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-int16-type
-fnative-half-type -o - | \
+// RUN: FileCheck %s -check-prefix=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
spirv-pc-vulkan-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-int16-type
-fnative-half-type -o - | \
+// RUN: FileCheck %s -check-prefix=CHECK,CHECK-SPV
+
+// CHECK: define {{.*}} <4 x i16> @_Z10test_u8u16u15uint8_t4_packed
+// CHECK-DXIL: [[VAR:%.*]] = call { i16, i16, i16, i16 }
@llvm.dx.unpack.u8u16(i32 %{{.*}})
+// CHECK-DXIL: %{{.*}} = extractvalue { i16, i16, i16, i16 } [[VAR]], 0
+// CHECK-DXIL: %{{.*}} = insertelement <4 x i16>
+// CHECK-DXIL: %{{.*}} = extractvalue { i16, i16, i16, i16 } [[VAR]], 1
+// CHECK-DXIL: %{{.*}} = insertelement <4 x i16>
+// CHECK-DXIL: %{{.*}} = extractvalue { i16, i16, i16, i16 } [[VAR]], 2
+// CHECK-DXIL: %{{.*}} = insertelement <4 x i16>
+// CHECK-DXIL: %{{.*}} = extractvalue { i16, i16, i16, i16 } [[VAR]], 3
+// CHECK-DXIL: %{{.*}} = insertelement <4 x i16>
+// CHECK-DXIL: ret <4 x i16>
joaosaffran wrote:
The DXIL checks only match `%{{.*}}`, so they don't verify dataflow. Can we
capture the values and check that each element is inserted into the right lane
and that the final vector is returned?
https://github.com/llvm/llvm-project/pull/228518
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.6-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-int16-type
-fnative-half-type -o - | \
+// RUN: FileCheck %s -check-prefix=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
spirv-pc-vulkan-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-int16-type
-fnative-half-type -o - | \
+// RUN: FileCheck %s -check-prefix=CHECK,CHECK-SPV
+
+// CHECK: define {{.*}} <4 x i16> @_Z10test_u8u16u15uint8_t4_packed
joaosaffran wrote:
I'd avoid matching the full mangled name here.
```suggestion
// CHECK-LABEL: define {{.*}} <4 x i16> {{.*}}test_u8u16
```
https://github.com/llvm/llvm-project/pull/228518
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
https://github.com/joaosaffran edited https://github.com/llvm/llvm-project/pull/228518 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
https://github.com/joaosaffran approved this pull request. The change looks correct to me. I've left some comments to improve tests. This patch fixes issues: https://github.com/llvm/llvm-project/issues/99223, https://github.com/llvm/llvm-project/issues/99226, https://github.com/llvm/llvm-project/issues/99224 and https://github.com/llvm/llvm-project/issues/99222 should be included in the patch summary. https://github.com/llvm/llvm-project/pull/228518 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-hlsl
Author: Alexander Johnston (Alexander-Johnston)
Changes
These HLSL intrinsics unpack a packed type (int8_t4_packed or uint8_t4_packed)
into an appropriate 4 element vector, as specified by the specific unpack
intrinsic used.
---
Patch is 33.35 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/228518.diff
25 Files Affected:
- (modified) clang/include/clang/Basic/Builtins.td (+24)
- (modified) clang/include/clang/Basic/HLSLIntrinsics.td (+24)
- (modified) clang/lib/CodeGen/CGHLSLBuiltins.cpp (+56)
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+4)
- (modified) clang/lib/Sema/SemaHLSL.cpp (+43)
- (added) clang/test/CodeGenHLSL/builtins/unpack_s8s16.hlsl (+21)
- (added) clang/test/CodeGenHLSL/builtins/unpack_s8s32.hlsl (+21)
- (added) clang/test/CodeGenHLSL/builtins/unpack_u8u16.hlsl (+21)
- (added) clang/test/CodeGenHLSL/builtins/unpack_u8u32.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_s8s16-errors.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_s8s32-errors.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_u8u16-errors.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_u8u32-errors.hlsl (+21)
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+5)
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+4)
- (modified) llvm/lib/Target/DirectX/DXIL.td (+35)
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+26)
- (added) llvm/test/CodeGen/DirectX/unpack_s8s16.ll (+18)
- (added) llvm/test/CodeGen/DirectX/unpack_s8s32.ll (+18)
- (added) llvm/test/CodeGen/DirectX/unpack_u8u16.ll (+18)
- (added) llvm/test/CodeGen/DirectX/unpack_u8u32.ll (+18)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_s8s16.ll (+17)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_s8s32.ll (+17)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_u8u16.ll (+17)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_u8u32.ll (+17)
``diff
diff --git a/clang/include/clang/Basic/Builtins.td
b/clang/include/clang/Basic/Builtins.td
index 7a59aaa133d522..319403c343c1f9 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -5973,6 +5973,30 @@ def HLSLDdyFine : LangBuiltin<"HLSL_LANG"> {
let Prototype = "void(...)";
}
+def HLSLUnpackU8U16 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_u8u16"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
+def HLSLUnpackU8U32 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_u8u32"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
+def HLSLUnpackS8S16 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_s8s16"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
+def HLSLUnpackS8S32 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_s8s32"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
// Builtins for XRay.
def XRayCustomEvent : Builtin {
let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td
b/clang/include/clang/Basic/HLSLIntrinsics.td
index 4be051476395cd..0a503ee766e972 100644
--- a/clang/include/clang/Basic/HLSLIntrinsics.td
+++ b/clang/include/clang/Basic/HLSLIntrinsics.td
@@ -1927,3 +1927,27 @@ let VaryingLongVector = 1;
let IsConvergent = 1;
let Availability = SM6_0;
}
+
+def hlsl_unpack_u8u16 : HLSLBuiltin<"unpack_u8u16",
"__builtin_hlsl_unpack_u8u16"> {
+ let Args = [UInt8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
+
+def hlsl_unpack_u8u32 : HLSLBuiltin<"unpack_u8u32",
"__builtin_hlsl_unpack_u8u32"> {
+ let Args = [UInt8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
+
+def hlsl_unpack_s8s16 : HLSLBuiltin<"unpack_s8s16",
"__builtin_hlsl_unpack_s8s16"> {
+ let Args = [Int8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
+
+def hlsl_unpack_s8s32 : HLSLBuiltin<"unpack_s8s32",
"__builtin_hlsl_unpack_s8s32"> {
+ let Args = [Int8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index 7ffadee3086a5c..158166214a52bb 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -416,6 +416,42 @@ static Value *handleInterlockedCompareOp(CodeGenFunction
&CGF,
return Original;
}
+static Value *handleHLSLUnpackOp(CodeGenFunction &CGF, const CallExpr *E,
+ unsigned BuiltinID, const Twine &Name,
+ const bool Short) {
+ Value *Op0 = CGF.EmitScalarExpr(E->getArg(0));
+ IntegerType *IntSizeType =
+ Short ? CGF.Builder.getInt16Ty() :
[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-llvm-ir
Author: Alexander Johnston (Alexander-Johnston)
Changes
These HLSL intrinsics unpack a packed type (int8_t4_packed or uint8_t4_packed)
into an appropriate 4 element vector, as specified by the specific unpack
intrinsic used.
---
Patch is 33.35 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/228518.diff
25 Files Affected:
- (modified) clang/include/clang/Basic/Builtins.td (+24)
- (modified) clang/include/clang/Basic/HLSLIntrinsics.td (+24)
- (modified) clang/lib/CodeGen/CGHLSLBuiltins.cpp (+56)
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+4)
- (modified) clang/lib/Sema/SemaHLSL.cpp (+43)
- (added) clang/test/CodeGenHLSL/builtins/unpack_s8s16.hlsl (+21)
- (added) clang/test/CodeGenHLSL/builtins/unpack_s8s32.hlsl (+21)
- (added) clang/test/CodeGenHLSL/builtins/unpack_u8u16.hlsl (+21)
- (added) clang/test/CodeGenHLSL/builtins/unpack_u8u32.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_s8s16-errors.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_s8s32-errors.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_u8u16-errors.hlsl (+21)
- (added) clang/test/SemaHLSL/BuiltIns/unpack_u8u32-errors.hlsl (+21)
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+5)
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+4)
- (modified) llvm/lib/Target/DirectX/DXIL.td (+35)
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+26)
- (added) llvm/test/CodeGen/DirectX/unpack_s8s16.ll (+18)
- (added) llvm/test/CodeGen/DirectX/unpack_s8s32.ll (+18)
- (added) llvm/test/CodeGen/DirectX/unpack_u8u16.ll (+18)
- (added) llvm/test/CodeGen/DirectX/unpack_u8u32.ll (+18)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_s8s16.ll (+17)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_s8s32.ll (+17)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_u8u16.ll (+17)
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_u8u32.ll (+17)
``diff
diff --git a/clang/include/clang/Basic/Builtins.td
b/clang/include/clang/Basic/Builtins.td
index 7a59aaa133d522..319403c343c1f9 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -5973,6 +5973,30 @@ def HLSLDdyFine : LangBuiltin<"HLSL_LANG"> {
let Prototype = "void(...)";
}
+def HLSLUnpackU8U16 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_u8u16"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
+def HLSLUnpackU8U32 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_u8u32"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
+def HLSLUnpackS8S16 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_s8s16"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
+def HLSLUnpackS8S32 : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_unpack_s8s32"];
+ let Attributes = [NoThrow, CustomTypeChecking];
+ let Prototype = "void(...)";
+}
+
// Builtins for XRay.
def XRayCustomEvent : Builtin {
let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td
b/clang/include/clang/Basic/HLSLIntrinsics.td
index 4be051476395cd..0a503ee766e972 100644
--- a/clang/include/clang/Basic/HLSLIntrinsics.td
+++ b/clang/include/clang/Basic/HLSLIntrinsics.td
@@ -1927,3 +1927,27 @@ let VaryingLongVector = 1;
let IsConvergent = 1;
let Availability = SM6_0;
}
+
+def hlsl_unpack_u8u16 : HLSLBuiltin<"unpack_u8u16",
"__builtin_hlsl_unpack_u8u16"> {
+ let Args = [UInt8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
+
+def hlsl_unpack_u8u32 : HLSLBuiltin<"unpack_u8u32",
"__builtin_hlsl_unpack_u8u32"> {
+ let Args = [UInt8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
+
+def hlsl_unpack_s8s16 : HLSLBuiltin<"unpack_s8s16",
"__builtin_hlsl_unpack_s8s16"> {
+ let Args = [Int8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
+
+def hlsl_unpack_s8s32 : HLSLBuiltin<"unpack_s8s32",
"__builtin_hlsl_unpack_s8s32"> {
+ let Args = [Int8PackedTy];
+ let ReturnType = VectorType;
+ let Availability = SM6_6;
+}
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index 7ffadee3086a5c..158166214a52bb 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -416,6 +416,42 @@ static Value *handleInterlockedCompareOp(CodeGenFunction
&CGF,
return Original;
}
+static Value *handleHLSLUnpackOp(CodeGenFunction &CGF, const CallExpr *E,
+ unsigned BuiltinID, const Twine &Name,
+ const bool Short) {
+ Value *Op0 = CGF.EmitScalarExpr(E->getArg(0));
+ IntegerType *IntSizeType =
+ Short ? CGF.Builder.getInt16Ty() :
[clang] [llvm] [HLSL] Add HLSL unpack intrinsics (PR #228518)
https://github.com/Alexander-Johnston created
https://github.com/llvm/llvm-project/pull/228518
These HLSL intrinsics unpack a packed type (int8_t4_packed or uint8_t4_packed)
into an appropriate 4 element vector, as specified by the specific unpack
intrinsic used.
>From b6b4e2e4bbe3101b219bc0aac760b03738ce5219 Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Fri, 2 Oct 2026 17:29:10 +0100
Subject: [PATCH 1/3] [DirectX] Add HLSL unpack intrinsics to DirectX backend
---
llvm/include/llvm/IR/IntrinsicsDirectX.td | 5
llvm/lib/Target/DirectX/DXIL.td | 35 +++
llvm/test/CodeGen/DirectX/unpack_s8s16.ll | 18
llvm/test/CodeGen/DirectX/unpack_s8s32.ll | 18
llvm/test/CodeGen/DirectX/unpack_u8u16.ll | 18
llvm/test/CodeGen/DirectX/unpack_u8u32.ll | 18
6 files changed, 112 insertions(+)
create mode 100644 llvm/test/CodeGen/DirectX/unpack_s8s16.ll
create mode 100644 llvm/test/CodeGen/DirectX/unpack_s8s32.ll
create mode 100644 llvm/test/CodeGen/DirectX/unpack_u8u16.ll
create mode 100644 llvm/test/CodeGen/DirectX/unpack_u8u32.ll
diff --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td
b/llvm/include/llvm/IR/IntrinsicsDirectX.td
index e087216b822da3..740e9b22a210ea 100644
--- a/llvm/include/llvm/IR/IntrinsicsDirectX.td
+++ b/llvm/include/llvm/IR/IntrinsicsDirectX.td
@@ -359,4 +359,9 @@ def int_dx_store_output
[llvm_i32_ty /*SigElementId*/, llvm_i32_ty /*RowIndex*/,
llvm_i8_ty /*ColIndex*/, llvm_any_ty /*Value*/],
[IntrConvergent]>;
+
+def int_dx_unpack_u8u16 : DefaultAttrsIntrinsic<[llvm_i16_ty, llvm_i16_ty,
llvm_i16_ty, llvm_i16_ty], [llvm_i32_ty], [IntrNoMem]>;
+def int_dx_unpack_u8u32 : DefaultAttrsIntrinsic<[llvm_i32_ty, llvm_i32_ty,
llvm_i32_ty, llvm_i32_ty], [llvm_i32_ty], [IntrNoMem]>;
+def int_dx_unpack_s8s16 : DefaultAttrsIntrinsic<[llvm_i16_ty, llvm_i16_ty,
llvm_i16_ty, llvm_i16_ty], [llvm_i32_ty], [IntrNoMem]>;
+def int_dx_unpack_s8s32 : DefaultAttrsIntrinsic<[llvm_i32_ty, llvm_i32_ty,
llvm_i32_ty, llvm_i32_ty], [llvm_i32_ty], [IntrNoMem]>;
}
diff --git a/llvm/lib/Target/DirectX/DXIL.td b/llvm/lib/Target/DirectX/DXIL.td
index 5e63e94a1c069a..ecc126ff7eff1f 100644
--- a/llvm/lib/Target/DirectX/DXIL.td
+++ b/llvm/lib/Target/DirectX/DXIL.td
@@ -329,6 +329,9 @@ defvar QuadOpKind_ReadAcrossX = 0;
defvar QuadOpKind_ReadAcrossY = 1;
defvar QuadOpKind_ReadAcrossDiagonal = 2;
+defvar Unpack_Unsigned = 0;
+defvar Unpack_Signed = 1;
+
// Intrinsic arg selection
class IntrinArgSelectType;
def IntrinArgSelect_Index : IntrinArgSelectType;
@@ -1560,3 +1563,35 @@ def CreateHandleFromHeap : DXILOp<218,
createHandleFromHeap> {
let stages = [Stages];
let attributes = [Attributes];
}
+
+def Unpack4x8 : DXILOp<219, unpack4x8> {
+ let Doc = "unpack 4 integer values from a single 32 bit value";
+ let intrinsics = [
+IntrinSelect,
+ IntrinArgIndex<0>
+ ]>,
+IntrinSelect,
+ IntrinArgIndex<0>
+ ]>,
+IntrinSelect,
+ IntrinArgIndex<0>
+ ]>,
+IntrinSelect,
+ IntrinArgIndex<0>
+ ]>,
+ ];
+
+ let arguments = [Int8Ty, Int32Ty];
+ let result = OverloadTy;
+ let overloads = [Overloads];
+ let stages = [Stages];
+ let attributes = [Attributes];
+}
diff --git a/llvm/test/CodeGen/DirectX/unpack_s8s16.ll
b/llvm/test/CodeGen/DirectX/unpack_s8s16.ll
new file mode 100644
index 00..d65db0c83faf50
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/unpack_s8s16.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.6-library %s |
FileCheck %s
+
+define noundef <4 x i16> @test_unpack_s8s16(i32 noundef %a) {
+ ; CHECK: %{{.*}} = call { i16, i16, i16, i16 } @dx.op.unpack4x8.i16(i32 219,
i8 1, i32 {{.*}})
+ %unpacked = call { i16, i16, i16, i16 } @llvm.dx.unpack.s8s16(i32 %a)
+ %1 = extractvalue { i16, i16, i16, i16 } %unpacked, 0
+ %2 = extractvalue { i16, i16, i16, i16 } %unpacked, 1
+ %3 = extractvalue { i16, i16, i16, i16 } %unpacked, 2
+ %4 = extractvalue { i16, i16, i16, i16 } %unpacked, 3
+ %5 = insertelement <4 x i16> poison, i16 %1, i32 0
+ %6 = insertelement <4 x i16> %5, i16 %2, i32 1
+ %7 = insertelement <4 x i16> %6, i16 %3, i32 2
+ %8 = insertelement <4 x i16> %7, i16 %4, i32 3
+ ret <4 x i16> %8
+}
+
+; CHECK-DAG: declare { i16, i16, i16, i16 } @dx.op.unpack4x8.i16(i32, i8, i32)
+declare { i16, i16, i16, i16 } @llvm.dx.unpack.s8s16(i32)
diff --git a/llvm/test/CodeGen/DirectX/unpack_s8s32.ll
b/llvm/test/CodeGen/DirectX/unpack_s8s32.ll
new file mode 100644
index 00..22d7736fa2a1d2
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/unpack_s8s32.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.6-library %s |
FileCheck %s
+
+define noundef <4 x i32> @test_unpack_s8s32(i32 noundef %a) {
+ ; CHECK: %{{.*}} = call { i32, i32, i32, i32 }
