1; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck %s
2
3; Nothing should be done if the addrspacecast is captured.
4
5declare void @consume_ptr2int(i32) #0
6
7; CHECK-LABEL: @addrspacecast_captured(
8; CHECK: %data = alloca i32, align 4
9; CHECK: %cast = addrspacecast i32* %data to i32 addrspace(4)*
10; CHECK: %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
11; CHECK: store i32 %ptr2int, i32 addrspace(1)* %out
12define amdgpu_kernel void @addrspacecast_captured(i32 addrspace(1)* %out) #0 {
13entry:
14  %data = alloca i32, align 4
15  %cast = addrspacecast i32* %data to i32 addrspace(4)*
16  %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
17  store i32 %ptr2int, i32 addrspace(1)* %out
18  ret void
19}
20
21; CHECK-LABEL: @addrspacecast_captured_store(
22; CHECK: %data = alloca i32, align 4
23; CHECK: %cast = addrspacecast i32* %data to i32 addrspace(4)*
24; CHECK: store i32 addrspace(4)* %cast, i32 addrspace(4)* addrspace(1)* %out
25define amdgpu_kernel void @addrspacecast_captured_store(i32 addrspace(4)* addrspace(1)* %out) #0 {
26entry:
27  %data = alloca i32, align 4
28  %cast = addrspacecast i32* %data to i32 addrspace(4)*
29  store i32 addrspace(4)* %cast, i32 addrspace(4)* addrspace(1)* %out
30  ret void
31}
32
33; CHECK-LABEL: @addrspacecast_captured_call(
34; CHECK: %data = alloca i32, align 4
35; CHECK: %cast = addrspacecast i32* %data to i32 addrspace(4)*
36; CHECK: %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
37; CHECK: call void @consume_ptr2int(i32 %ptr2int)
38define amdgpu_kernel void @addrspacecast_captured_call() #0 {
39entry:
40  %data = alloca i32, align 4
41  %cast = addrspacecast i32* %data to i32 addrspace(4)*
42  %ptr2int = ptrtoint i32 addrspace(4)* %cast to i32
43  call void @consume_ptr2int(i32 %ptr2int)
44  ret void
45}
46
47attributes #0 = { nounwind }
48