[llvm] 335d5d5 - [SPIRV] Tweak parsing of base type name in builtins (#88255)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 10:04:35 PDT 2024
Author: Vyacheslav Levytskyy
Date: 2024-04-10T19:04:31+02:00
New Revision: 335d5d5f47b883055e676ffe5f981469a5f5f4f6
URL: https://github.com/llvm/llvm-project/commit/335d5d5f47b883055e676ffe5f981469a5f5f4f6
DIFF: https://github.com/llvm/llvm-project/commit/335d5d5f47b883055e676ffe5f981469a5f5f4f6.diff
LOG: [SPIRV] Tweak parsing of base type name in builtins (#88255)
This PR is a small improvement of parsing of base type name in builtins,
allowing to understand `unsigned ...` types. The test case that fails
without the fix is attached.
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVUtils.cpp
llvm/test/CodeGen/SPIRV/SampledImageRetType.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index c87c1293c622fc..299a4341193bfd 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -374,13 +374,21 @@ Type *parseBasicTypeName(StringRef TypeName, LLVMContext &Ctx) {
return Type::getVoidTy(Ctx);
else if (TypeName.consume_front("bool"))
return Type::getIntNTy(Ctx, 1);
- else if (TypeName.consume_front("char") || TypeName.consume_front("uchar"))
+ else if (TypeName.consume_front("char") ||
+ TypeName.consume_front("unsigned char") ||
+ TypeName.consume_front("uchar"))
return Type::getInt8Ty(Ctx);
- else if (TypeName.consume_front("short") || TypeName.consume_front("ushort"))
+ else if (TypeName.consume_front("short") ||
+ TypeName.consume_front("unsigned short") ||
+ TypeName.consume_front("ushort"))
return Type::getInt16Ty(Ctx);
- else if (TypeName.consume_front("int") || TypeName.consume_front("uint"))
+ else if (TypeName.consume_front("int") ||
+ TypeName.consume_front("unsigned int") ||
+ TypeName.consume_front("uint"))
return Type::getInt32Ty(Ctx);
- else if (TypeName.consume_front("long") || TypeName.consume_front("ulong"))
+ else if (TypeName.consume_front("long") ||
+ TypeName.consume_front("unsigned long") ||
+ TypeName.consume_front("ulong"))
return Type::getInt64Ty(Ctx);
else if (TypeName.consume_front("half"))
return Type::getHalfTy(Ctx);
diff --git a/llvm/test/CodeGen/SPIRV/SampledImageRetType.ll b/llvm/test/CodeGen/SPIRV/SampledImageRetType.ll
index 1aa3af83bcd207..7af5876a023e5b 100644
--- a/llvm/test/CodeGen/SPIRV/SampledImageRetType.ll
+++ b/llvm/test/CodeGen/SPIRV/SampledImageRetType.ll
@@ -8,6 +8,8 @@ declare dso_local spir_func ptr addrspace(4) @_Z20__spirv_SampledImageI14ocl_ima
declare dso_local spir_func <4 x float> @_Z30__spirv_ImageSampleExplicitLodIPvDv4_fiET0_T_T1_if(ptr addrspace(4) %0, i32 %1, i32 %2, float %3) local_unnamed_addr
+declare dso_local spir_func <4 x i32> @_Z30__spirv_ImageSampleExplicitLodI32__spirv_SampledImage__image1d_roDv4_jfET0_T_T1_if(target("spirv.SampledImage", void, 0, 0, 0, 0, 0, 0, 0) %0, float %1, i32 %2, float %3) local_unnamed_addr
+
@__spirv_BuiltInGlobalInvocationId = external dso_local local_unnamed_addr addrspace(2) constant <3 x i64>, align 32
define weak_odr dso_local spir_kernel void @_ZTS17image_kernel_readILi1EE(target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 0), target("spirv.Sampler")) {
@@ -25,3 +27,10 @@ define weak_odr dso_local spir_kernel void @_ZTS17image_kernel_readILi1EE(target
ret void
}
+
+define weak_odr dso_local spir_kernel void @foo_lod(target("spirv.SampledImage", void, 0, 0, 0, 0, 0, 0, 0) %_arg) {
+ %lod = call spir_func <4 x i32> @_Z30__spirv_ImageSampleExplicitLodI32__spirv_SampledImage__image1d_roDv4_jfET0_T_T1_if(target("spirv.SampledImage", void, 0, 0, 0, 0, 0, 0, 0) %_arg, float 0x3FE7FFEB00000000, i32 2, float 0.000000e+00)
+; CHECK: %[[#sampled_image_lod:]] = OpFunctionParameter %[[#sampled_image_t]]
+; CHECK: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#sampled_image_lod]] %[[#]] {{.*}} %[[#]]
+ ret void
+}
More information about the llvm-commits
mailing list