Skip to content

Commit 8160c3b

Browse files
authored
[Backport to 15] Ignore UserSemantic decorations on BuiltIn variables (#2796)
UserSemantic decorations on BuiltIn variables would be added into `llvm.global.annotations`. During lowering of builtin variables to function calls, `replaceUsesOfBuiltinVar` would not know how to handle the annotation and crash. Right now there is no clear use case for UserSemantic decorations on BuiltIn variables, so just ignore the decoration and drop it during translation from SPIR-V to LLVM. Test-case-by: Ben Ashbaugh <ben.ashbaugh@intel.com> (cherry picked from commit 0317fa8)
1 parent 631bfc1 commit 8160c3b

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,6 +3786,11 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
37863786
Builder.CreateCall(AnnotationFn, Args);
37873787
}
37883788
} else if (auto *GV = dyn_cast<GlobalVariable>(V)) {
3789+
// Do not add annotations for builtin variables.
3790+
SPIRVBuiltinVariableKind Kind;
3791+
if (isSPIRVBuiltinVariable(GV, &Kind))
3792+
return;
3793+
37893794
SmallString<256> AnnotStr;
37903795
generateIntelFPGAAnnotation(BV, AnnotStr);
37913796

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; REQUIRES: spirv-as
2+
; RUN: spirv-as --target-env spv1.4 -o %t.spv %s
3+
; RUN: spirv-val %t.spv
4+
; RUN: llvm-spirv -r --spirv-target-env=CL2.0 %t.spv -o - | llvm-dis | FileCheck --check-prefix=CHECK-OCL %s
5+
; RUN: llvm-spirv -r --spirv-target-env=SPV-IR %t.spv -o - | llvm-dis | FileCheck --check-prefix=CHECK-SPV-IR %s
6+
7+
; Ensure that UserSemantic decorations on BuiltIn variables do not prevent successful translation.
8+
9+
; CHECK-OCL: call spir_func i64 @_Z13get_global_idj(i32 0)
10+
; CHECK-SPV-IR: call spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32 0)
11+
12+
OpCapability Addresses
13+
OpCapability Linkage
14+
OpCapability Kernel
15+
OpCapability Int64
16+
OpMemoryModel Physical64 OpenCL
17+
OpEntryPoint Kernel %usersemantic_test "usersemantic_test" %global_id
18+
OpDecorate %global_id LinkageAttributes "global_id" Import
19+
OpDecorate %global_id Constant
20+
OpDecorate %global_id BuiltIn GlobalInvocationId
21+
; Basic decoration:
22+
OpDecorateString %global_id UserSemantic "FOO"
23+
; Duplicate decorations are allowed as long as the string is different.
24+
OpDecorateString %global_id UserSemantic "BAR"
25+
; Try one more string with punctuation.
26+
OpDecorateString %global_id UserSemantic "FOO? BAR. BAZ!"
27+
%ulong = OpTypeInt 64 0
28+
%uint = OpTypeInt 32 0
29+
%v3ulong = OpTypeVector %ulong 3
30+
%_ptr_Input_v3ulong = OpTypePointer Input %v3ulong
31+
%void = OpTypeVoid
32+
%_ptr_CrossWorkgroup_uint = OpTypePointer CrossWorkgroup %uint
33+
%9 = OpTypeFunction %void %_ptr_CrossWorkgroup_uint
34+
%global_id = OpVariable %_ptr_Input_v3ulong Input
35+
%usersemantic_test = OpFunction %void None %9
36+
%dst = OpFunctionParameter %_ptr_CrossWorkgroup_uint
37+
%entry = OpLabel
38+
%index = OpLoad %v3ulong %global_id Aligned 32
39+
%call = OpCompositeExtract %ulong %index 0
40+
%conv = OpUConvert %uint %call
41+
%idxprom = OpSConvert %ulong %conv
42+
%arrayidx = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_uint %dst %idxprom
43+
OpStore %arrayidx %conv Aligned 4
44+
OpReturn
45+
OpFunctionEnd

0 commit comments

Comments
 (0)