[llvm] [SPIRV] Legalize extended integers for compare instructions. (PR #180254)
Faijul Amin via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 6 10:19:02 PST 2026
https://github.com/mdfaijul created https://github.com/llvm/llvm-project/pull/180254
Currently, legalization fails for integer (lower than 8 bit) comparison with extensions, for example, SPV_INTEL_int4. This PR extends integers for supported extensions.
>From 7e0ab9920d38253a38254f5e1c0e9cfc36c0dcd3 Mon Sep 17 00:00:00 2001
From: mdfaijul <md.faijul.amin at intel.com>
Date: Fri, 6 Feb 2026 09:11:08 -0800
Subject: [PATCH] Legalize extended integers on compare instructions.
---
llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp | 4 +++
.../SPIRV/legalization/icmp_extended_int.ll | 33 +++++++++++++++++++
2 files changed, 37 insertions(+)
create mode 100644 llvm/test/CodeGen/SPIRV/legalization/icmp_extended_int.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
index dc5906cfa9ceb..70a405cbd1c7e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
@@ -382,6 +382,10 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
.unsupportedIf(LegalityPredicates::any(
all(typeIs(0, p9), typeInSet(1, allPtrs), typeIsNot(1, p9)),
all(typeInSet(0, allPtrs), typeIsNot(0, p9), typeIs(1, p9))))
+ .legalIf([IsExtendedInts](const LegalityQuery &Query) {
+ const LLT Ty = Query.Types[1];
+ return IsExtendedInts && Ty.isValid() && !Ty.isPointerOrPointerVector();
+ })
.customIf(all(typeInSet(0, allBoolScalarsAndVectors),
typeInSet(1, allPtrsScalarsAndVectors)));
diff --git a/llvm/test/CodeGen/SPIRV/legalization/icmp_extended_int.ll b/llvm/test/CodeGen/SPIRV/legalization/icmp_extended_int.ll
new file mode 100644
index 0000000000000..774733ec599ea
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/legalization/icmp_extended_int.ll
@@ -0,0 +1,33 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_int4 %s -o - | FileCheck %s
+
+; CHECK: OpCapability Int4TypeINTEL
+; CHECK: OpExtension "SPV_INTEL_int4"
+
+; CHECK: %[[#i4:]] = OpTypeInt 4 0
+; CHECK: %[[#bool:]] = OpTypeBool
+; CHECK: %[[#scalar_func:]] = OpTypeFunction %[[#bool]] %[[#i4]] %[[#i4]]
+; CHECK: %[[#vec_i4:]] = OpTypeVector %[[#i4]] 4
+; CHECK: %[[#vec_bool:]] = OpTypeVector %[[#bool]] 4
+; CHECK: %[[#vector_func:]] = OpTypeFunction %[[#vec_bool]] %[[#vec_i4]] %[[#vec_i4]]
+
+; CHECK: %[[#test_scalar:]] = OpFunction %[[#bool]] None %[[#scalar_func]]
+; CHECK: %[[#scalar_a:]] = OpFunctionParameter %[[#i4]]
+; CHECK: %[[#scalar_b:]] = OpFunctionParameter %[[#i4]]
+define spir_func i1 @test_scalar(i4 %a, i4 %b) {
+entry:
+; CHECK: %[[#scalar_entry:]] = OpLabel
+ %res1 = icmp eq i4 %a, %b
+; CHECK: %[[#scalar_cmp:]] = OpIEqual %[[#bool]] %[[#scalar_a]] %[[#scalar_b]]
+ ret i1 %res1
+}
+
+; CHECK: %[[#test_vector:]] = OpFunction %[[#vec_bool]] None %[[#vector_func]]
+; CHECK: %[[#vector_a:]] = OpFunctionParameter %[[#vec_i4]]
+; CHECK: %[[#vector_b:]] = OpFunctionParameter %[[#vec_i4]]
+define spir_func <4 x i1> @test_vector(<4 x i4> %a, <4 x i4> %b) {
+entry:
+; CHECK: %[[#vector_entry:]] = OpLabel
+ %res2 = icmp eq <4 x i4> %a, %b
+; CHECK: %[[#vector_cmp:]] = OpIEqual %[[#vec_bool]] %[[#vector_a]] %[[#vector_b]]
+ ret <4 x i1> %res2
+}
More information about the llvm-commits
mailing list