xref: /llvm-project/llvm/test/CodeGen/SPIRV/transcoding/ConvertPtr.ll (revision 0a443f13b49b3f392461a0bb60b0146cfc4607c7)
1; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3
4;; kernel void testConvertPtrToU(global int *a, global unsigned long *res) {
5;;   res[0] = (unsigned long)&a[0];
6;; }
7
8; CHECK-SPIRV: OpConvertPtrToU
9
10define dso_local spir_kernel void @testConvertPtrToU(i32 addrspace(1)* noundef %a, i64 addrspace(1)* nocapture noundef writeonly %res) local_unnamed_addr {
11entry:
12  %0 = ptrtoint i32 addrspace(1)* %a to i32
13  %1 = zext i32 %0 to i64
14  store i64 %1, i64 addrspace(1)* %res, align 8
15  ret void
16}
17
18;; kernel void testConvertUToPtr(unsigned long a) {
19;;   global unsigned int *res = (global unsigned int *)a;
20;;   res[0] = 0;
21;; }
22
23; CHECK-SPIRV: OpConvertUToPtr
24
25define dso_local spir_kernel void @testConvertUToPtr(i64 noundef %a) local_unnamed_addr {
26entry:
27  %conv = trunc i64 %a to i32
28  %0 = inttoptr i32 %conv to i32 addrspace(1)*
29  store i32 0, i32 addrspace(1)* %0, align 4
30  ret void
31}
32