Skip to content

Commit 2a70c50

Browse files
svenvhDmitry Sidorov
authored andcommitted
[Backport to 17] 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. (cherry picked from commit 9d56f01)
1 parent bc62bcb commit 2a70c50

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/SPIRV/SPIRVToOCL.cpp

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

651651
void SPIRVToOCLBase::visitCallSPIRVCvtBuiltin(CallInst *CI, Op OC,
652652
StringRef DemangledName) {
653+
if (auto *TET =
654+
dyn_cast<TargetExtType>(CI->getFunctionType()->getReturnType())) {
655+
// Preserve any cooperative matrix type conversions as SPIR-V calls.
656+
if (TET->getName() == "spirv.CooperativeMatrixKHR") {
657+
return;
658+
}
659+
}
653660
std::string CastBuiltInName;
654661
if (isCvtFromUnsignedOpCode(OC))
655662
CastBuiltInName = "u";

test/extensions/KHR/SPV_KHR_cooperative_matrix/conversion_instructions.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
77

88
; RUN: llvm-spirv -r --spirv-target-env=SPV-IR %t.spv -o %t.rev.bc
9-
; RUN: llvm-dis %t.rev.bc
9+
; RUN: llvm-dis %t.rev.bc
1010
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
1111

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

0 commit comments

Comments
 (0)