Skip to content

Commit 6f3663d

Browse files
committed
[Backport to 14] Fix crash on coopmat conversion without decoration (KhronosGroup#3190)
The SPIR-V reader would crash on the added test during reverse translation. Ensure any cooperative matrix type conversion is handled the same way as a cooperative matrix type conversion with an FPRoundingMode or SaturatedConversion decoration. (cherry picked from commit 32738f9)
1 parent c8897c9 commit 6f3663d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,8 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
28522852
if (isCvtOpCode(OC) && OC != OpGenericCastToPtrExplicit) {
28532853
auto BI = static_cast<SPIRVInstruction *>(BV);
28542854
Value *Inst = nullptr;
2855-
if (BI->hasFPRoundingMode() || BI->isSaturatedConversion())
2855+
if (BI->hasFPRoundingMode() || BI->isSaturatedConversion() ||
2856+
BI->getType()->isTypeCooperativeMatrixKHR())
28562857
Inst = transSPIRVBuiltinFromInst(BI, BB);
28572858
else
28582859
Inst = transConvertInst(BV, F, BB);

test/transcoding/SPV_KHR_cooperative_matrix/conversion_instructions.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ entry:
4242
ret void
4343
}
4444

45+
; CHECK-SPIRV: CompositeConstruct [[#MatrixTypeFloat]] [[#MatrixIn:]] [[#]] {{$}}
46+
; CHECK-SPIRV: ConvertFToU [[#MatrixTypeInt32]] [[#]] [[#MatrixIn]]
47+
48+
; CHECK-LLVM: %[[#Matrix:]] = call spir_func %spirv.CooperativeMatrixKHR._float_3_12_12_3 addrspace(1)* @_Z26__spirv_CompositeConstructf(float 0.000000e+00)
49+
; CHECK-LLVM: call spir_func %spirv.CooperativeMatrixKHR._int_3_12_12_3 addrspace(1)* @_Z72__spirv_ConvertFToU_RPU3AS143__spirv_CooperativeMatrixKHR__int_3_12_12_3PU3AS145__spirv_CooperativeMatrixKHR__float_3_12_12_3(%spirv.CooperativeMatrixKHR._float_3_12_12_3 addrspace(1)* %0)
50+
51+
define void @convert_f_to_u_no_fproundingmode() {
52+
entry:
53+
%0 = tail call spir_func noundef %spirv.CooperativeMatrixKHR._float_3_12_12_3 addrspace(1)* @_Z26__spirv_CompositeConstructFloat(float 0.000000e+00)
54+
%call = call spir_func %spirv.CooperativeMatrixKHR._int_3_12_12_3 addrspace(1)* @_Z73__spirv_ConvertFToU_RPU3AS144__spirv_CooperativeMatrixKHR__uint_3_12_12_2PU3AS145__spirv_CooperativeMatrixKHR__float_3_12_12_2(%spirv.CooperativeMatrixKHR._float_3_12_12_3 addrspace(1)* %0)
55+
ret void
56+
}
57+
4558
; CHECK-SPIRV: CompositeConstruct [[#MatrixTypeFloat]] [[#MatrixIn:]] [[#]] {{$}}
4659
; CHECK-SPIRV: ConvertFToS [[#MatrixTypeInt32]] [[#]] [[#MatrixIn]]
4760

@@ -132,6 +145,8 @@ declare spir_func noundef %spirv.CooperativeMatrixKHR._char_3_12_12_3 addrspace(
132145

133146
declare spir_func noundef %spirv.CooperativeMatrixKHR._int_3_12_12_3 addrspace(1)* @_Z76__spirv_ConvertFToU_RPU3AS143__spirv_CooperativeMatrixKHR__int_3_12_12_3_rtpPU3AS145__spirv_CooperativeMatrixKHR__float_3_12_12_3(%spirv.CooperativeMatrixKHR._float_3_12_12_3 addrspace(1)* noundef)
134147

148+
declare spir_func noundef %spirv.CooperativeMatrixKHR._int_3_12_12_3 addrspace(1)* @_Z73__spirv_ConvertFToU_RPU3AS144__spirv_CooperativeMatrixKHR__uint_3_12_12_2PU3AS145__spirv_CooperativeMatrixKHR__float_3_12_12_2(%spirv.CooperativeMatrixKHR._float_3_12_12_3 addrspace(1)* noundef)
149+
135150
declare spir_func noundef %spirv.CooperativeMatrixKHR._int_3_12_12_3 addrspace(1)* @_Z76__spirv_ConvertFToS_RPU3AS143__spirv_CooperativeMatrixKHR__int_3_12_12_3_rtpPU3AS145__spirv_CooperativeMatrixKHR__float_3_12_12_3(%spirv.CooperativeMatrixKHR._float_3_12_12_3 addrspace(1)* noundef)
136151

137152
declare spir_func noundef %spirv.CooperativeMatrixKHR._half_3_12_12_3 addrspace(1)* @_Z77__spirv_ConvertSToF_RPU3AS144__spirv_CooperativeMatrixKHR__half_3_12_12_3_rtpPU3AS145__spirv_CooperativeMatrixKHR__short_3_12_12_3(%spirv.CooperativeMatrixKHR._short_3_12_12_3 addrspace(1)* noundef)

0 commit comments

Comments
 (0)