Skip to content

Commit f59f24e

Browse files
authored
[Backport to 14] Check if OpCooperativeMatrixLengthKHR operand is a type (#3005)
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. This is a backport of #3011
1 parent c4302cd commit f59f24e

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3455,7 +3455,8 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName,
34553455
Func->addFnAttr(Attribute::Convergent);
34563456
}
34573457
CallInst *Call;
3458-
if (BI->getOpCode() == OpCooperativeMatrixLengthKHR) {
3458+
if (BI->getOpCode() == OpCooperativeMatrixLengthKHR &&
3459+
Ops[0]->getOpCode() == OpTypeCooperativeMatrixKHR) {
34593460
// OpCooperativeMatrixLengthKHR needs special handling as its operand is
34603461
// a Type instead of a Value.
34613462
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_CooperativeMatrixLengthKHRPU3AS143__spirv_CooperativeMatrixKHR__int_3_12_48_0(%spirv.CooperativeMatrixKHR._int_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)