1 ; RUN: llc -O0 -mtriple=spirv64-unknown-linux %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
4 ;; The IR was generated from the following source:
5 ;; #include <CL/sycl.hpp>
7 ;; template <typename T, int N>
10 ;; using namespace cl::sycl;
15 ;; nd_range<1> NdRange(X, X);
16 ;; buffer<int> buf(X);
17 ;; Queue.submit([&](handler &cgh) {
18 ;; auto acc = buf.template get_access<access::mode::read_write>(cgh);
19 ;; cgh.parallel_for<sycl_subgr<int, 0>>(NdRange, [=](nd_item<1> NdItem) {
20 ;; intel::sub_group SG = NdItem.get_sub_group();
22 ;; acc[0] = SG.get_max_local_range()[0];
24 ;; acc[1] = (X % 3) ? 1 : SG.get_max_local_range()[0];
30 ;; clang -fsycl -fsycl-device-only -Xclang -fsycl-enable-optimizations tmp.cpp -o tmp.bc
31 ;; llvm-spirv tmp.bc -s -o builtin_vars_opt.ll
33 ; CHECK-SPIRV-DAG: OpDecorate %[[#SG_MaxSize_BI:]] BuiltIn SubgroupMaxSize
34 ; CHECK-SPIRV-DAG: OpDecorate %[[#SG_MaxSize_BI:]] Constant
35 ; CHECK-SPIRV-DAG: OpDecorate %[[#SG_MaxSize_BI:]] LinkageAttributes "__spirv_BuiltInSubgroupMaxSize" Import
37 %"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range" = type { %"class._ZTSN2cl4sycl6detail5arrayILi1EEE.cl::sycl::detail::array" }
38 %"class._ZTSN2cl4sycl6detail5arrayILi1EEE.cl::sycl::detail::array" = type { [1 x i64] }
39 %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id" = type { %"class._ZTSN2cl4sycl6detail5arrayILi1EEE.cl::sycl::detail::array" }
41 $_ZTS10sycl_subgrIiLi0EE = comdat any
43 @__spirv_BuiltInSubgroupMaxSize = external dso_local local_unnamed_addr addrspace(1) constant i32, align 4
46 define weak_odr dso_local spir_kernel void @_ZTS10sycl_subgrIiLi0EE(i32 %_arg_, i32 addrspace(1)* %_arg_1, %"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range"* byval(%"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range") align 8 %_arg_3, %"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range"* byval(%"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range") align 8 %_arg_4, %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id"* byval(%"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id") align 8 %_arg_5) local_unnamed_addr comdat {
48 %0 = getelementptr inbounds %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id", %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id"* %_arg_5, i64 0, i32 0, i32 0, i64 0
49 %1 = load i64, i64* %0, align 8
50 %add.ptr.i = getelementptr inbounds i32, i32 addrspace(1)* %_arg_1, i64 %1
51 %2 = and i32 %_arg_, 1
52 %tobool.not.i = icmp eq i32 %2, 0
53 %3 = addrspacecast i32 addrspace(1)* @__spirv_BuiltInSubgroupMaxSize to i32 addrspace(4)*
54 br i1 %tobool.not.i, label %if.end.i, label %if.then.i
56 if.then.i: ; preds = %entry
57 %4 = load i32, i32 addrspace(4)* %3, align 4
58 %ptridx.ascast.i14.i = addrspacecast i32 addrspace(1)* %add.ptr.i to i32 addrspace(4)*
59 store i32 %4, i32 addrspace(4)* %ptridx.ascast.i14.i, align 4
62 if.end.i: ; preds = %if.then.i, %entry
63 %rem3.i = srem i32 %_arg_, 3
64 %tobool4.not.i = icmp eq i32 %rem3.i, 0
65 br i1 %tobool4.not.i, label %cond.false.i, label %"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_7nd_itemILi1EEEE_clES5_.exit"
67 cond.false.i: ; preds = %if.end.i
68 %5 = load i32, i32 addrspace(4)* %3, align 4
69 br label %"_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_7nd_itemILi1EEEE_clES5_.exit"
71 "_ZZZ4mainENK3$_0clERN2cl4sycl7handlerEENKUlNS1_7nd_itemILi1EEEE_clES5_.exit": ; preds = %cond.false.i, %if.end.i
72 %cond.i = phi i32 [ %5, %cond.false.i ], [ 1, %if.end.i ]
73 %ptridx.i.i = getelementptr inbounds i32, i32 addrspace(1)* %add.ptr.i, i64 1
74 %ptridx.ascast.i.i = addrspacecast i32 addrspace(1)* %ptridx.i.i to i32 addrspace(4)*
75 store i32 %cond.i, i32 addrspace(4)* %ptridx.ascast.i.i, align 4