Skip to content

Commit 2681497

Browse files
authored
[SPIRV] Allow multiple FuncParamAttr decoration on the same id. (llvm#166782)
According to SPIR-V spec: > It is invalid to decorate any given id or structure member more than one time with the same [decoration](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Decoration), unless explicitly allowed below for a specific decoration. `FuncParamAttr` explicitly allows multiple uses of the decoration on the same id, so this patch honors it.
1 parent 99a5e7b commit 2681497

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,18 @@ static InstrSignature instrToSignature(const MachineInstr &MI,
249249
InstrSignature Signature{MI.getOpcode()};
250250
for (unsigned i = 0; i < MI.getNumOperands(); ++i) {
251251
// The only decorations that can be applied more than once to a given <id>
252-
// or structure member are UserSemantic(5635), CacheControlLoadINTEL (6442),
253-
// and CacheControlStoreINTEL (6443). For all the rest of decorations, we
254-
// will only add to the signature the Opcode, the id to which it applies,
255-
// and the decoration id, disregarding any decoration flags. This will
256-
// ensure that any subsequent decoration with the same id will be deemed as
257-
// a duplicate. Then, at the call site, we will be able to handle duplicates
258-
// in the best way.
252+
// or structure member are FuncParamAttr (38), UserSemantic (5635),
253+
// CacheControlLoadINTEL (6442), and CacheControlStoreINTEL (6443). For all
254+
// the rest of decorations, we will only add to the signature the Opcode,
255+
// the id to which it applies, and the decoration id, disregarding any
256+
// decoration flags. This will ensure that any subsequent decoration with
257+
// the same id will be deemed as a duplicate. Then, at the call site, we
258+
// will be able to handle duplicates in the best way.
259259
unsigned Opcode = MI.getOpcode();
260260
if ((Opcode == SPIRV::OpDecorate) && i >= 2) {
261261
unsigned DecorationID = MI.getOperand(1).getImm();
262-
if (DecorationID != SPIRV::Decoration::UserSemantic &&
262+
if (DecorationID != SPIRV::Decoration::FuncParamAttr &&
263+
DecorationID != SPIRV::Decoration::UserSemantic &&
263264
DecorationID != SPIRV::Decoration::CacheControlLoadINTEL &&
264265
DecorationID != SPIRV::Decoration::CacheControlStoreINTEL)
265266
continue;

llvm/test/CodeGen/SPIRV/spirv_param_decorations_quals.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ entry:
77

88
; CHECK-SPIRV: OpDecorate %[[#PId:]] Volatile
99
; CHECK-SPIRV: OpDecorate %[[#PId]] FuncParamAttr NoAlias
10+
; CHECK-SPIRV: OpDecorate %[[#PId]] FuncParamAttr NoWrite
1011
; CHECK-SPIRV: %[[#PId]] = OpFunctionParameter %[[#]]
1112

1213
!7 = !{!"volatile"}
1314
!8 = !{i32 38, i32 4} ; FuncParamAttr NoAlias
14-
!9 = !{!8}
15+
!11 = !{i32 38, i32 6} ; FuncParamAttr NoWrite
16+
!9 = !{!8, !11}
1517
!10 = !{!9}

0 commit comments

Comments
 (0)