Skip to content

Commit b0cae0f

Browse files
committed
Fix parameter decoration metadata overwrite in entry-point wrapper
In the entry-point wrapper pattern two SPIR-V functions map to the same LLVM function; only one carries decorated parameters. transOCLMetadata unconditionally set spirv.ParameterDecorations for both, so the undecorated function could overwrite the decorated one's metadata. Skip the write when the current function has no decorations and metadata is already present. AI-assisted: Claude Sonnet 4.6 (commercial SaaS)
1 parent 300d5c5 commit b0cae0f

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

lib/SPIRV/SPIRVReader.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5087,12 +5087,20 @@ bool SPIRVToLLVM::transOCLMetadata(SPIRVFunction *BF) {
50875087
return ConstantAsMetadata::get(
50885088
ConstantInt::get(Type::getInt1Ty(*Context), 1));
50895089
});
5090-
// Generate metadata for spirv.ParameterDecorations
5091-
addKernelArgumentMetadata(Context, SPIRV_MD_PARAMETER_DECORATIONS, BF, F,
5092-
[=](SPIRVFunctionParameter *Arg) {
5093-
return transDecorationsToMetadataList(
5094-
Context, Arg->getDecorations());
5095-
});
5090+
// Generate metadata for spirv.ParameterDecorations.
5091+
// In the entry-point wrapper pattern two SPIR-V functions map to the same
5092+
// LLVM function; only one carries decorated parameters. Skip the
5093+
// undecorated function so it cannot overwrite the decorated one.
5094+
bool HasDecorations = false;
5095+
BF->foreachArgument([&](SPIRVFunctionParameter *Arg) {
5096+
HasDecorations |= Arg->getNumDecorations() > 0;
5097+
});
5098+
if (HasDecorations || !F->hasMetadata(SPIRV_MD_PARAMETER_DECORATIONS))
5099+
addKernelArgumentMetadata(Context, SPIRV_MD_PARAMETER_DECORATIONS, BF, F,
5100+
[=](SPIRVFunctionParameter *Arg) {
5101+
return transDecorationsToMetadataList(
5102+
Context, Arg->getDecorations());
5103+
});
50965104
return true;
50975105
}
50985106

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
; Verify that CacheControlLoadINTEL decoration on a FunctionParameter
2+
; survives reverse translation of the entry-point wrapper pattern.
3+
4+
; RUN: llvm-spirv -spirv-text --to-binary %s -o %t.spv
5+
; RUN: spirv-val %t.spv
6+
; RUN: llvm-spirv -spirv-text -r --spirv-target-env=SPV-IR %s -o - | llvm-dis | FileCheck %s --check-prefix=CHECK-LLVM
7+
8+
; CHECK-LLVM: spirv.ParameterDecorations ![[#ParamDecs:]]
9+
; CHECK-LLVM: ![[#ParamDecs]] = !{![[#FirstParam:]]}
10+
; CHECK-LLVM: ![[#FirstParam]] = !{![[#DecoNode:]]}
11+
; CHECK-LLVM: ![[#DecoNode]] = !{i32 6442, i32 0, i32 1}
12+
13+
119734787 66560 393230 14 0
14+
2 Capability Addresses
15+
2 Capability Linkage
16+
2 Capability Kernel
17+
2 Capability CacheControlsINTEL
18+
8 Extension "SPV_INTEL_cache_controls"
19+
5 ExtInstImport 1 "OpenCL.std"
20+
3 MemoryModel 2 2
21+
5 EntryPoint 6 9 "test"
22+
3 Source 4 100000
23+
4 TypeInt 2 32 0
24+
2 TypeVoid 3
25+
4 TypePointer 5 5 2
26+
4 TypeFunction 6 3 5
27+
6 Decorate 4 LinkageAttributes "test" Export
28+
5 Decorate 7 CacheControlLoadINTEL 0 1
29+
30+
5 Function 3 4 0 6
31+
3 FunctionParameter 5 7
32+
2 Label 8
33+
4 Load 2 13 7
34+
1 Return
35+
1 FunctionEnd
36+
37+
5 Function 3 9 0 6
38+
3 FunctionParameter 5 10
39+
2 Label 11
40+
5 FunctionCall 3 12 4 10
41+
1 Return
42+
1 FunctionEnd

0 commit comments

Comments
 (0)