[llvm] [SPIR-V] Add s128 to allPtrsScalarsAndVectors in legalizer (PR #199998)

Arseniy Obolenskiy via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 03:17:30 PDT 2026


https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/199998

>From a9528c6473d2d8437f450bba4d2215c31471a6d2 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Wed, 27 May 2026 16:52:04 +0200
Subject: [PATCH 1/3] [SPIR-V] Add s128 to allPtrsScalarsAndVectors in
 legalizer

Without this, i128 G_ICMP fails legalization before OpTypeInt can emit the diagnostic pointing at lack of SPV_ALTERA_arbitrary_precision_integers extension even though it is not supposed to be needed in that case
---
 llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp  |  6 ++--
 .../i128-icmp.ll                              | 32 +++++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll

diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
index dd48aa3ea2f0f..9e480fd2f32fd 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
@@ -103,9 +103,9 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
   auto allPtrsScalarsAndVectors = {
       p0,    p1,    p2,    p3,    p4,    p5,     p6,     p7,    p8,
       p9,    p10,   p11,   p12,   p13,   s1,     s8,     s16,   s32,
-      s64,   v2s1,  v2s8,  v2s16, v2s32, v2s64,  v3s1,   v3s8,  v3s16,
-      v3s32, v3s64, v4s1,  v4s8,  v4s16, v4s32,  v4s64,  v8s1,  v8s8,
-      v8s16, v8s32, v8s64, v16s1, v16s8, v16s16, v16s32, v16s64};
+      s64,   s128,  v2s1,  v2s8,  v2s16, v2s32,  v2s64,  v3s1,  v3s8,
+      v3s16, v3s32, v3s64, v4s1,  v4s8,  v4s16,  v4s32,  v4s64, v8s1,
+      v8s8,  v8s16, v8s32, v8s64, v16s1, v16s8,  v16s16, v16s32, v16s64};
 
   auto allVectors = {v2s1,  v2s8,   v2s16,  v2s32, v2s64, v3s1,  v3s8,
                      v3s16, v3s32,  v3s64,  v4s1,  v4s8,  v4s16, v4s32,
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll
new file mode 100644
index 0000000000000..aca31b695ab76
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll
@@ -0,0 +1,32 @@
+; RUN: not llc -O0 -mtriple=spirv64-unknown-unknown %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_ALTERA_arbitrary_precision_integers %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_ALTERA_arbitrary_precision_integers %s -o - -filetype=obj | spirv-val %}
+
+; Without the extension, i128 cannot be lowered: the diagnostic must come from
+; OpTypeInt emission, not a legalizer "unable to legalize G_ICMP" failure.
+
+; CHECK-ERROR: LLVM ERROR: OpTypeInt type with a width other than 8, 16, 32 or 64 bits requires the following SPIR-V extension: SPV_ALTERA_arbitrary_precision_integers
+
+; CHECK: OpCapability ArbitraryPrecisionIntegersALTERA
+; CHECK: OpExtension "SPV_ALTERA_arbitrary_precision_integers"
+; CHECK-DAG: %[[#BoolTy:]] = OpTypeBool
+; CHECK-DAG: %[[#Int128Ty:]] = OpTypeInt 128 0
+
+; CHECK: OpFunction
+; CHECK: %{{[0-9]+}} = OpSGreaterThan %[[#BoolTy]]
+; CHECK: %{{[0-9]+}} = OpIEqual %[[#BoolTy]]
+; CHECK: %{{[0-9]+}} = OpULessThan %[[#BoolTy]]
+define spir_func void @test_icmp_i128(i128 %a, i128 %b, ptr %out) {
+entry:
+  %sgt = icmp sgt i128 %a, %b
+  %eq = icmp eq i128 %a, %b
+  %ult = icmp ult i128 %a, %b
+  %t1 = zext i1 %sgt to i32
+  %t2 = zext i1 %eq to i32
+  %t3 = zext i1 %ult to i32
+  store i32 %t1, ptr %out
+  store i32 %t2, ptr %out
+  store i32 %t3, ptr %out
+  ret void
+}

>From 15b86d316226dcd9a823cde83121a8fbdbee1a38 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Wed, 27 May 2026 17:02:10 +0200
Subject: [PATCH 2/3] fmt

---
 llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
index 9e480fd2f32fd..099243acc8819 100644
--- a/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVLegalizerInfo.cpp
@@ -101,11 +101,11 @@ SPIRVLegalizerInfo::SPIRVLegalizerInfo(const SPIRVSubtarget &ST) {
 
   // TODO: remove copy-pasting here by using concatenation in some way.
   auto allPtrsScalarsAndVectors = {
-      p0,    p1,    p2,    p3,    p4,    p5,     p6,     p7,    p8,
-      p9,    p10,   p11,   p12,   p13,   s1,     s8,     s16,   s32,
-      s64,   s128,  v2s1,  v2s8,  v2s16, v2s32,  v2s64,  v3s1,  v3s8,
-      v3s16, v3s32, v3s64, v4s1,  v4s8,  v4s16,  v4s32,  v4s64, v8s1,
-      v8s8,  v8s16, v8s32, v8s64, v16s1, v16s8,  v16s16, v16s32, v16s64};
+      p0,    p1,    p2,    p3,    p4,    p5,    p6,     p7,     p8,
+      p9,    p10,   p11,   p12,   p13,   s1,    s8,     s16,    s32,
+      s64,   s128,  v2s1,  v2s8,  v2s16, v2s32, v2s64,  v3s1,   v3s8,
+      v3s16, v3s32, v3s64, v4s1,  v4s8,  v4s16, v4s32,  v4s64,  v8s1,
+      v8s8,  v8s16, v8s32, v8s64, v16s1, v16s8, v16s16, v16s32, v16s64};
 
   auto allVectors = {v2s1,  v2s8,   v2s16,  v2s32, v2s64, v3s1,  v3s8,
                      v3s16, v3s32,  v3s64,  v4s1,  v4s8,  v4s16, v4s32,

>From df6f55fa352d184709e305267347391b680ee5e7 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <gooddoog at student.su>
Date: Thu, 28 May 2026 12:17:20 +0200
Subject: [PATCH 3/3] Update
 llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll

Co-authored-by: Dmitry Sidorov <dsidorov at amd.com>
---
 .../SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll
index aca31b695ab76..38f01c9336275 100644
--- a/llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_ALTERA_arbitrary_precision_integers/i128-icmp.ll
@@ -14,9 +14,9 @@
 ; CHECK-DAG: %[[#Int128Ty:]] = OpTypeInt 128 0
 
 ; CHECK: OpFunction
-; CHECK: %{{[0-9]+}} = OpSGreaterThan %[[#BoolTy]]
-; CHECK: %{{[0-9]+}} = OpIEqual %[[#BoolTy]]
-; CHECK: %{{[0-9]+}} = OpULessThan %[[#BoolTy]]
+; CHECK: [[#]] = OpSGreaterThan %[[#BoolTy]]
+; CHECK: [[#]] = OpIEqual %[[#BoolTy]]
+; CHECK: [[#]] = OpULessThan %[[#BoolTy]]
 define spir_func void @test_icmp_i128(i128 %a, i128 %b, ptr %out) {
 entry:
   %sgt = icmp sgt i128 %a, %b



More information about the llvm-commits mailing list