Skip to content

Commit c7b3545

Browse files
vmaksimosys-ce-bb
authored andcommitted
Fix TaskSequenceCreateINTEL instruction verification (#2384)
This patch fixes verification of Get/Async Capacity literals making translator accept zero values which are valid by spec. Original commit: KhronosGroup/SPIRV-LLVM-Translator@22f9e3e67b36b36
1 parent 89b4bc9 commit c7b3545

File tree

4 files changed

+198
-6
lines changed

4 files changed

+198
-6
lines changed

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,21 +3904,21 @@ class SPIRVTaskSequenceCreateINTELInst : public SPIRVTaskSequenceINTELInst {
39043904
ClusterMode >= -1 && ClusterMode <= 1, SPIRVEC_InvalidInstruction,
39053905
InstName + "\nClusterMode valid values are -1, 0, 1.\n");
39063906

3907-
const uint32_t GetCapacity =
3907+
const int GetCapacity =
39083908
static_cast<SPIRVConstant *>(
39093909
const_cast<SPIRVTaskSequenceCreateINTELInst *>(this)->getOperand(3))
39103910
->getZExtIntValue();
39113911
SPVErrLog.checkError(
3912-
GetCapacity, SPIRVEC_InvalidInstruction,
3913-
InstName + "\nGetCapacity must be unsigned 32 bit integer.\n");
3912+
GetCapacity >= 0, SPIRVEC_InvalidInstruction,
3913+
InstName + "\nGetCapacity must be an unsigned 32-bit integer.\n");
39143914

