[llvm] [SPIR-V] Fix inverted signed/unsigned opcode for int-to-int convert builtins (PR #200791)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 05:07:51 PDT 2026
https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/200791
None
>From 8b33967f9825a43b2f20f8c990d8d0e794e69dc6 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 1 Jun 2026 14:03:39 +0200
Subject: [PATCH] [SPIR-V] Fix inverted signed/unsigned opcode for int-to-int
convert builtins
---
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 4 ++--
.../SPIRV/transcoding/OpenCL/convert_functions.ll | 11 ++++++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index 1febfc21ed3b0..9fa72ae2f6f7f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -3158,8 +3158,8 @@ static bool generateConvertInst(const StringRef DemangledCall,
Opcode = Builtin->IsDestinationSigned ? SPIRV::OpSatConvertUToS
: SPIRV::OpSatConvertSToU;
else
- Opcode = Builtin->IsDestinationSigned ? SPIRV::OpUConvert
- : SPIRV::OpSConvert;
+ Opcode = Builtin->IsDestinationSigned ? SPIRV::OpSConvert
+ : SPIRV::OpUConvert;
} else if (GR->isScalarOrVectorOfType(Call->ReturnRegister,
SPIRV::OpTypeFloat)) {
// Int -> Float
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/OpenCL/convert_functions.ll b/llvm/test/CodeGen/SPIRV/transcoding/OpenCL/convert_functions.ll
index 13a61b08b75df..f2f05e235d200 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/OpenCL/convert_functions.ll
+++ b/llvm/test/CodeGen/SPIRV/transcoding/OpenCL/convert_functions.ll
@@ -10,10 +10,13 @@
; CHECK-SPIRV: OpName %[[#Func2:]] "_Z21convert_float_rtzfunc"
; CHECK-SPIRV-DAG: %[[#VoidTy:]] = OpTypeVoid
; CHECK-SPIRV-DAG: %[[#CharTy:]] = OpTypeInt 8
+; CHECK-SPIRV-DAG: %[[#LongTy:]] = OpTypeInt 64
; CHECK-SPIRV-DAG: %[[#FloatTy:]] = OpTypeFloat 32
; CHECK-SPIRV: %[[#Func]] = OpFunction %[[#VoidTy]] None %[[#]]
-; CHECK-SPIRV: %[[#ConvertId1:]] = OpUConvert %[[#CharTy]] %[[#]]
+; CHECK-SPIRV: %[[#ConvertId1:]] = OpSConvert %[[#CharTy]] %[[#]]
+; CHECK-SPIRV: %[[#]] = OpSConvert %[[#LongTy]] %[[#]]
+; CHECK-SPIRV: %[[#]] = OpUConvert %[[#LongTy]] %[[#]]
; CHECK-SPIRV: %[[#ConvertId2:]] = OpConvertSToF %[[#FloatTy]] %[[#]]
; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#VoidTy]] %[[#Func]] %[[#ConvertId2]]
; CHECK-SPIRV: %[[#]] = OpFunctionCall %[[#VoidTy]] %[[#Func1]] %[[#]]
@@ -44,6 +47,8 @@ entry:
store i32 %x, ptr %x.addr, align 4
%0 = load i32, ptr %x.addr, align 4
call spir_func signext i8 @_Z16convert_char_rtei(i32 noundef %0)
+ call spir_func i64 @_Z12convert_longi(i32 noundef %0)
+ call spir_func i64 @_Z13convert_ulongj(i32 noundef %0)
%call = call spir_func float @_Z13convert_floati(i32 noundef %0)
call spir_func void @_Z18convert_float_func(float noundef %call)
call spir_func void @_Z20convert_uint_satfunc(i32 noundef %0)
@@ -53,4 +58,8 @@ entry:
declare spir_func signext i8 @_Z16convert_char_rtei(i32 noundef)
+declare spir_func i64 @_Z12convert_longi(i32 noundef)
+
+declare spir_func i64 @_Z13convert_ulongj(i32 noundef)
+
declare spir_func float @_Z13convert_floati(i32 noundef)
More information about the llvm-commits
mailing list