diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index 832117e8d4..f52c25c2ec 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -3252,8 +3252,16 @@ Instruction *SPIRVToLLVM::transBuiltinFromInst(const std::string &FuncName, isSplitBarrierINTELOpCode(OC) || OC == OpControlBarrier) Func->addFnAttr(Attribute::Convergent); } - auto Call = - CallInst::Create(Func, transValue(Ops, BB->getParent(), BB), "", BB); + CallInst *Call; + 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(Ops[0])); + Call = CallInst::Create(Func, Constant::getNullValue(MatTy), "", BB); + } else { + Call = CallInst::Create(Func, transValue(Ops, BB->getParent(), BB), "", BB); + } setName(Call, BI); setAttrByCalledFunc(Call); SPIRVDBG(spvdbgs() << "[transInstToBuiltinCall] " << *BI << " -> "; diff --git a/lib/SPIRV/libSPIRV/SPIRVInstruction.cpp b/lib/SPIRV/libSPIRV/SPIRVInstruction.cpp index db6caf5995..f12bc18320 100644 --- a/lib/SPIRV/libSPIRV/SPIRVInstruction.cpp +++ b/lib/SPIRV/libSPIRV/SPIRVInstruction.cpp @@ -146,6 +146,8 @@ SPIRVInstruction::getOperandTypes(const std::vector &Ops) { SPIRVType *Ty = nullptr; if (I->getOpCode() == OpFunction) Ty = reinterpret_cast(I)->getFunctionType(); + else if (I->getOpCode() == OpTypeCooperativeMatrixKHR) + Ty = reinterpret_cast(I); else Ty = I->getType(); diff --git a/test/transcoding/SPV_KHR_cooperative_matrix/length.spvasm b/test/transcoding/SPV_KHR_cooperative_matrix/length.spvasm new file mode 100644 index 0000000000..db38a42576 --- /dev/null +++ b/test/transcoding/SPV_KHR_cooperative_matrix/length.spvasm @@ -0,0 +1,25 @@ +; RUN: spirv-as --target-env spv1.0 -o %t.spv %s +; RUN: spirv-val %t.spv +; RUN: llvm-spirv -r -o - %t.spv | llvm-dis | FileCheck %s + +OpCapability Addresses +OpCapability Kernel +OpCapability CooperativeMatrixKHR +OpExtension "SPV_KHR_cooperative_matrix" +OpMemoryModel Physical64 OpenCL +OpEntryPoint Kernel %1 "testCoopMat" +%void = OpTypeVoid +%float = OpTypeFloat 32 +%fnTy = OpTypeFunction %void +%uint = OpTypeInt 32 0 +%uint_3 = OpConstant %uint 3 +%uint_0 = OpConstant %uint 0 +%uint_8 = OpConstant %uint 8 +%matTy = OpTypeCooperativeMatrixKHR %float %uint_3 %uint_8 %uint_8 %uint_0 +%1 = OpFunction %void None %fnTy +%2 = OpLabel +%3 = OpCooperativeMatrixLengthKHR %uint %matTy +OpReturn +OpFunctionEnd + +; CHECK: call spir_func i32 @_Z34__spirv_CooperativeMatrixLengthKHRPU3AS143__spirv_CooperativeMatrixKHR__float_3_8_8_0(%spirv.CooperativeMatrixKHR._float_3_8_8_0 addrspace(1)* null)