Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport to 14] Check if OpCooperativeMatrixLengthKHR operand is a type #3005

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3455,7 +3455,8 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName,
Func->addFnAttr(Attribute::Convergent);
}
CallInst *Call;
if (BI->getOpCode() == OpCooperativeMatrixLengthKHR) {
if (BI->getOpCode() == OpCooperativeMatrixLengthKHR &&
Ops[0]->getOpCode() == OpTypeCooperativeMatrixKHR) {
// OpCooperativeMatrixLengthKHR needs special handling as its operand is
// a Type instead of a Value.
llvm::Type *MatTy = transType(reinterpret_cast<SPIRVType *>(Ops[0]));
Expand Down
56 changes: 56 additions & 0 deletions test/transcoding/SPV_KHR_cooperative_matrix/length_legacy.spt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
; This test is used to check that we do not break backward translation of `CooperativeMatrixLengthKHR`,
; even in case when it was generated not specification conformant (as value, not type) in forward translation.

; RUN: llvm-spirv %s -to-binary -o %t.spv
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o %t.ll
; RUN: FileCheck %s --input-file %t.ll

; CHECK: call spir_func i32 @_Z34__spirv_CooperativeMatrixLengthKHRPU3AS143__spirv_CooperativeMatrixKHR__int_3_12_48_0(%spirv.CooperativeMatrixKHR._int_3_12_48_0

119734787 65536 393230 21 0
2 Capability Addresses
2 Capability Linkage
2 Capability Kernel
2 Capability Int64
2 Capability GenericPointer
2 Capability Int8
2 Capability CooperativeMatrixKHR
8 Extension "SPV_KHR_cooperative_matrix"
5 ExtInstImport 1 "OpenCL.std"
3 MemoryModel 2 2
3 Source 0 0
5 Name 7 "matr_mult"
5 Name 8 "_arg_accA"
4 Name 9 "_arg_K"
4 Name 10 "entry"
4 Name 12 "accA3"
3 Name 19 "m2"
3 Name 20 "len"

7 Decorate 7 LinkageAttributes "matr_mult" Export
4 Decorate 8 Alignment 1
4 TypeInt 3 8 0
4 TypeInt 5 64 0
4 TypeInt 13 32 0
4 Constant 13 14 3
4 Constant 13 15 12
4 Constant 13 16 48
4 Constant 13 17 0
2 TypeVoid 2
4 TypePointer 4 5 3
5 TypeFunction 6 2 4 5
4 TypePointer 11 8 3
7 TypeCooperativeMatrixKHR 18 13 14 15 16 17

5 Function 2 7 0 6
3 FunctionParameter 4 8
3 FunctionParameter 5 9

2 Label 10
4 PtrCastToGeneric 11 12 8
7 CooperativeMatrixLoadKHR 18 19 12 17 9 1
4 CooperativeMatrixLengthKHR 13 20 19
1 Return

1 FunctionEnd

Loading