Skip to content

Commit 9d56f01

Browse files
authored
Always emit coopmat conversions as SPIR-V friendly IR calls (#3398)
Map all cooperative matrix type conversions to SPIR-V friendly IR calls, regardless of the environment specified. In particular, do not attempt to map such conversions to the OpenCL `convert` builtin. The SPIR-V TargetExtType is already encoded in the function suffix, so the previous translation was an odd hybrid between OpenCL and SPIR-V friendly IR.
1 parent 8dceb11 commit 9d56f01

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,13 @@ void SPIRVToOCLBase::visitCallGenericCastToPtrExplicitBuiltIn(CallInst *CI,
676676

677677
void SPIRVToOCLBase::visitCallSPIRVCvtBuiltin(CallInst *CI, Op OC,
678678
StringRef DemangledName) {
679+
if (auto *TET =
680+
dyn_cast<TargetExtType>(CI->getFunctionType()->getReturnType())) {
681+
// Preserve any cooperative matrix type conversions as SPIR-V calls.
682+
if (TET->getName() == "spirv.CooperativeMatrixKHR") {
683+
return;
684+
}
685+
}
679686
std::string CastBuiltInName;
680687
if (isCvtFromUnsignedOpCode(OC))
681688
CastBuiltInName = "u";

test/extensions/KHR/SPV_KHR_cooperative_matrix/conversion_instructions.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
; RUN: llvm-dis %t.rev.bc
1818
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
1919

20+
; Ensure cooperative matrix conversions are mapped to SPIR-V friendly IR calls.
21+
; RUN: llvm-spirv -r --spirv-target-env=CL2.0 %t.spv -o %t.rev.bc
22+
; RUN: llvm-dis %t.rev.bc
23+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
24+
2025
; CHECK-SPIRV: TypeInt [[#TypeInt32:]] 32 0
2126
; CHECK-SPIRV: TypeInt [[#TypeInt16:]] 16 0
2227
; CHECK-SPIRV: TypeInt [[#TypeInt8:]] 8 0

0 commit comments

Comments
 (0)