Skip to content

Commit 1a7f142

Browse files
authored
Add validation of vloada_half instruction (#1138)
The instruction is for vector types and not for scalar types. It's a kind of a follow up for: KhronosGroup/OpenCL-CTS#1002 Signed-off-by: Dmitry Sidorov <dmitry.sidorov@intel.com>
1 parent ea7468e commit 1a7f142

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,8 @@ void SPIRVToOCLBase::visitCallSPIRVVLoadn(CallInst *CI, OCLExtOpKind Kind) {
982982
std::string Name = OCLExtOpMap::map(Kind);
983983
if (ConstantInt *C = dyn_cast<ConstantInt>(Args.back())) {
984984
uint64_t NumComponents = C->getZExtValue();
985+
assert(NumComponents > 1 &&
986+
"vloada_halfn instruction is not for scalar types");
985987
std::stringstream SS;
986988
SS << NumComponents;
987989
Name.replace(Name.find("n"), 1, SS.str());

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ bool LLVMToSPIRVBase::isBuiltinTransToExtInst(
209209
OCLExtOpKind EOC;
210210
if (!OCLExtOpMap::rfind(Splited.first.str(), &EOC))
211211
return false;
212+
if (EOC == OpenCLLIB::Vloada_halfn) {
213+
auto *VecTy = dyn_cast<VectorType>(F->getReturnType());
214+
if (!VecTy)
215+
BM->getErrorLog().checkError(
216+
false, SPIRVEC_InvalidModule,
217+
"vloada_half should be of a half vector type");
218+
auto *Ty = VecTy->getElementType();
219+
BM->getErrorLog().checkError(Ty->isHalfTy(), SPIRVEC_InvalidModule,
220+
"vloada_half should be of a half vector type");
221+
}
212222

213223
if (ExtSet)
214224
*ExtSet = Set;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: not llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
3+
4+
; CHECK: InvalidModule: Invalid SPIR-V module: vloada_half should be of a half vector type
5+
6+
; ModuleID = 'loada.bc'
7+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
8+
target triple = "spir64-unknown-unknown"
9+
10+
; Function Attrs: noinline nounwind
11+
define spir_kernel void @test(half %val, half addrspace(4)* %res) #0 {
12+
entry:
13+
%call1 = call spir_func float @_Z12vloada_half1mPU3AS4KDh(half %val, half addrspace(4)* %res) #1
14+
ret void
15+
}
16+
17+
; Function Attrs: nounwind
18+
declare spir_func float @_Z12vloada_half1mPU3AS4KDh(half, half addrspace(4)*) #1
19+
20+
attributes #0 = { noinline nounwind }
21+
attributes #1 = { nounwind }
22+
23+
!spirv.MemoryModel = !{!0}
24+
!opencl.enable.FP_CONTRACT = !{}
25+
!spirv.Source = !{!1}
26+
!opencl.spir.version = !{!2}
27+
!opencl.ocl.version = !{!3}
28+
!opencl.used.extensions = !{!4}
29+
!opencl.used.optional.core.features = !{!4}
30+
!spirv.Generator = !{!5}
31+
32+
!0 = !{i32 2, i32 2}
33+
!1 = !{i32 3, i32 300000}
34+
!2 = !{i32 2, i32 0}
35+
!3 = !{i32 3, i32 0}
36+
!4 = !{}
37+
!5 = !{i16 6, i16 14}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: not llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s
3+
4+
; CHECK: InvalidModule: Invalid SPIR-V module: vloada_half should be of a half vector type
5+
6+
; ModuleID = 'loada.bc'
7+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
8+
target triple = "spir64-unknown-unknown"
9+
10+
; Function Attrs: noinline nounwind
11+
define spir_kernel void @test(<2 x float> %val, half addrspace(4)* %res) #0 {
12+
entry:
13+
%call1 = call spir_func float @_Z12vloada_half1mPU3AS4KDh(<2 x float> %val, half addrspace(4)* %res) #1
14+
ret void
15+
}
16+
17+
; Function Attrs: nounwind
18+
declare spir_func float @_Z12vloada_half1mPU3AS4KDh(<2 x float>, half addrspace(4)*) #1
19+
20+
attributes #0 = { noinline nounwind }
21+
attributes #1 = { nounwind }
22+
23+
!spirv.MemoryModel = !{!0}
24+
!opencl.enable.FP_CONTRACT = !{}
25+
!spirv.Source = !{!1}
26+
!opencl.spir.version = !{!2}
27+
!opencl.ocl.version = !{!3}
28+
!opencl.used.extensions = !{!4}
29+
!opencl.used.optional.core.features = !{!4}
30+
!spirv.Generator = !{!5}
31+
32+
!0 = !{i32 2, i32 2}
33+
!1 = !{i32 3, i32 300000}
34+
!2 = !{i32 2, i32 0}
35+
!3 = !{i32 3, i32 0}
36+
!4 = !{}
37+
!5 = !{i16 6, i16 14}

0 commit comments

Comments
 (0)