Home | History | Annotate | Download | only in transcoding
      1 ; ModuleID = '<stdin>'
      2 target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
      3 target triple = "spir64-unknown-unknown"
      4 
      5 ; RUN: llvm-as %s -o %t.bc
      6 ; RUN: llvm-spirv %t.bc -spirv-text -o %t.txt
      7 ; RUN: FileCheck < %t.txt %s --check-prefix=CHECK-SPIRV
      8 ; RUN: llvm-spirv %t.bc -o %t.spv
      9 ; RUN: llvm-spirv -r %t.spv -o %t.bc
     10 ; RUN: llvm-dis < %t.bc | FileCheck %s
     11 
     12 ; Check conversion of get_image_width, get_image_height, get_image_depth,
     13 ; get_image_array_size, and get_image_dim OCL built-ins.
     14 ; In general the SPRI-V reader converts OpImageQuerySize into get_image_dim
     15 ; and subsequent extract or shufflevector instructions. Unfortunately there is
     16 ; no get_image_dim for 1D images and get_image_dim cannot replace get_image_array_size
     17 
     18 ; CHECK-DAG: %opencl.image1d_t = type opaque
     19 ; CHECK-DAG: %opencl.image1d_buffer_t = type opaque
     20 ; CHECK-DAG: %opencl.image1d_array_t = type opaque
     21 ; CHECK-DAG: %opencl.image2d_t = type opaque
     22 ; CHECK-DAG: %opencl.image2d_depth_t = type opaque
     23 ; CHECK-DAG: %opencl.image2d_array_t = type opaque
     24 ; CHECK-SPIRV: 10 TypeImage [[ArrayTypeID:[0-9]+]] {{[0-9]+}} 0 0 1 0 0 0 0
     25 ; CHECK-DAG: %opencl.image2d_array_depth_t = type opaque
     26 ; CHECK-DAG: %opencl.image3d_t = type opaque
     27 
     28 %opencl.image1d_t = type opaque
     29 %opencl.image1d_buffer_t = type opaque
     30 %opencl.image1d_array_t = type opaque
     31 %opencl.image2d_t = type opaque
     32 %opencl.image2d_depth_t = type opaque
     33 %opencl.image2d_array_t = type opaque
     34 %opencl.image2d_array_depth_t = type opaque
     35 %opencl.image3d_t = type opaque
     36 
     37 ; CHECK:   define {{.*}} @test_image1d
     38 
     39 ; CHECK:   call {{.*}} @_Z15get_image_width11ocl_image1d
     40 
     41 ; CHECK:   call {{.*}} @_Z15get_image_width17ocl_image1dbuffer
     42 
     43 ; CHECK:   call {{.*}} @_Z15get_image_width16ocl_image1darray
     44 ; CHECK:   insertelement <2 x i32> {{.*}} 0
     45 ; CHECK:   call {{.*}} i64 @_Z20get_image_array_size16ocl_image1darray
     46 ; CHECK:   trunc i64 {{.*}} to i32
     47 ; CHECK:   insertelement <2 x i32> {{.*}} 1
     48 
     49 ; CHECK:   call {{.*}} i64 @_Z20get_image_array_size16ocl_image1darray
     50 ; CHECK-SPIRV: 3 FunctionParameter [[ArrayTypeID]] [[ArrayVarID:[0-9]+]]
     51 ; CHECK-SPIRV: ImageQuerySizeLod {{[0-9]+}} {{[0-9]+}} [[ArrayVarID]]
     52 ; CHECK-SPIRV-NOT: {{[0-9]*}} ExtInst {{[0-9]*}} {{[0-9]*}} {{[0-9]*}} get_image_array_size
     53 
     54 ; Function Attrs: nounwind
     55 define spir_kernel void @test_image1d(i32 addrspace(1)* nocapture %sizes, %opencl.image1d_t addrspace(1)* %img, %opencl.image1d_buffer_t addrspace(1)* %buffer, %opencl.image1d_array_t addrspace(1)* %array) #0 {
     56   %1 = tail call spir_func i32 @_Z15get_image_width11ocl_image1d(%opencl.image1d_t addrspace(1)* %img) #1
     57   %2 = tail call spir_func i32 @_Z15get_image_width17ocl_image1dbuffer(%opencl.image1d_buffer_t addrspace(1)* %buffer) #1
     58   %3 = tail call spir_func i32 @_Z15get_image_width16ocl_image1darray(%opencl.image1d_array_t addrspace(1)* %array) #1
     59   %4 = tail call spir_func i64 @_Z20get_image_array_size16ocl_image1darray(%opencl.image1d_array_t addrspace(1)* %array) #1
     60   %5 = trunc i64 %4 to i32
     61   %6 = add nsw i32 %2, %1
     62   %7 = add nsw i32 %6, %3
     63   %8 = add nsw i32 %7, %5
     64   store i32 %8, i32 addrspace(1)* %sizes, align 4, !tbaa !22
     65   ret void
     66 }
     67 
     68 ; Function Attrs: nounwind readnone
     69 declare spir_func i32 @_Z15get_image_width11ocl_image1d(%opencl.image1d_t addrspace(1)*) #1
     70 
     71 ; Function Attrs: nounwind readnone
     72 declare spir_func i32 @_Z15get_image_width17ocl_image1dbuffer(%opencl.image1d_buffer_t addrspace(1)*) #1
     73 
     74 ; Function Attrs: nounwind readnone
     75 declare spir_func i32 @_Z15get_image_width16ocl_image1darray(%opencl.image1d_array_t addrspace(1)*) #1
     76 
     77 ; Function Attrs: nounwind readnone
     78 declare spir_func i64 @_Z20get_image_array_size16ocl_image1darray(%opencl.image1d_array_t addrspace(1)*) #1
     79 
     80 ; CHECK:   define {{.*}} @test_image2d
     81 
     82 ; CHECK:   call {{.*}} @_Z13get_image_dim11ocl_image2d
     83 ; CHECK:   extractelement <2 x i32> {{.*}} 0
     84 
     85 ; CHECK:   call {{.*}} @_Z13get_image_dim11ocl_image2d
     86 ; CHECK:   extractelement <2 x i32> {{.*}} 1
     87 
     88 ; CHECK:   call {{.*}} @_Z13get_image_dim11ocl_image2d
     89 ; CHECK:   call {{.*}} @_Z13get_image_dim16ocl_image2darray
     90 ; CHECK:   shufflevector <2 x i32> {{.*}} <3 x i32>
     91 ; CHECK:   call {{.*}} i64 @_Z20get_image_array_size16ocl_image2darray
     92 ; CHECK:   trunc i64 {{.*}} to i32
     93 ; CHECK:   insertelement <3 x i32> {{.*}} i32 2
     94 ; CHECK:   extractelement <3 x i32> {{.*}} 0
     95 
     96 ; CHECK:   call {{.*}} @_Z13get_image_dim16ocl_image2darray
     97 ; CHECK:   shufflevector <2 x i32> {{.*}} <3 x i32>
     98 ; CHECK:   call {{.*}} i64 @_Z20get_image_array_size16ocl_image2darray
     99 ; CHECK:   trunc i64 {{.*}} to i32
    100 ; CHECK:   insertelement <3 x i32> {{.*}} i32 2
    101 ; CHECK:   extractelement <3 x i32> {{.*}} 1
    102 
    103 ; CHECK:   call {{.*}} @_Z20get_image_array_size16ocl_image2darray
    104 
    105 ; CHECK:   call {{.*}} @_Z13get_image_dim16ocl_image2darray
    106 ; CHECK:   shufflevector <2 x i32> {{.*}} <3 x i32>
    107 ; CHECK:   call {{.*}} i64 @_Z20get_image_array_size16ocl_image2darray
    108 ; CHECK:   trunc i64 {{.*}} to i32
    109 ; CHECK:   insertelement <3 x i32> {{.*}} i32 2
    110 ; CHECK:   shufflevector <3 x i32> {{.*}} <2 x i32>
    111 
    112 ; Function Attrs: nounwind
    113 define spir_kernel void @test_image2d(i32 addrspace(1)* nocapture %sizes, %opencl.image2d_t addrspace(1)* %img, %opencl.image2d_depth_t addrspace(1)* nocapture %img_depth, %opencl.image2d_array_t addrspace(1)* %array, %opencl.image2d_array_depth_t addrspace(1)* nocapture %array_depth) #0 {
    114   %1 = tail call spir_func i32 @_Z15get_image_width11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #1
    115   %2 = tail call spir_func i32 @_Z16get_image_height11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #1
    116   %3 = tail call spir_func <2 x i32> @_Z13get_image_dim11ocl_image2d(%opencl.image2d_t addrspace(1)* %img) #1
    117   %4 = tail call spir_func i32 @_Z15get_image_width16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1
    118   %5 = tail call spir_func i32 @_Z16get_image_height16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1
    119   %6 = tail call spir_func i64 @_Z20get_image_array_size16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1
    120   %7 = trunc i64 %6 to i32
    121   %8 = tail call spir_func <2 x i32> @_Z13get_image_dim16ocl_image2darray(%opencl.image2d_array_t addrspace(1)* %array) #1
    122   %9 = add nsw i32 %2, %1
    123   %10 = extractelement <2 x i32> %3, i32 0
    124   %11 = add nsw i32 %9, %10
    125   %12 = extractelement <2 x i32> %3, i32 1
    126   %13 = add nsw i32 %11, %12
    127   %14 = add nsw i32 %13, %4
    128   %15 = add nsw i32 %14, %5
    129   %16 = add nsw i32 %15, %7
    130   %17 = extractelement <2 x i32> %8, i32 0
    131   %18 = add nsw i32 %16, %17
    132   %19 = extractelement <2 x i32> %8, i32 1
    133   %20 = add nsw i32 %18, %19
    134   store i32 %20, i32 addrspace(1)* %sizes, align 4, !tbaa !22
    135   ret void
    136 }
    137 
    138 ; Function Attrs: nounwind readnone
    139 declare spir_func i32 @_Z15get_image_width11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1
    140 
    141 ; Function Attrs: nounwind readnone
    142 declare spir_func i32 @_Z16get_image_height11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1
    143 
    144 ; Function Attrs: nounwind readnone
    145 declare spir_func <2 x i32> @_Z13get_image_dim11ocl_image2d(%opencl.image2d_t addrspace(1)*) #1
    146 
    147 ; Function Attrs: nounwind readnone
    148 declare spir_func i32 @_Z15get_image_width16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1
    149 
    150 ; Function Attrs: nounwind readnone
    151 declare spir_func i32 @_Z16get_image_height16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1
    152 
    153 ; Function Attrs: nounwind readnone
    154 declare spir_func i64 @_Z20get_image_array_size16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1
    155 
    156 ; Function Attrs: nounwind readnone
    157 declare spir_func <2 x i32> @_Z13get_image_dim16ocl_image2darray(%opencl.image2d_array_t addrspace(1)*) #1
    158 
    159 ; CHECK:   define {{.*}} @test_image3d
    160 
    161 ; CHECK:   call {{.*}} @_Z13get_image_dim11ocl_image3d
    162 ; CHECK:   shufflevector <4 x i32> {{.*}} <3 x i32>
    163 ; CHECK:   extractelement <3 x i32> {{.*}} 0
    164 
    165 ; CHECK:   call {{.*}} @_Z13get_image_dim11ocl_image3d
    166 ; CHECK:   shufflevector <4 x i32> {{.*}} <3 x i32>
    167 ; CHECK:   extractelement <3 x i32> {{.*}} 1
    168 
    169 ; CHECK:   call {{.*}} @_Z13get_image_dim11ocl_image3d
    170 ; CHECK:   shufflevector <4 x i32> {{.*}} <3 x i32>
    171 ; CHECK:   extractelement <3 x i32> {{.*}} 2
    172 
    173 ; CHECK:   call {{.*}} @_Z13get_image_dim11ocl_image3d
    174 ; CHECK:   shufflevector <4 x i32> {{.*}} <3 x i32>
    175 ; CHECK:   shufflevector <3 x i32> {{.*}} <4 x i32>
    176 
    177 ; Function Attrs: nounwind
    178 define spir_kernel void @test_image3d(i32 addrspace(1)* nocapture %sizes, %opencl.image3d_t addrspace(1)* %img) #0 {
    179   %1 = tail call spir_func i32 @_Z15get_image_width11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1
    180   %2 = tail call spir_func i32 @_Z16get_image_height11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1
    181   %3 = tail call spir_func i32 @_Z15get_image_depth11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1
    182   %4 = tail call spir_func <4 x i32> @_Z13get_image_dim11ocl_image3d(%opencl.image3d_t addrspace(1)* %img) #1
    183   %5 = add nsw i32 %2, %1
    184   %6 = add nsw i32 %5, %3
    185   %7 = extractelement <4 x i32> %4, i32 0
    186   %8 = add nsw i32 %6, %7
    187   %9 = extractelement <4 x i32> %4, i32 1
    188   %10 = add nsw i32 %8, %9
    189   %11 = extractelement <4 x i32> %4, i32 2
    190   %12 = add nsw i32 %10, %11
    191   %13 = extractelement <4 x i32> %4, i32 3
    192   %14 = add nsw i32 %12, %13
    193   store i32 %14, i32 addrspace(1)* %sizes, align 4, !tbaa !22
    194   ret void
    195 }
    196 
    197 ; Function Attrs: nounwind readnone
    198 declare spir_func i32 @_Z15get_image_width11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1
    199 
    200 ; Function Attrs: nounwind readnone
    201 declare spir_func i32 @_Z16get_image_height11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1
    202 
    203 ; Function Attrs: nounwind readnone
    204 declare spir_func i32 @_Z15get_image_depth11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1
    205 
    206 ; Function Attrs: nounwind readnone
    207 declare spir_func <4 x i32> @_Z13get_image_dim11ocl_image3d(%opencl.image3d_t addrspace(1)*) #1
    208 
    209 ; CHECK:   define {{.*}} @test_image2d_array_depth_t
    210 
    211 ; CHECK:   call {{.*}} <2 x i32> @_Z13get_image_dim21ocl_image2darraydepth
    212 ; CHECK:   shufflevector <2 x i32>
    213 ; CHECK:   call {{.*}} i64 @_Z20get_image_array_size21ocl_image2darraydepth
    214 ; CHECK:   trunc i64 {{.*}} to i32
    215 ; CHECK:   insertelement <3 x i32> {{.*}} 2
    216 ; CHECK:   extractelement <3 x i32> {{.*}} 0
    217 
    218 ; CHECK:   call {{.*}} <2 x i32> @_Z13get_image_dim21ocl_image2darraydepth
    219 ; CHECK:   shufflevector <2 x i32>
    220 ; CHECK:   call {{.*}} i64 @_Z20get_image_array_size21ocl_image2darraydepth
    221 ; CHECK:   trunc i64 {{.*}} to i32
    222 ; CHECK:   insertelement <3 x i32> {{.*}} 2
    223 ; CHECK:   extractelement <3 x i32> {{.*}} 1
    224 
    225 ; Function Attrs: nounwind
    226 define spir_kernel void @test_image2d_array_depth_t(i32 addrspace(1)* nocapture %sizes, %opencl.image2d_array_depth_t addrspace(1)* %array) #0 {
    227   %1 = tail call spir_func i32 @_Z15get_image_width21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)* %array) #1
    228   %2 = tail call spir_func i32 @_Z16get_image_height21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)* %array) #1
    229   %3 = tail call spir_func i64 @_Z20get_image_array_size21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)* %array) #1
    230   %4 = trunc i64 %3 to i32
    231   %5 = add nsw i32 %2, %1
    232   %6 = add nsw i32 %5, %4
    233   store i32 %5, i32 addrspace(1)* %sizes, align 4, !tbaa !25
    234   ret void
    235 }
    236 
    237 ; Function Attrs: nounwind readnone
    238 declare spir_func i32 @_Z15get_image_width21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)*) #1
    239 
    240 ; Function Attrs: nounwind readnone
    241 declare spir_func i32 @_Z16get_image_height21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)*) #1
    242 
    243 ; Function Attrs: nounwind readnone
    244 declare spir_func i64 @_Z20get_image_array_size21ocl_image2darraydepth(%opencl.image2d_array_depth_t addrspace(1)*) #1
    245 
    246 attributes #0 = { nounwind }
    247 attributes #1 = { nounwind readnone }
    248 
    249 !opencl.kernels = !{!0, !6, !12}
    250 !opencl.enable.FP_CONTRACT = !{}
    251 !opencl.spir.version = !{!18}
    252 !opencl.ocl.version = !{!18}
    253 !opencl.used.extensions = !{!19}
    254 !opencl.used.optional.core.features = !{!20}
    255 !opencl.compiler.options = !{!21}
    256 
    257 !0 = !{void (i32 addrspace(1)*, %opencl.image1d_t addrspace(1)*, %opencl.image1d_buffer_t addrspace(1)*, %opencl.image1d_array_t addrspace(1)*)* @test_image1d, !1, !2, !3, !4, !5}
    258 !1 = !{!"kernel_arg_addr_space", i32 1, i32 1, i32 1, i32 1}
    259 !2 = !{!"kernel_arg_access_qual", !"none", !"read_only", !"read_only", !"read_only"}
    260 !3 = !{!"kernel_arg_type", !"int*", !"image1d_t", !"image1d_buffer_t", !"image1d_array_t"}
    261 !4 = !{!"kernel_arg_type_qual", !"", !"", !"", !""}
    262 !5 = !{!"kernel_arg_base_type", !"int*", !"image1d_t", !"image1d_buffer_t", !"image1d_array_t"}
    263 !6 = !{void (i32 addrspace(1)*, %opencl.image2d_t addrspace(1)*, %opencl.image2d_depth_t addrspace(1)*, %opencl.image2d_array_t addrspace(1)*, %opencl.image2d_array_depth_t addrspace(1)*)* @test_image2d, !7, !8, !9, !10, !11}
    264 !7 = !{!"kernel_arg_addr_space", i32 1, i32 1, i32 1, i32 1, i32 1}
    265 !8 = !{!"kernel_arg_access_qual", !"none", !"read_only", !"read_only", !"read_only", !"read_only"}
    266 !9 = !{!"kernel_arg_type", !"int*", !"image2d_t", !"image2d_depth_t", !"image2d_array_t", !"image2d_array_depth_t"}
    267 !10 = !{!"kernel_arg_type_qual", !"", !"", !"", !"", !""}
    268 !11 = !{!"kernel_arg_base_type", !"int*", !"image2d_t", !"image2d_depth_t", !"image2d_array_t", !"image2d_array_depth_t"}
    269 !12 = !{void (i32 addrspace(1)*, %opencl.image3d_t addrspace(1)*)* @test_image3d, !13, !14, !15, !16, !17}
    270 !13 = !{!"kernel_arg_addr_space", i32 1, i32 1}
    271 !14 = !{!"kernel_arg_access_qual", !"none", !"read_only"}
    272 !15 = !{!"kernel_arg_type", !"int*", !"image3d_t"}
    273 !16 = !{!"kernel_arg_type_qual", !"", !""}
    274 !17 = !{!"kernel_arg_base_type", !"int*", !"image3d_t"}
    275 !18 = !{i32 1, i32 2}
    276 !19 = !{!"cl_khr_depth_images"}
    277 !20 = !{!"cl_images"}
    278 !21 = !{}
    279 !22 = !{!23, !23, i64 0}
    280 !23 = !{!"int", !24}
    281 !24 = !{!"omnipotent char", !25}
    282 !25 = !{!"Simple C/C++ TBAA"}
    283 !26 = !{void (i32 addrspace(1)*, %opencl.image2d_array_depth_t addrspace(1)*)* @test_image2d_array_depth_t, !27, !28, !29, !30, !31}
    284 !27 = !{!"kernel_arg_addr_space", i32 1, i32 1}
    285 !28 = !{!"kernel_arg_access_qual", !"none", !"read_only"}
    286 !29 = !{!"kernel_arg_type", !"int*", !"image2d_array_depth_t"}
    287 !30 = !{!"kernel_arg_type_qual", !"", !""}
    288 !31 = !{!"kernel_arg_base_type", !"int*", !"image2d_array_depth_t"}
    289