1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s
2
3; CHECK-LABEL: @objectsize_group_to_flat_i32(
4; CHECK: %val = call i32 @llvm.objectsize.i32.p3i8(i8 addrspace(3)* %group.ptr, i1 true, i1 false, i1 false)
5define i32 @objectsize_group_to_flat_i32(i8 addrspace(3)* %group.ptr) #0 {
6  %cast = addrspacecast i8 addrspace(3)* %group.ptr to i8*
7  %val = call i32 @llvm.objectsize.i32.p0i8(i8* %cast, i1 true, i1 false, i1 false)
8  ret i32 %val
9}
10
11; CHECK-LABEL: @objectsize_global_to_flat_i64(
12; CHECK: %val = call i64 @llvm.objectsize.i64.p3i8(i8 addrspace(3)* %global.ptr, i1 true, i1 false, i1 false)
13define i64 @objectsize_global_to_flat_i64(i8 addrspace(3)* %global.ptr) #0 {
14  %cast = addrspacecast i8 addrspace(3)* %global.ptr to i8*
15  %val = call i64 @llvm.objectsize.i64.p0i8(i8* %cast, i1 true, i1 false, i1 false)
16  ret i64 %val
17}
18
19; CHECK-LABEL: @atomicinc_global_to_flat_i32(
20; CHECK: call i32 @llvm.amdgcn.atomic.inc.i32.p1i32(i32 addrspace(1)* %global.ptr, i32 %y, i32 0, i32 0, i1 false)
21define i32 @atomicinc_global_to_flat_i32(i32 addrspace(1)* %global.ptr, i32 %y) #0 {
22  %cast = addrspacecast i32 addrspace(1)* %global.ptr to i32*
23  %ret = call i32 @llvm.amdgcn.atomic.inc.i32.p0i32(i32* %cast, i32 %y, i32 0, i32 0, i1 false)
24  ret i32 %ret
25}
26
27; CHECK-LABEL: @atomicinc_group_to_flat_i32(
28; CHECK: %ret = call i32 @llvm.amdgcn.atomic.inc.i32.p3i32(i32 addrspace(3)* %group.ptr, i32 %y, i32 0, i32 0, i1 false)
29define i32 @atomicinc_group_to_flat_i32(i32 addrspace(3)* %group.ptr, i32 %y) #0 {
30  %cast = addrspacecast i32 addrspace(3)* %group.ptr to i32*
31  %ret = call i32 @llvm.amdgcn.atomic.inc.i32.p0i32(i32* %cast, i32 %y, i32 0, i32 0, i1 false)
32  ret i32 %ret
33}
34
35; CHECK-LABEL: @atomicinc_global_to_flat_i64(
36; CHECK: call i64 @llvm.amdgcn.atomic.inc.i64.p1i64(i64 addrspace(1)* %global.ptr, i64 %y, i32 0, i32 0, i1 false)
37define i64 @atomicinc_global_to_flat_i64(i64 addrspace(1)* %global.ptr, i64 %y) #0 {
38  %cast = addrspacecast i64 addrspace(1)* %global.ptr to i64*
39  %ret = call i64 @llvm.amdgcn.atomic.inc.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 false)
40  ret i64 %ret
41}
42
43; CHECK-LABEL: @atomicinc_group_to_flat_i64(
44; CHECK: call i64 @llvm.amdgcn.atomic.inc.i64.p3i64(i64 addrspace(3)* %group.ptr, i64 %y, i32 0, i32 0, i1 false)
45define i64 @atomicinc_group_to_flat_i64(i64 addrspace(3)* %group.ptr, i64 %y) #0 {
46  %cast = addrspacecast i64 addrspace(3)* %group.ptr to i64*
47  %ret = call i64 @llvm.amdgcn.atomic.inc.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 false)
48  ret i64 %ret
49}
50
51; CHECK-LABEL: @atomicdec_global_to_flat_i32(
52; CHECK: call i32 @llvm.amdgcn.atomic.dec.i32.p1i32(i32 addrspace(1)* %global.ptr, i32 %val, i32 0, i32 0, i1 false)
53define i32 @atomicdec_global_to_flat_i32(i32 addrspace(1)* %global.ptr, i32 %val) #0 {
54  %cast = addrspacecast i32 addrspace(1)* %global.ptr to i32*
55  %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* %cast, i32 %val, i32 0, i32 0, i1 false)
56  ret i32 %ret
57}
58
59; CHECK-LABEL: @atomicdec_group_to_flat_i32(
60; CHECK: %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p3i32(i32 addrspace(3)* %group.ptr, i32 %val, i32 0, i32 0, i1 false)
61define i32 @atomicdec_group_to_flat_i32(i32 addrspace(3)* %group.ptr, i32 %val) #0 {
62  %cast = addrspacecast i32 addrspace(3)* %group.ptr to i32*
63  %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* %cast, i32 %val, i32 0, i32 0, i1 false)
64  ret i32 %ret
65}
66
67; CHECK-LABEL: @atomicdec_global_to_flat_i64(
68; CHECK: call i64 @llvm.amdgcn.atomic.dec.i64.p1i64(i64 addrspace(1)* %global.ptr, i64 %y, i32 0, i32 0, i1 false)
69define i64 @atomicdec_global_to_flat_i64(i64 addrspace(1)* %global.ptr, i64 %y) #0 {
70  %cast = addrspacecast i64 addrspace(1)* %global.ptr to i64*
71  %ret = call i64 @llvm.amdgcn.atomic.dec.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 false)
72  ret i64 %ret
73}
74
75; CHECK-LABEL: @atomicdec_group_to_flat_i64(
76; CHECK: call i64 @llvm.amdgcn.atomic.dec.i64.p3i64(i64 addrspace(3)* %group.ptr, i64 %y, i32 0, i32 0, i1 false
77define i64 @atomicdec_group_to_flat_i64(i64 addrspace(3)* %group.ptr, i64 %y) #0 {
78  %cast = addrspacecast i64 addrspace(3)* %group.ptr to i64*
79  %ret = call i64 @llvm.amdgcn.atomic.dec.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 false)
80  ret i64 %ret
81}
82
83; CHECK-LABEL: @volatile_atomicinc_group_to_flat_i64(
84; CHECK-NEXT: %cast = addrspacecast i64 addrspace(3)* %group.ptr to i64*
85; CHECK-NEXT: %ret = call i64 @llvm.amdgcn.atomic.inc.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 true)
86define i64 @volatile_atomicinc_group_to_flat_i64(i64 addrspace(3)* %group.ptr, i64 %y) #0 {
87  %cast = addrspacecast i64 addrspace(3)* %group.ptr to i64*
88  %ret = call i64 @llvm.amdgcn.atomic.inc.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 true)
89  ret i64 %ret
90}
91
92; CHECK-LABEL: @volatile_atomicdec_global_to_flat_i32(
93; CHECK-NEXT: %cast = addrspacecast i32 addrspace(1)* %global.ptr to i32*
94; CHECK-NEXT: %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* %cast, i32 %val, i32 0, i32 0, i1 true)
95define i32 @volatile_atomicdec_global_to_flat_i32(i32 addrspace(1)* %global.ptr, i32 %val) #0 {
96  %cast = addrspacecast i32 addrspace(1)* %global.ptr to i32*
97  %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* %cast, i32 %val, i32 0, i32 0, i1 true)
98  ret i32 %ret
99}
100
101; CHECK-LABEL: @volatile_atomicdec_group_to_flat_i32(
102; CHECK-NEXT: %cast = addrspacecast i32 addrspace(3)* %group.ptr to i32*
103; CHECK-NEXT: %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* %cast, i32 %val, i32 0, i32 0, i1 true)
104define i32 @volatile_atomicdec_group_to_flat_i32(i32 addrspace(3)* %group.ptr, i32 %val) #0 {
105  %cast = addrspacecast i32 addrspace(3)* %group.ptr to i32*
106  %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* %cast, i32 %val, i32 0, i32 0, i1 true)
107  ret i32 %ret
108}
109
110; CHECK-LABEL: @volatile_atomicdec_global_to_flat_i64(
111; CHECK-NEXT: %cast = addrspacecast i64 addrspace(1)* %global.ptr to i64*
112; CHECK-NEXT: %ret = call i64 @llvm.amdgcn.atomic.dec.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 true)
113define i64 @volatile_atomicdec_global_to_flat_i64(i64 addrspace(1)* %global.ptr, i64 %y) #0 {
114  %cast = addrspacecast i64 addrspace(1)* %global.ptr to i64*
115  %ret = call i64 @llvm.amdgcn.atomic.dec.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 true)
116  ret i64 %ret
117}
118
119; CHECK-LABEL: @volatile_atomicdec_group_to_flat_i64(
120; CHECK-NEXT: %cast = addrspacecast i64 addrspace(3)* %group.ptr to i64*
121; CHECK-NEXT: %ret = call i64 @llvm.amdgcn.atomic.dec.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 true)
122define i64 @volatile_atomicdec_group_to_flat_i64(i64 addrspace(3)* %group.ptr, i64 %y) #0 {
123  %cast = addrspacecast i64 addrspace(3)* %group.ptr to i64*
124  %ret = call i64 @llvm.amdgcn.atomic.dec.i64.p0i64(i64* %cast, i64 %y, i32 0, i32 0, i1 true)
125  ret i64 %ret
126}
127
128declare i32 @llvm.objectsize.i32.p0i8(i8*, i1, i1, i1) #1
129declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1) #1
130declare i32 @llvm.amdgcn.atomic.inc.i32.p0i32(i32* nocapture, i32, i32, i32, i1) #2
131declare i64 @llvm.amdgcn.atomic.inc.i64.p0i64(i64* nocapture, i64, i32, i32, i1) #2
132declare i32 @llvm.amdgcn.atomic.dec.i32.p0i32(i32* nocapture, i32, i32, i32, i1) #2
133declare i64 @llvm.amdgcn.atomic.dec.i64.p0i64(i64* nocapture, i64, i32, i32, i1) #2
134
135attributes #0 = { nounwind }
136attributes #1 = { nounwind readnone }
137attributes #2 = { nounwind argmemonly }
138