blob: 22c6c92459771a8ec76182ec43dde6e865778d05 [file] [log] [blame]
Matt Arsenaultdc8f5cc2017-07-29 01:12:31 +00001; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=tahiti < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-SI -check-prefix=OPT-SICIVI %s
2; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=bonaire < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-CI -check-prefix=OPT-SICIVI %s
3; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=tonga -mattr=-flat-for-global < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-VI -check-prefix=OPT-SICIVI %s
4; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=gfx900 < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-GFX9 %s
5; RUN: llc -march=amdgcn -mcpu=tahiti -mattr=-promote-alloca -amdgpu-scalarize-global-loads=false -amdgpu-sroa=0 < %s | FileCheck -check-prefix=GCN -check-prefix=SI -check-prefix=SICIVI %s
6; RUN: llc -march=amdgcn -mcpu=bonaire -mattr=-promote-alloca -amdgpu-scalarize-global-loads=false -amdgpu-sroa=0 < %s | FileCheck -check-prefix=GCN -check-prefix=CI -check-prefix=SICIVI %s
7; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -amdgpu-scalarize-global-loads=false -mattr=-promote-alloca -amdgpu-sroa=0 < %s | FileCheck -check-prefix=GCN -check-prefix=VI -check-prefix=SICIVI %s
8; RUN: llc -march=amdgcn -mcpu=gfx900 -mattr=-promote-alloca -amdgpu-scalarize-global-loads=false -amdgpu-sroa=0 < %s | FileCheck -check-prefix=GCN -check-prefix=GFX9 %s
Matt Arsenault73e06fa2015-06-04 16:17:42 +00009
Matt Arsenault9de2fb52018-09-13 11:56:28 +000010target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
Matt Arsenault02d915b2017-03-15 22:35:20 +000011
Matt Arsenault73e06fa2015-06-04 16:17:42 +000012; OPT-LABEL: @test_sink_global_small_offset_i32(
Tom Stellard70580f82015-07-20 14:28:41 +000013; OPT-CI-NOT: getelementptr i32, i32 addrspace(1)* %in
14; OPT-VI: getelementptr i32, i32 addrspace(1)* %in
Matt Arsenault73e06fa2015-06-04 16:17:42 +000015; OPT: br i1
Eli Friedman5fba1e52017-04-06 22:42:18 +000016; OPT-CI: getelementptr i8,
Matt Arsenault73e06fa2015-06-04 16:17:42 +000017
18; GCN-LABEL: {{^}}test_sink_global_small_offset_i32:
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000019define amdgpu_kernel void @test_sink_global_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
Matt Arsenault73e06fa2015-06-04 16:17:42 +000020entry:
21 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
22 %in.gep = getelementptr i32, i32 addrspace(1)* %in, i64 7
Tom Stellardbc4497b2016-02-12 23:45:29 +000023 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
24 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault73e06fa2015-06-04 16:17:42 +000025 br i1 %tmp0, label %endif, label %if
26
27if:
28 %tmp1 = load i32, i32 addrspace(1)* %in.gep
29 br label %endif
30
31endif:
32 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
33 store i32 %x, i32 addrspace(1)* %out.gep
34 br label %done
35
36done:
37 ret void
38}
39
40; OPT-LABEL: @test_sink_global_small_max_i32_ds_offset(
41; OPT: %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 65535
42; OPT: br i1
43
44; GCN-LABEL: {{^}}test_sink_global_small_max_i32_ds_offset:
45; GCN: s_and_saveexec_b64
Matt Arsenaultdc8f5cc2017-07-29 01:12:31 +000046; SICIVI: buffer_load_sbyte {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, s{{[0-9]+$}}
47; GFX9: global_load_sbyte {{v[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}, off{{$}}
Matt Arsenault73e06fa2015-06-04 16:17:42 +000048; GCN: {{^}}BB1_2:
49; GCN: s_or_b64 exec
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000050define amdgpu_kernel void @test_sink_global_small_max_i32_ds_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) {
Matt Arsenault73e06fa2015-06-04 16:17:42 +000051entry:
52 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 99999
53 %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 65535
Tom Stellardbc4497b2016-02-12 23:45:29 +000054 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
55 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault73e06fa2015-06-04 16:17:42 +000056 br i1 %tmp0, label %endif, label %if
57
58if:
59 %tmp1 = load i8, i8 addrspace(1)* %in.gep
60 %tmp2 = sext i8 %tmp1 to i32
61 br label %endif
62
63endif:
64 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
65 store i32 %x, i32 addrspace(1)* %out.gep
66 br label %done
67
68done:
69 ret void
70}
71
72; GCN-LABEL: {{^}}test_sink_global_small_max_mubuf_offset:
73; GCN: s_and_saveexec_b64
Matt Arsenaultdc8f5cc2017-07-29 01:12:31 +000074; SICIVI: buffer_load_sbyte {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:4095{{$}}
75; GFX9: global_load_sbyte {{v[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}, off offset:4095{{$}}
Matt Arsenault73e06fa2015-06-04 16:17:42 +000076; GCN: {{^}}BB2_2:
77; GCN: s_or_b64 exec
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000078define amdgpu_kernel void @test_sink_global_small_max_mubuf_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) {
Matt Arsenault73e06fa2015-06-04 16:17:42 +000079entry:
80 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 1024
81 %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 4095
Tom Stellardbc4497b2016-02-12 23:45:29 +000082 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
83 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault73e06fa2015-06-04 16:17:42 +000084 br i1 %tmp0, label %endif, label %if
85
86if:
87 %tmp1 = load i8, i8 addrspace(1)* %in.gep
88 %tmp2 = sext i8 %tmp1 to i32
89 br label %endif
90
91endif:
92 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
93 store i32 %x, i32 addrspace(1)* %out.gep
94 br label %done
95
96done:
97 ret void
98}
99
100; GCN-LABEL: {{^}}test_sink_global_small_max_plus_1_mubuf_offset:
101; GCN: s_and_saveexec_b64
Matt Arsenaultdc8f5cc2017-07-29 01:12:31 +0000102; SICIVI: buffer_load_sbyte {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, s{{[0-9]+$}}
103; GFX9: global_load_sbyte {{v[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}, off{{$}}
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000104; GCN: {{^}}BB3_2:
105; GCN: s_or_b64 exec
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000106define amdgpu_kernel void @test_sink_global_small_max_plus_1_mubuf_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) {
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000107entry:
108 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 99999
109 %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 4096
Tom Stellardbc4497b2016-02-12 23:45:29 +0000110 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
111 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000112 br i1 %tmp0, label %endif, label %if
113
114if:
115 %tmp1 = load i8, i8 addrspace(1)* %in.gep
116 %tmp2 = sext i8 %tmp1 to i32
117 br label %endif
118
119endif:
120 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
121 store i32 %x, i32 addrspace(1)* %out.gep
122 br label %done
123
124done:
125 ret void
126}
127
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000128; OPT-LABEL: @test_sink_scratch_small_offset_i32(
129; OPT-NOT: getelementptr [512 x i32]
130; OPT: br i1
Eli Friedman5fba1e52017-04-06 22:42:18 +0000131; OPT: getelementptr i8,
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000132
133; GCN-LABEL: {{^}}test_sink_scratch_small_offset_i32:
134; GCN: s_and_saveexec_b64
Matt Arsenault39787bd2016-10-26 15:08:16 +0000135; GCN: buffer_store_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offset:4092{{$}}
136; GCN: buffer_load_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offset:4092{{$}}
Matt Arsenault711b3902015-08-07 20:18:34 +0000137; GCN: {{^}}BB4_2:
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000138define amdgpu_kernel void @test_sink_scratch_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %arg) {
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000139entry:
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000140 %alloca = alloca [512 x i32], align 4, addrspace(5)
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000141 %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998
142 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999
143 %add.arg = add i32 %arg, 8
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000144 %alloca.gep = getelementptr [512 x i32], [512 x i32] addrspace(5)* %alloca, i32 0, i32 1022
Matt Arsenault707780b2017-02-22 21:05:25 +0000145 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
146 %tmp0 = icmp eq i32 %tid, 0
147 br i1 %tmp0, label %endif, label %if
148
149if:
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000150 store volatile i32 123, i32 addrspace(5)* %alloca.gep
151 %tmp1 = load volatile i32, i32 addrspace(5)* %alloca.gep
Matt Arsenault707780b2017-02-22 21:05:25 +0000152 br label %endif
153
154endif:
155 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
156 store i32 %x, i32 addrspace(1)* %out.gep.0
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000157 %load = load volatile i32, i32 addrspace(5)* %alloca.gep
Matt Arsenault707780b2017-02-22 21:05:25 +0000158 store i32 %load, i32 addrspace(1)* %out.gep.1
159 br label %done
160
161done:
162 ret void
163}
164
165; This ends up not fitting due to the reserved 4 bytes at offset 0
166; OPT-LABEL: @test_sink_scratch_small_offset_i32_reserved(
167; OPT-NOT: getelementptr [512 x i32]
168; OPT: br i1
Eli Friedman5fba1e52017-04-06 22:42:18 +0000169; OPT: getelementptr i8,
Matt Arsenault707780b2017-02-22 21:05:25 +0000170
171; GCN-LABEL: {{^}}test_sink_scratch_small_offset_i32_reserved:
172; GCN: s_and_saveexec_b64
173; GCN: v_mov_b32_e32 [[BASE_FI0:v[0-9]+]], 4
174; GCN: buffer_store_dword {{v[0-9]+}}, [[BASE_FI0]], {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen offset:4092{{$}}
175; GCN: v_mov_b32_e32 [[BASE_FI1:v[0-9]+]], 4
176; GCN: buffer_load_dword {{v[0-9]+}}, [[BASE_FI1]], {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen offset:4092{{$}}
177; GCN: {{^BB[0-9]+}}_2:
178
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000179define amdgpu_kernel void @test_sink_scratch_small_offset_i32_reserved(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %arg) {
Matt Arsenault707780b2017-02-22 21:05:25 +0000180entry:
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000181 %alloca = alloca [512 x i32], align 4, addrspace(5)
Matt Arsenault707780b2017-02-22 21:05:25 +0000182 %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998
183 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999
184 %add.arg = add i32 %arg, 8
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000185 %alloca.gep = getelementptr [512 x i32], [512 x i32] addrspace(5)* %alloca, i32 0, i32 1023
Tom Stellardbc4497b2016-02-12 23:45:29 +0000186 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
187 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000188 br i1 %tmp0, label %endif, label %if
189
190if:
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000191 store volatile i32 123, i32 addrspace(5)* %alloca.gep
192 %tmp1 = load volatile i32, i32 addrspace(5)* %alloca.gep
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000193 br label %endif
194
195endif:
196 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
197 store i32 %x, i32 addrspace(1)* %out.gep.0
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000198 %load = load volatile i32, i32 addrspace(5)* %alloca.gep
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000199 store i32 %load, i32 addrspace(1)* %out.gep.1
200 br label %done
201
202done:
203 ret void
204}
205
206; OPT-LABEL: @test_no_sink_scratch_large_offset_i32(
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000207; OPT: %alloca.gep = getelementptr [512 x i32], [512 x i32] addrspace(5)* %alloca, i32 0, i32 1024
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000208; OPT: br i1
209; OPT-NOT: ptrtoint
210
211; GCN-LABEL: {{^}}test_no_sink_scratch_large_offset_i32:
212; GCN: s_and_saveexec_b64
213; GCN: buffer_store_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen{{$}}
214; GCN: buffer_load_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen{{$}}
Matt Arsenault707780b2017-02-22 21:05:25 +0000215; GCN: {{^BB[0-9]+}}_2:
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000216define amdgpu_kernel void @test_no_sink_scratch_large_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %arg) {
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000217entry:
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000218 %alloca = alloca [512 x i32], align 4, addrspace(5)
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000219 %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998
220 %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999
221 %add.arg = add i32 %arg, 8
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000222 %alloca.gep = getelementptr [512 x i32], [512 x i32] addrspace(5)* %alloca, i32 0, i32 1024
Tom Stellardbc4497b2016-02-12 23:45:29 +0000223 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
224 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000225 br i1 %tmp0, label %endif, label %if
226
227if:
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000228 store volatile i32 123, i32 addrspace(5)* %alloca.gep
229 %tmp1 = load volatile i32, i32 addrspace(5)* %alloca.gep
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000230 br label %endif
231
232endif:
233 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
234 store i32 %x, i32 addrspace(1)* %out.gep.0
Yaxun Liu2a22c5d2018-02-02 16:07:16 +0000235 %load = load volatile i32, i32 addrspace(5)* %alloca.gep
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000236 store i32 %load, i32 addrspace(1)* %out.gep.1
237 br label %done
238
239done:
240 ret void
241}
242
243; GCN-LABEL: {{^}}test_sink_global_vreg_sreg_i32:
244; GCN: s_and_saveexec_b64
Tom Stellard70580f82015-07-20 14:28:41 +0000245; CI: buffer_load_dword {{v[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
246; VI: flat_load_dword v{{[0-9]+}}, v[{{[0-9]+:[0-9]+}}]
Matt Arsenault707780b2017-02-22 21:05:25 +0000247; GCN: {{^BB[0-9]+}}_2:
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000248define amdgpu_kernel void @test_sink_global_vreg_sreg_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %offset) {
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000249entry:
250 %offset.ext = zext i32 %offset to i64
251 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
252 %in.gep = getelementptr i32, i32 addrspace(1)* %in, i64 %offset.ext
Tom Stellardbc4497b2016-02-12 23:45:29 +0000253 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
254 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault73e06fa2015-06-04 16:17:42 +0000255 br i1 %tmp0, label %endif, label %if
256
257if:
258 %tmp1 = load i32, i32 addrspace(1)* %in.gep
259 br label %endif
260
261endif:
262 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
263 store i32 %x, i32 addrspace(1)* %out.gep
264 br label %done
265
266done:
267 ret void
268}
269
Matt Arsenault711b3902015-08-07 20:18:34 +0000270; OPT-LABEL: @test_sink_constant_small_offset_i32
Yaxun Liu0124b542018-02-13 18:00:25 +0000271; OPT-NOT: getelementptr i32, i32 addrspace(4)*
Matt Arsenault711b3902015-08-07 20:18:34 +0000272; OPT: br i1
273
274; GCN-LABEL: {{^}}test_sink_constant_small_offset_i32:
275; GCN: s_and_saveexec_b64
276; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x7{{$}}
277; GCN: s_or_b64 exec, exec
Yaxun Liu0124b542018-02-13 18:00:25 +0000278define amdgpu_kernel void @test_sink_constant_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(4)* %in) {
Matt Arsenault711b3902015-08-07 20:18:34 +0000279entry:
280 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
Yaxun Liu0124b542018-02-13 18:00:25 +0000281 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 7
Tom Stellardbc4497b2016-02-12 23:45:29 +0000282 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
283 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault711b3902015-08-07 20:18:34 +0000284 br i1 %tmp0, label %endif, label %if
285
286if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000287 %tmp1 = load i32, i32 addrspace(4)* %in.gep
Matt Arsenault711b3902015-08-07 20:18:34 +0000288 br label %endif
289
290endif:
291 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
292 store i32 %x, i32 addrspace(1)* %out.gep
293 br label %done
294
295done:
296 ret void
297}
298
299; OPT-LABEL: @test_sink_constant_max_8_bit_offset_i32
Yaxun Liu0124b542018-02-13 18:00:25 +0000300; OPT-NOT: getelementptr i32, i32 addrspace(4)*
Matt Arsenault711b3902015-08-07 20:18:34 +0000301; OPT: br i1
302
303; GCN-LABEL: {{^}}test_sink_constant_max_8_bit_offset_i32:
304; GCN: s_and_saveexec_b64
305; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0xff{{$}}
306; GCN: s_or_b64 exec, exec
Yaxun Liu0124b542018-02-13 18:00:25 +0000307define amdgpu_kernel void @test_sink_constant_max_8_bit_offset_i32(i32 addrspace(1)* %out, i32 addrspace(4)* %in) {
Matt Arsenault711b3902015-08-07 20:18:34 +0000308entry:
309 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
Yaxun Liu0124b542018-02-13 18:00:25 +0000310 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 255
Tom Stellardbc4497b2016-02-12 23:45:29 +0000311 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
312 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault711b3902015-08-07 20:18:34 +0000313 br i1 %tmp0, label %endif, label %if
314
315if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000316 %tmp1 = load i32, i32 addrspace(4)* %in.gep
Matt Arsenault711b3902015-08-07 20:18:34 +0000317 br label %endif
318
319endif:
320 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
321 store i32 %x, i32 addrspace(1)* %out.gep
322 br label %done
323
324done:
325 ret void
326}
327
328; OPT-LABEL: @test_sink_constant_max_8_bit_offset_p1_i32
Yaxun Liu0124b542018-02-13 18:00:25 +0000329; OPT-SI: getelementptr i32, i32 addrspace(4)*
330; OPT-CI-NOT: getelementptr i32, i32 addrspace(4)*
331; OPT-VI-NOT: getelementptr i32, i32 addrspace(4)*
Matt Arsenault711b3902015-08-07 20:18:34 +0000332; OPT: br i1
333
334; GCN-LABEL: {{^}}test_sink_constant_max_8_bit_offset_p1_i32:
335; GCN: s_and_saveexec_b64
336; SI: s_movk_i32 [[OFFSET:s[0-9]+]], 0x400
337
338; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}}
339; GCN: s_or_b64 exec, exec
Yaxun Liu0124b542018-02-13 18:00:25 +0000340define amdgpu_kernel void @test_sink_constant_max_8_bit_offset_p1_i32(i32 addrspace(1)* %out, i32 addrspace(4)* %in) {
Matt Arsenault711b3902015-08-07 20:18:34 +0000341entry:
342 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
Yaxun Liu0124b542018-02-13 18:00:25 +0000343 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 256
Tom Stellardbc4497b2016-02-12 23:45:29 +0000344 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
345 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault711b3902015-08-07 20:18:34 +0000346 br i1 %tmp0, label %endif, label %if
347
348if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000349 %tmp1 = load i32, i32 addrspace(4)* %in.gep
Matt Arsenault711b3902015-08-07 20:18:34 +0000350 br label %endif
351
352endif:
353 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
354 store i32 %x, i32 addrspace(1)* %out.gep
355 br label %done
356
357done:
358 ret void
359}
360
361; OPT-LABEL: @test_sink_constant_max_32_bit_offset_i32
Yaxun Liu0124b542018-02-13 18:00:25 +0000362; OPT-SI: getelementptr i32, i32 addrspace(4)*
363; OPT-CI-NOT: getelementptr i32, i32 addrspace(4)*
Matt Arsenault711b3902015-08-07 20:18:34 +0000364; OPT: br i1
365
366; GCN-LABEL: {{^}}test_sink_constant_max_32_bit_offset_i32:
367; GCN: s_and_saveexec_b64
Tom Stellard9a197672015-09-09 15:43:26 +0000368; GCN: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, -4{{$}}
369; GCN: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, 3{{$}}
Matt Arsenault711b3902015-08-07 20:18:34 +0000370; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x0{{$}}
371; GCN: s_or_b64 exec, exec
Yaxun Liu0124b542018-02-13 18:00:25 +0000372define amdgpu_kernel void @test_sink_constant_max_32_bit_offset_i32(i32 addrspace(1)* %out, i32 addrspace(4)* %in) {
Matt Arsenault711b3902015-08-07 20:18:34 +0000373entry:
374 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
Yaxun Liu0124b542018-02-13 18:00:25 +0000375 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 4294967295
Tom Stellardbc4497b2016-02-12 23:45:29 +0000376 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
377 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault711b3902015-08-07 20:18:34 +0000378 br i1 %tmp0, label %endif, label %if
379
380if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000381 %tmp1 = load i32, i32 addrspace(4)* %in.gep
Matt Arsenault711b3902015-08-07 20:18:34 +0000382 br label %endif
383
384endif:
385 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
386 store i32 %x, i32 addrspace(1)* %out.gep
387 br label %done
388
389done:
390 ret void
391}
392
393; OPT-LABEL: @test_sink_constant_max_32_bit_offset_p1_i32
Yaxun Liu0124b542018-02-13 18:00:25 +0000394; OPT: getelementptr i32, i32 addrspace(4)*
Matt Arsenault711b3902015-08-07 20:18:34 +0000395; OPT: br i1
396
397; GCN-LABEL: {{^}}test_sink_constant_max_32_bit_offset_p1_i32:
398; GCN: s_and_saveexec_b64
399; GCN: s_add_u32
400; GCN: s_addc_u32
401; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x0{{$}}
402; GCN: s_or_b64 exec, exec
Yaxun Liu0124b542018-02-13 18:00:25 +0000403define amdgpu_kernel void @test_sink_constant_max_32_bit_offset_p1_i32(i32 addrspace(1)* %out, i32 addrspace(4)* %in) {
Matt Arsenault711b3902015-08-07 20:18:34 +0000404entry:
405 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
Yaxun Liu0124b542018-02-13 18:00:25 +0000406 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 17179869181
Tom Stellardbc4497b2016-02-12 23:45:29 +0000407 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
408 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault711b3902015-08-07 20:18:34 +0000409 br i1 %tmp0, label %endif, label %if
410
411if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000412 %tmp1 = load i32, i32 addrspace(4)* %in.gep
Matt Arsenault711b3902015-08-07 20:18:34 +0000413 br label %endif
414
415endif:
416 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
417 store i32 %x, i32 addrspace(1)* %out.gep
418 br label %done
419
420done:
421 ret void
422}
423
424; GCN-LABEL: {{^}}test_sink_constant_max_20_bit_byte_offset_i32:
425; GCN: s_and_saveexec_b64
426; SI: s_mov_b32 [[OFFSET:s[0-9]+]], 0xffffc{{$}}
427; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}}
428
429; CI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x3ffff{{$}}
430; VI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0xffffc{{$}}
431
432; GCN: s_or_b64 exec, exec
Yaxun Liu0124b542018-02-13 18:00:25 +0000433define amdgpu_kernel void @test_sink_constant_max_20_bit_byte_offset_i32(i32 addrspace(1)* %out, i32 addrspace(4)* %in) {
Matt Arsenault711b3902015-08-07 20:18:34 +0000434entry:
435 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
Yaxun Liu0124b542018-02-13 18:00:25 +0000436 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 262143
Tom Stellardbc4497b2016-02-12 23:45:29 +0000437 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
438 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault711b3902015-08-07 20:18:34 +0000439 br i1 %tmp0, label %endif, label %if
440
441if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000442 %tmp1 = load i32, i32 addrspace(4)* %in.gep
Matt Arsenault711b3902015-08-07 20:18:34 +0000443 br label %endif
444
445endif:
446 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
447 store i32 %x, i32 addrspace(1)* %out.gep
448 br label %done
449
450done:
451 ret void
452}
453
454; OPT-LABEL: @test_sink_constant_max_20_bit_byte_offset_p1_i32
Yaxun Liu0124b542018-02-13 18:00:25 +0000455; OPT-SI: getelementptr i32, i32 addrspace(4)*
456; OPT-CI-NOT: getelementptr i32, i32 addrspace(4)*
457; OPT-VI: getelementptr i32, i32 addrspace(4)*
Matt Arsenault711b3902015-08-07 20:18:34 +0000458; OPT: br i1
459
460; GCN-LABEL: {{^}}test_sink_constant_max_20_bit_byte_offset_p1_i32:
461; GCN: s_and_saveexec_b64
462; SI: s_mov_b32 [[OFFSET:s[0-9]+]], 0x100000{{$}}
463; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}}
464
465; CI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x40000{{$}}
466
467; VI: s_mov_b32 [[OFFSET:s[0-9]+]], 0x100000{{$}}
468; VI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}}
469
470; GCN: s_or_b64 exec, exec
Yaxun Liu0124b542018-02-13 18:00:25 +0000471define amdgpu_kernel void @test_sink_constant_max_20_bit_byte_offset_p1_i32(i32 addrspace(1)* %out, i32 addrspace(4)* %in) {
Matt Arsenault711b3902015-08-07 20:18:34 +0000472entry:
473 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
Yaxun Liu0124b542018-02-13 18:00:25 +0000474 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 262144
Tom Stellardbc4497b2016-02-12 23:45:29 +0000475 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
476 %tmp0 = icmp eq i32 %tid, 0
Matt Arsenault711b3902015-08-07 20:18:34 +0000477 br i1 %tmp0, label %endif, label %if
478
479if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000480 %tmp1 = load i32, i32 addrspace(4)* %in.gep
Matt Arsenault711b3902015-08-07 20:18:34 +0000481 br label %endif
482
483endif:
484 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
485 store i32 %x, i32 addrspace(1)* %out.gep
486 br label %done
487
488done:
489 ret void
490}
Tom Stellardbc4497b2016-02-12 23:45:29 +0000491
Matt Arsenaultc1e6a452016-07-09 08:02:28 +0000492%struct.foo = type { [3 x float], [3 x float] }
493
494; OPT-LABEL: @sink_ds_address(
Eli Friedman5fba1e52017-04-06 22:42:18 +0000495; OPT: getelementptr i8,
Matt Arsenaultc1e6a452016-07-09 08:02:28 +0000496
497; GCN-LABEL: {{^}}sink_ds_address:
498; GCN: s_load_dword [[SREG1:s[0-9]+]],
499; GCN: v_mov_b32_e32 [[VREG1:v[0-9]+]], [[SREG1]]
500; GCN-DAG: ds_read2_b32 v[{{[0-9+:[0-9]+}}], [[VREG1]] offset0:3 offset1:5
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000501define amdgpu_kernel void @sink_ds_address(%struct.foo addrspace(3)* nocapture %ptr) nounwind {
Matt Arsenaultc1e6a452016-07-09 08:02:28 +0000502entry:
503 %x = getelementptr inbounds %struct.foo, %struct.foo addrspace(3)* %ptr, i32 0, i32 1, i32 0
504 %y = getelementptr inbounds %struct.foo, %struct.foo addrspace(3)* %ptr, i32 0, i32 1, i32 2
505 br label %bb32
506
507bb32:
508 %a = load float, float addrspace(3)* %x, align 4
509 %b = load float, float addrspace(3)* %y, align 4
510 %cmp = fcmp one float %a, %b
511 br i1 %cmp, label %bb34, label %bb33
512
513bb33:
514 unreachable
515
516bb34:
517 unreachable
518}
519
Matt Arsenault3cc1e002016-08-13 01:43:51 +0000520; Address offset is not a multiple of 4. This is a valid mubuf offset,
521; but not smrd.
522
523; OPT-LABEL: @test_sink_constant_small_max_mubuf_offset_load_i32_align_1(
524; OPT: br i1 %tmp0,
525; OPT: if:
Eli Friedman5fba1e52017-04-06 22:42:18 +0000526; OPT: getelementptr i8, {{.*}} 4095
Yaxun Liu0124b542018-02-13 18:00:25 +0000527define amdgpu_kernel void @test_sink_constant_small_max_mubuf_offset_load_i32_align_1(i32 addrspace(1)* %out, i8 addrspace(4)* %in) {
Matt Arsenault3cc1e002016-08-13 01:43:51 +0000528entry:
529 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 1024
Yaxun Liu0124b542018-02-13 18:00:25 +0000530 %in.gep = getelementptr i8, i8 addrspace(4)* %in, i64 4095
Matt Arsenault3cc1e002016-08-13 01:43:51 +0000531 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
532 %tmp0 = icmp eq i32 %tid, 0
533 br i1 %tmp0, label %endif, label %if
534
535if:
Yaxun Liu0124b542018-02-13 18:00:25 +0000536 %bitcast = bitcast i8 addrspace(4)* %in.gep to i32 addrspace(4)*
537 %tmp1 = load i32, i32 addrspace(4)* %bitcast, align 1
Matt Arsenault3cc1e002016-08-13 01:43:51 +0000538 br label %endif
539
540endif:
541 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
542 store i32 %x, i32 addrspace(1)* %out.gep
543 br label %done
544
545done:
546 ret void
547}
548
Matt Arsenault02d915b2017-03-15 22:35:20 +0000549; OPT-LABEL: @test_sink_local_small_offset_atomicrmw_i32(
Eli Friedman5fba1e52017-04-06 22:42:18 +0000550; OPT: %0 = bitcast i32 addrspace(3)* %in to i8 addrspace(3)*
551; OPT: %sunkaddr = getelementptr i8, i8 addrspace(3)* %0, i32 28
552; OPT: %1 = bitcast i8 addrspace(3)* %sunkaddr to i32 addrspace(3)*
553; OPT: %tmp1 = atomicrmw add i32 addrspace(3)* %1, i32 2 seq_cst
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000554define amdgpu_kernel void @test_sink_local_small_offset_atomicrmw_i32(i32 addrspace(3)* %out, i32 addrspace(3)* %in) {
Matt Arsenault02d915b2017-03-15 22:35:20 +0000555entry:
556 %out.gep = getelementptr i32, i32 addrspace(3)* %out, i32 999999
557 %in.gep = getelementptr i32, i32 addrspace(3)* %in, i32 7
558 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
559 %tmp0 = icmp eq i32 %tid, 0
560 br i1 %tmp0, label %endif, label %if
561
562if:
563 %tmp1 = atomicrmw add i32 addrspace(3)* %in.gep, i32 2 seq_cst
564 br label %endif
565
566endif:
567 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
568 store i32 %x, i32 addrspace(3)* %out.gep
569 br label %done
570
571done:
572 ret void
573}
574
575; OPT-LABEL: @test_sink_local_small_offset_cmpxchg_i32(
Eli Friedman5fba1e52017-04-06 22:42:18 +0000576; OPT: %0 = bitcast i32 addrspace(3)* %in to i8 addrspace(3)*
577; OPT: %sunkaddr = getelementptr i8, i8 addrspace(3)* %0, i32 28
578; OPT: %1 = bitcast i8 addrspace(3)* %sunkaddr to i32 addrspace(3)*
579; OPT: %tmp1.struct = cmpxchg i32 addrspace(3)* %1, i32 undef, i32 2 seq_cst monotonic
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000580define amdgpu_kernel void @test_sink_local_small_offset_cmpxchg_i32(i32 addrspace(3)* %out, i32 addrspace(3)* %in) {
Matt Arsenault02d915b2017-03-15 22:35:20 +0000581entry:
582 %out.gep = getelementptr i32, i32 addrspace(3)* %out, i32 999999
583 %in.gep = getelementptr i32, i32 addrspace(3)* %in, i32 7
584 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
585 %tmp0 = icmp eq i32 %tid, 0
586 br i1 %tmp0, label %endif, label %if
587
588if:
589 %tmp1.struct = cmpxchg i32 addrspace(3)* %in.gep, i32 undef, i32 2 seq_cst monotonic
590 %tmp1 = extractvalue { i32, i1 } %tmp1.struct, 0
591 br label %endif
592
593endif:
594 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
595 store i32 %x, i32 addrspace(3)* %out.gep
596 br label %done
597
598done:
599 ret void
600}
601
602; OPT-LABEL: @test_wrong_operand_local_small_offset_cmpxchg_i32(
603; OPT: %in.gep = getelementptr i32, i32 addrspace(3)* %in, i32 7
604; OPT: br i1
605; OPT: cmpxchg i32 addrspace(3)* addrspace(3)* undef, i32 addrspace(3)* %in.gep, i32 addrspace(3)* undef seq_cst monotonic
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000606define amdgpu_kernel void @test_wrong_operand_local_small_offset_cmpxchg_i32(i32 addrspace(3)* addrspace(3)* %out, i32 addrspace(3)* %in) {
Matt Arsenault02d915b2017-03-15 22:35:20 +0000607entry:
608 %out.gep = getelementptr i32 addrspace(3)*, i32 addrspace(3)* addrspace(3)* %out, i32 999999
609 %in.gep = getelementptr i32, i32 addrspace(3)* %in, i32 7
610 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
611 %tmp0 = icmp eq i32 %tid, 0
612 br i1 %tmp0, label %endif, label %if
613
614if:
615 %tmp1.struct = cmpxchg i32 addrspace(3)* addrspace(3)* undef, i32 addrspace(3)* %in.gep, i32 addrspace(3)* undef seq_cst monotonic
616 %tmp1 = extractvalue { i32 addrspace(3)*, i1 } %tmp1.struct, 0
617 br label %endif
618
619endif:
620 %x = phi i32 addrspace(3)* [ %tmp1, %if ], [ null, %entry ]
621 store i32 addrspace(3)* %x, i32 addrspace(3)* addrspace(3)* %out.gep
622 br label %done
623
624done:
625 ret void
626}
627
Matt Arsenault7dc01c92017-03-15 23:15:12 +0000628; OPT-LABEL: @test_sink_local_small_offset_atomic_inc_i32(
Eli Friedman5fba1e52017-04-06 22:42:18 +0000629; OPT: %0 = bitcast i32 addrspace(3)* %in to i8 addrspace(3)*
630; OPT: %sunkaddr = getelementptr i8, i8 addrspace(3)* %0, i32 28
631; OPT: %1 = bitcast i8 addrspace(3)* %sunkaddr to i32 addrspace(3)*
632; OPT: %tmp1 = call i32 @llvm.amdgcn.atomic.inc.i32.p3i32(i32 addrspace(3)* %1, i32 2, i32 0, i32 0, i1 false)
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000633define amdgpu_kernel void @test_sink_local_small_offset_atomic_inc_i32(i32 addrspace(3)* %out, i32 addrspace(3)* %in) {
Matt Arsenault7dc01c92017-03-15 23:15:12 +0000634entry:
635 %out.gep = getelementptr i32, i32 addrspace(3)* %out, i32 999999
636 %in.gep = getelementptr i32, i32 addrspace(3)* %in, i32 7
637 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
638 %tmp0 = icmp eq i32 %tid, 0
639 br i1 %tmp0, label %endif, label %if
640
641if:
Matt Arsenault79f837c2017-03-30 22:21:40 +0000642 %tmp1 = call i32 @llvm.amdgcn.atomic.inc.i32.p3i32(i32 addrspace(3)* %in.gep, i32 2, i32 0, i32 0, i1 false)
Matt Arsenault7dc01c92017-03-15 23:15:12 +0000643 br label %endif
644
645endif:
646 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
647 store i32 %x, i32 addrspace(3)* %out.gep
648 br label %done
649
650done:
651 ret void
652}
653
654; OPT-LABEL: @test_sink_local_small_offset_atomic_dec_i32(
Eli Friedman5fba1e52017-04-06 22:42:18 +0000655; OPT: %0 = bitcast i32 addrspace(3)* %in to i8 addrspace(3)*
656; OPT: %sunkaddr = getelementptr i8, i8 addrspace(3)* %0, i32 28
657; OPT: %1 = bitcast i8 addrspace(3)* %sunkaddr to i32 addrspace(3)*
658; OPT: %tmp1 = call i32 @llvm.amdgcn.atomic.dec.i32.p3i32(i32 addrspace(3)* %1, i32 2, i32 0, i32 0, i1 false)
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000659define amdgpu_kernel void @test_sink_local_small_offset_atomic_dec_i32(i32 addrspace(3)* %out, i32 addrspace(3)* %in) {
Matt Arsenault7dc01c92017-03-15 23:15:12 +0000660entry:
661 %out.gep = getelementptr i32, i32 addrspace(3)* %out, i32 999999
662 %in.gep = getelementptr i32, i32 addrspace(3)* %in, i32 7
663 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
664 %tmp0 = icmp eq i32 %tid, 0
665 br i1 %tmp0, label %endif, label %if
666
667if:
Matt Arsenault79f837c2017-03-30 22:21:40 +0000668 %tmp1 = call i32 @llvm.amdgcn.atomic.dec.i32.p3i32(i32 addrspace(3)* %in.gep, i32 2, i32 0, i32 0, i1 false)
Matt Arsenault7dc01c92017-03-15 23:15:12 +0000669 br label %endif
670
671endif:
672 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
673 store i32 %x, i32 addrspace(3)* %out.gep
674 br label %done
675
676done:
677 ret void
678}
679
Matt Arsenaultdc8f5cc2017-07-29 01:12:31 +0000680; OPT-LABEL: @test_sink_global_small_min_scratch_global_offset(
681; OPT-SICIVI: %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 -4096
682; OPT-SICIV: br
683; OPT-SICIVI: %tmp1 = load i8, i8 addrspace(1)* %in.gep
684
685; OPT-GFX9: br
686; OPT-GFX9: %sunkaddr = getelementptr i8, i8 addrspace(1)* %in, i64 -4096
687; OPT-GFX9: load i8, i8 addrspace(1)* %sunkaddr
688
689; GCN-LABEL: {{^}}test_sink_global_small_min_scratch_global_offset:
690; GFX9: global_load_sbyte v{{[0-9]+}}, v{{\[[0-9]+:[0-9]+\]}}, off offset:-4096{{$}}
691define amdgpu_kernel void @test_sink_global_small_min_scratch_global_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) {
692entry:
693 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 1024
694 %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 -4096
695 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
696 %tmp0 = icmp eq i32 %tid, 0
697 br i1 %tmp0, label %endif, label %if
698
699if:
700 %tmp1 = load i8, i8 addrspace(1)* %in.gep
701 %tmp2 = sext i8 %tmp1 to i32
702 br label %endif
703
704endif:
705 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
706 store i32 %x, i32 addrspace(1)* %out.gep
707 br label %done
708
709done:
710 ret void
711}
712
713; OPT-LABEL: @test_sink_global_small_min_scratch_global_neg1_offset(
714; OPT: %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 -4097
715; OPT: br
716; OPT: load i8, i8 addrspace(1)* %in.gep
717
718; GCN-LABEL: {{^}}test_sink_global_small_min_scratch_global_neg1_offset:
719define amdgpu_kernel void @test_sink_global_small_min_scratch_global_neg1_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) {
720entry:
721 %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 99999
722 %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 -4097
723 %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0
724 %tmp0 = icmp eq i32 %tid, 0
725 br i1 %tmp0, label %endif, label %if
726
727if:
728 %tmp1 = load i8, i8 addrspace(1)* %in.gep
729 %tmp2 = sext i8 %tmp1 to i32
730 br label %endif
731
732endif:
733 %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
734 store i32 %x, i32 addrspace(1)* %out.gep
735 br label %done
736
737done:
738 ret void
739}
740
Tom Stellardbc4497b2016-02-12 23:45:29 +0000741declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #0
Matt Arsenault79f837c2017-03-30 22:21:40 +0000742declare i32 @llvm.amdgcn.atomic.inc.i32.p3i32(i32 addrspace(3)* nocapture, i32, i32, i32, i1) #2
743declare i32 @llvm.amdgcn.atomic.dec.i32.p3i32(i32 addrspace(3)* nocapture, i32, i32, i32, i1) #2
Tom Stellardbc4497b2016-02-12 23:45:29 +0000744
745attributes #0 = { nounwind readnone }
Matt Arsenault3cc1e002016-08-13 01:43:51 +0000746attributes #1 = { nounwind }
Matt Arsenault7dc01c92017-03-15 23:15:12 +0000747attributes #2 = { nounwind argmemonly }