Skip to content

Commit 335d5d5

Browse files
[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.
1 parent 798e04f commit 335d5d5

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

llvm/lib/Target/SPIRV/SPIRVUtils.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,21 @@ Type *parseBasicTypeName(StringRef TypeName, LLVMContext &Ctx) {
374374
return Type::getVoidTy(Ctx);
375375
else if (TypeName.consume_front("bool"))
376376
return Type::getIntNTy(Ctx, 1);
377-
else if (TypeName.consume_front("char") || TypeName.consume_front("uchar"))
377+
else if (TypeName.consume_front("char") ||
378+
TypeName.consume_front("unsigned char") ||
379+
TypeName.consume_front("uchar"))
378380
return Type::getInt8Ty(Ctx);
379-
else if (TypeName.consume_front("short") || TypeName.consume_front("ushort"))
381+
else if (TypeName.consume_front("short") ||
382+
TypeName.consume_front("unsigned short") ||
383+
TypeName.consume_front("ushort"))
380384
return Type::getInt16Ty(Ctx);
381-
else if (TypeName.consume_front("int") || TypeName.consume_front("uint"))
385+
else if (TypeName.consume_front("int") ||
386+
TypeName.consume_front("unsigned int") ||
387+
TypeName.consume_front("uint"))
382388
return Type::getInt32Ty(Ctx);
383-
else if (TypeName.consume_front("long") || TypeName.consume_front("ulong"))
389+
else if (TypeName.consume_front("long") ||
390+
TypeName.consume_front("unsigned long") ||
391+
TypeName.consume_front("ulong"))
384392
return Type::getInt64Ty(Ctx);
385393
else if (TypeName.consume_front("half"))
386394
return Type::getHalfTy(Ctx);

llvm/test/CodeGen/SPIRV/SampledImageRetType.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ declare dso_local spir_func ptr addrspace(4) @_Z20__spirv_SampledImageI14ocl_ima
88

99
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
1010

11+
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
12+
1113
@__spirv_BuiltInGlobalInvocationId = external dso_local local_unnamed_addr addrspace(2) constant <3 x i64>, align 32
1214

1315
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
2527

2628
ret void
2729
}
30+
31+
define weak_odr dso_local spir_kernel void @foo_lod(target("spirv.SampledImage", void, 0, 0, 0, 0, 0, 0, 0) %_arg) {
32+
%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)
33+
; CHECK: %[[#sampled_image_lod:]] = OpFunctionParameter %[[#sampled_image_t]]
34+
; CHECK: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#sampled_image_lod]] %[[#]] {{.*}} %[[#]]
35+
ret void
36+
}

0 commit comments

Comments
 (0)