Skip to content

Commit fd83727

Browse files
vmaksimojsji
authored andcommitted
Check if OpCooperativeMatrixLengthKHR operand is a type
Translate the operand as a type only when it is an `OpTypeCooperativeMatrixKHR`. This relaxation is needed to preserve backward compatibility, as earlier we translated operand as value, not a type. Original commit: KhronosGroup/SPIRV-LLVM-Translator@1eb5da241503e51
1 parent 15f9301 commit fd83727

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,9 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName,
36793679
Func->addFnAttr(Attribute::Convergent);
36803680
}
36813681
CallInst *Call;
3682-
if (OC == OpCooperativeMatrixLengthKHR) {
3682+
// TODO: Remove the check for matrix type once drivers are updated.
3683+
if (OC == OpCooperativeMatrixLengthKHR &&
3684+
Ops[0]->getOpCode() == OpTypeCooperativeMatrixKHR) {
36833685
// OpCooperativeMatrixLengthKHR needs special handling as its operand is
36843686
// a Type instead of a Value.
36853687
llvm::Type *MatTy = transType(reinterpret_cast<SPIRVType *>(Ops[0]));
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; This test is used to check that we do not break backward translation of `CooperativeMatrixLengthKHR`,
2+
; even in case when it was generated not specification conformant (as value, not type) in forward translation.
3+
4+
; RUN: llvm-spirv %s -to-binary -o %t.spv
5+
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o %t.ll
6+
; RUN: FileCheck %s --input-file %t.ll
7+
8+
; CHECK: call spir_func i32 @_Z34__spirv_CooperativeMatrixLengthKHRPU3AS144__spirv_CooperativeMatrixKHR__uint_3_12_48_0(target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0)
9+
10+
119734787 65536 393230 21 0
11+
2 Capability Addresses
12+
2 Capability Linkage
13+
2 Capability Kernel
14+
2 Capability Int64
15+
2 Capability GenericPointer
16+
2 Capability Int8
17+
2 Capability CooperativeMatrixKHR
18+
8 Extension "SPV_KHR_cooperative_matrix"
19+
5 ExtInstImport 1 "OpenCL.std"
20+
3 MemoryModel 2 2
21+
3 Source 0 0
22+
5 Name 7 "matr_mult"
23+
5 Name 8 "_arg_accA"
24+
4 Name 9 "_arg_K"
25+
4 Name 10 "entry"
26+
4 Name 12 "accA3"
27+
3 Name 19 "m2"
28+
3 Name 20 "len"
29+
30+
7 Decorate 7 LinkageAttributes "matr_mult" Export
31+
4 Decorate 8 Alignment 1
32+
4 TypeInt 3 8 0
33+
4 TypeInt 5 64 0
34+
4 TypeInt 13 32 0
35+
4 Constant 13 14 3
36+
4 Constant 13 15 12
37+
4 Constant 13 16 48
38+
4 Constant 13 17 0
39+
2 TypeVoid 2
40+
4 TypePointer 4 5 3
41+
5 TypeFunction 6 2 4 5
42+
4 TypePointer 11 8 3
43+
7 TypeCooperativeMatrixKHR 18 13 14 15 16 17
44+
45+
5 Function 2 7 0 6
46+
3 FunctionParameter 4 8
47+
3 FunctionParameter 5 9
48+
49+
2 Label 10
50+
4 PtrCastToGeneric 11 12 8
51+
7 CooperativeMatrixLoadKHR 18 19 12 17 9 1
52+
4 CooperativeMatrixLengthKHR 13 20 19
53+
1 Return
54+
55+
1 FunctionEnd
56+

0 commit comments

Comments
 (0)