3915-
const uint32_t AsyncCapacity =
3915+
const int AsyncCapacity =
39163916
static_cast<SPIRVConstant *>(
39173917
const_cast<SPIRVTaskSequenceCreateINTELInst *>(this)->getOperand(4))
39183918
->getZExtIntValue();
39193919
SPVErrLog.checkError(
3920-
AsyncCapacity, SPIRVEC_InvalidInstruction,
3921-
InstName + "\nAsyncCapacity must be unsigned 32 bit integer.\n");
3920+
AsyncCapacity >= 0, SPIRVEC_InvalidInstruction,
3921+
InstName + "\nAsyncCapacity must be an unsigned 32-bit integer.\n");
39223922
}
39233923
};
39243924

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: not llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence 2>&1 \
3+
; RUN: | FileCheck %s --check-prefix=CHECK-ERROR
4+
5+
; CHECK-ERROR: InvalidInstruction: Can't translate llvm instruction:
6+
; CHECK-ERROR-NEXT: TaskSequenceCreateINTEL
7+
; CHECK-ERROR-NEXT: AsyncCapacity must be an unsigned 32-bit integer
8+
9+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
10+
target triple = "spir64-unknown-unknown"
11+
12+
%"class.task_sequence" = type { target("spirv.TaskSequenceINTEL") }
13+
14+
$_ZTS8MyKernel = comdat any
15+
16+
; Function Attrs: convergent mustprogress norecurse nounwind
17+
define weak_odr dso_local spir_kernel void @_ZTS8MyKernel(ptr addrspace(1) noundef align 4 %_arg_in, ptr addrspace(1) noundef align 4 %_arg_res) local_unnamed_addr #0 comdat !srcloc !5 !kernel_arg_buffer_location !6 !sycl_fixed_targets !7 !sycl_kernel_omit_args !8 !stall_enable !9 {
18+
entry:
19+
%myMultTask.i = alloca %"class.task_sequence", align 8
20+
store i32 0, ptr %myMultTask.i, align 8
21+
%call.i1 = call spir_func noundef target("spirv.TaskSequenceINTEL") @_Z31__spirv_TaskSequenceCreateINTEL(ptr noundef nonnull @_Z4multii, i32 noundef 10, i32 noundef -1, i32 noundef 17, i32 noundef zeroext -1) #3
22+
%id.i = getelementptr inbounds %"class.task_sequence", ptr %myMultTask.i, i64 0, i32 0
23+
store target("spirv.TaskSequenceINTEL") %call.i1, ptr %id.i, align 8
24+
ret void
25+
}
26+
27+
; Function Attrs: mustprogress norecurse nounwind
28+
define linkonce_odr dso_local spir_func noundef i32 @_Z4multii(i32 noundef %a, i32 noundef %b) #1 !srcloc !10 {
29+
entry:
30+
%mul = mul nsw i32 %a, %b
31+
ret i32 %mul
32+
}
33+
34+
; Function Attrs: convergent nounwind
35+
declare dso_local spir_func noundef target("spirv.TaskSequenceINTEL") @_Z31__spirv_TaskSequenceCreateINTEL(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef zeroext) local_unnamed_addr #2
36+
37+
attributes #0 = { convergent mustprogress norecurse nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-fpga-cluster"="1" "sycl-module-id"="test.cpp" "sycl-optlevel"="2" "sycl-single-task" "uniform-work-group-size"="true" }
38+
attributes #1 = { mustprogress norecurse nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-optlevel"="2" }
39+
attributes #2 = { convergent nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
40+
attributes #3 = { convergent nounwind }
41+
42+
!opencl.spir.version = !{!0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0}
43+
!spirv.Source = !{!1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1}
44+
!llvm.ident = !{!2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2}
45+
!llvm.module.flags = !{!3, !4}
46+
!sycl.specialization-constants = !{}
47+
!sycl.specialization-constants-default-values = !{}
48+
49+
!0 = !{i32 1, i32 2}
50+
!1 = !{i32 4, i32 100000}
51+
!2 = !{!"clang version 18.0.0git (https://github.com/bowenxue-intel/llvm.git bb1121cb47589e94ab65b81971a298b9d2c21ff6)"}
52+
!3 = !{i32 1, !"wchar_size", i32 4}
53+
!4 = !{i32 7, !"frame-pointer", i32 2}
54+
!5 = !{i32 5445863}
55+
!6 = !{i32 -1, i32 -1}
56+
!7 = !{}
57+
!8 = !{i1 false, i1 false}
58+
!9 = !{i1 true}
59+
!10 = !{i32 5445350}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: not llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence 2>&1 \
3+
; RUN: | FileCheck %s --check-prefix=CHECK-ERROR
4+
5+
; CHECK-ERROR: InvalidInstruction: Can't translate llvm instruction:
6+
; CHECK-ERROR-NEXT: TaskSequenceCreateINTEL
7+
; CHECK-ERROR-NEXT: GetCapacity must be an unsigned 32-bit integer.
8+
9+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
10+
target triple = "spir64-unknown-unknown"
11+
12+
%"class.task_sequence" = type { target("spirv.TaskSequenceINTEL") }
13+
14+
$_ZTS8MyKernel = comdat any
15+
16+
; Function Attrs: convergent mustprogress norecurse nounwind
17+
define weak_odr dso_local spir_kernel void @_ZTS8MyKernel(ptr addrspace(1) noundef align 4 %_arg_in, ptr addrspace(1) noundef align 4 %_arg_res) local_unnamed_addr #0 comdat !srcloc !5 !kernel_arg_buffer_location !6 !sycl_fixed_targets !7 !sycl_kernel_omit_args !8 !stall_enable !9 {
18+
entry:
19+
%myMultTask.i = alloca %"class.task_sequence", align 8
20+
store i32 0, ptr %myMultTask.i, align 8
21+
%call.i1 = call spir_func noundef target("spirv.TaskSequenceINTEL") @_Z31__spirv_TaskSequenceCreateINTEL(ptr noundef nonnull @_Z4multii, i32 noundef 10, i32 noundef -1, i32 noundef -1, i16 noundef zeroext 1) #3
22+
%id.i = getelementptr inbounds %"class.task_sequence", ptr %myMultTask.i, i64 0, i32 0
23+
store target("spirv.TaskSequenceINTEL") %call.i1, ptr %id.i, align 8
24+
ret void
25+
}
26+
27+
; Function Attrs: mustprogress norecurse nounwind
28+
define linkonce_odr dso_local spir_func noundef i32 @_Z4multii(i32 noundef %a, i32 noundef %b) #1 !srcloc !10 {
29+
entry:
30+
%mul = mul nsw i32 %a, %b
31+
ret i32 %mul
32+
}
33+
34+
; Function Attrs: convergent nounwind
35+
declare dso_local spir_func noundef target("spirv.TaskSequenceINTEL") @_Z31__spirv_TaskSequenceCreateINTEL(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #2
36+
37+
attributes #0 = { convergent mustprogress norecurse nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-fpga-cluster"="1" "sycl-module-id"="test.cpp" "sycl-optlevel"="2" "sycl-single-task" "uniform-work-group-size"="true" }
38+
attributes #1 = { mustprogress norecurse nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-optlevel"="2" }
39+
attributes #2 = { convergent nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
40+
attributes #3 = { convergent nounwind }
41+
42+
!opencl.spir.version = !{!0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0}
43+
!spirv.Source = !{!1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1}
44+
!llvm.ident = !{!2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2}
45+
!llvm.module.flags = !{!3, !4}
46+
!sycl.specialization-constants = !{}
47+
!sycl.specialization-constants-default-values = !{}
48+
49+
!0 = !{i32 1, i32 2}
50+
!1 = !{i32 4, i32 100000}
51+
!2 = !{!"clang version 18.0.0git (https://github.com/bowenxue-intel/llvm.git bb1121cb47589e94ab65b81971a298b9d2c21ff6)"}
52+
!3 = !{i32 1, !"wchar_size", i32 4}
53+
!4 = !{i32 7, !"frame-pointer", i32 2}
54+
!5 = !{i32 5445863}
55+
!6 = !{i32 -1, i32 -1}
56+
!7 = !{}
57+
!8 = !{i1 false, i1 false}
58+
!9 = !{i1 true}
59+
!10 = !{i32 5445350}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_task_sequence -o %t.spv
3+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
4+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
5+
6+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
7+
; RUN: llvm-dis %t.rev.bc
8+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
9+
10+
; CHECK-SPIRV: TypeInt [[#IntTy:]] 32 0
11+
; CHECK-SPIRV: TypeTaskSequenceINTEL [[#TypeTS:]]
12+
; CHECK-SPIRV: TypeFunction [[#FuncTy:]] [[#IntTy]] [[#IntTy]] [[#IntTy]]
13+
; CHECK-SPIRV: TypePointer [[#PtrTS:]] 7 [[#TypeTS]]
14+
15+
; <id> Result Type <id> Result <id> Function Literal Pipelined Literal UseStallEnableClusters Literal GetCapacity Literal AsyncCapacity
16+
; CHECK-SPIRV: TaskSequenceCreateINTEL [[#TypeTS]] [[#CreateRes:]] [[#FuncId:]] 10 4294967295 0 0
17+
; CHECK-SPIRV: InBoundsPtrAccessChain [[#PtrTS]] [[#GEP:]]
18+
; CHECK-SPIRV: Store [[#GEP]] [[#CreateRes]]
19+
20+
; CHECK-SPIRV: Function [[#IntTy]] [[#FuncId]] 0 [[#FuncTy]]
21+
22+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
23+
target triple = "spir64-unknown-unknown"
24+
25+
%"class.task_sequence" = type { target("spirv.TaskSequenceINTEL") }
26+
27+
$_ZTS8MyKernel = comdat any
28+
29+
; Function Attrs: convergent mustprogress norecurse nounwind
30+
define weak_odr dso_local spir_kernel void @_ZTS8MyKernel(ptr addrspace(1) noundef align 4 %_arg_in, ptr addrspace(1) noundef align 4 %_arg_res) local_unnamed_addr #0 comdat !srcloc !5 !kernel_arg_buffer_location !6 !sycl_fixed_targets !7 !sycl_kernel_omit_args !8 !stall_enable !9 {
31+
entry:
32+
%myMultTask.i = alloca %"class.task_sequence", align 8
33+
store i32 0, ptr %myMultTask.i, align 8
34+
; CHECK-LLVM: %[[TSCreate:[a-z0-9.]+]] = call spir_func target("spirv.TaskSequenceINTEL") @_Z66__spirv_TaskSequenceCreateINTEL_RPU3AS125__spirv_TaskSequenceINTELPiiiii(ptr @_Z4multii, i32 10, i32 -1, i32 0, i32 0)
35+
; CHECK-LLVM: store target("spirv.TaskSequenceINTEL") %[[TSCreate]], ptr %id.i
36+
%call.i1 = call spir_func noundef target("spirv.TaskSequenceINTEL") @_Z31__spirv_TaskSequenceCreateINTEL(ptr noundef nonnull @_Z4multii, i32 noundef 10, i32 noundef -1, i32 noundef 0, i16 noundef zeroext 0) #3
37+
%id.i = getelementptr inbounds %"class.task_sequence", ptr %myMultTask.i, i64 0, i32 0
38+
store target("spirv.TaskSequenceINTEL") %call.i1, ptr %id.i, align 8
39+
ret void
40+
}
41+
42+
; Function Attrs: mustprogress norecurse nounwind
43+
define linkonce_odr dso_local spir_func noundef i32 @_Z4multii(i32 noundef %a, i32 noundef %b) #1 !srcloc !10 {
44+
entry:
45+
%mul = mul nsw i32 %a, %b
46+
ret i32 %mul
47+
}
48+
49+
; Function Attrs: convergent nounwind
50+
declare dso_local spir_func noundef target("spirv.TaskSequenceINTEL") @_Z31__spirv_TaskSequenceCreateINTEL(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #2
51+
52+
attributes #0 = { convergent mustprogress norecurse nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-fpga-cluster"="1" "sycl-module-id"="test.cpp" "sycl-optlevel"="2" "sycl-single-task" "uniform-work-group-size"="true" }
53+
attributes #1 = { mustprogress norecurse nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-optlevel"="2" }
54+
attributes #2 = { convergent nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
55+
attributes #3 = { convergent nounwind }
56+
57+
!opencl.spir.version = !{!0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0}
58+
!spirv.Source = !{!1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1}
59+
!llvm.ident = !{!2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2}
60+
!llvm.module.flags = !{!3, !4}
61+
!sycl.specialization-constants = !{}
62+
!sycl.specialization-constants-default-values = !{}
63+
64+
!0 = !{i32 1, i32 2}
65+
!1 = !{i32 4, i32 100000}
66+
!2 = !{!"clang version 18.0.0git (https://github.com/bowenxue-intel/llvm.git bb1121cb47589e94ab65b81971a298b9d2c21ff6)"}
67+
!3 = !{i32 1, !"wchar_size", i32 4}
68+
!4 = !{i32 7, !"frame-pointer", i32 2}
69+
!5 = !{i32 5445863}
70+
!6 = !{i32 -1, i32 -1}
71+
!7 = !{}
72+
!8 = !{i1 false, i1 false}
73+
!9 = !{i1 true}
74+
!10 = !{i32 5445350}

0 commit comments

Comments
 (0)