Skip to content

Commit 9367883

Browse files
authored
[Backport to 19] Always emit coopmat conversions as SPIR-V friendly IR calls (KhronosGroup#3439)
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. (cherry picked from commit 9d56f01)
1 parent c72352f commit 9367883

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
@@ -656,6 +656,13 @@ void SPIRVToOCLBase::visitCallGenericCastToPtrExplicitBuiltIn(CallInst *CI,
656656

657657
void SPIRVToOCLBase::visitCallSPIRVCvtBuiltin(CallInst *CI, Op OC,
658658
StringRef DemangledName) {
659+
if (auto *TET =
660+
dyn_cast<TargetExtType>(CI->getFunctionType()->getReturnType())) {
661+
// Preserve any cooperative matrix type conversions as SPIR-V calls.
662+
if (TET->getName() == "spirv.CooperativeMatrixKHR") {
663+
return;
664+
}
665+
}
659666
std::string CastBuiltInName;
660667
if (isCvtFromUnsignedOpCode(OC))
661668
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
@@ -8,6 +8,11 @@
88
; RUN: llvm-dis %t.rev.bc
99
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
1010

11+
; Ensure cooperative matrix conversions are mapped to SPIR-V friendly IR calls.
12+
; RUN: llvm-spirv -r --spirv-target-env=CL2.0 %t.spv -o %t.rev.bc
13+
; RUN: llvm-dis %t.rev.bc
14+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
15+
1116
; CHECK-SPIRV: TypeInt [[#TypeInt32:]] 32 0
1217
; CHECK-SPIRV: TypeInt [[#TypeInt16:]] 16 0
1318
; CHECK-SPIRV: TypeInt [[#TypeInt8:]] 8 0

0 commit comments

Comments
 (0)