1; RUN: llc -march=r600 -mcpu=cypress < %s | FileCheck %s -check-prefix=R600 -check-prefix=FUNC
2; RUN: llc -show-mc-encoding -mattr=+promote-alloca -verify-machineinstrs -march=amdgcn < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC
3; RUN: llc -show-mc-encoding -mattr=+promote-alloca -verify-machineinstrs -mtriple=amdgcn--amdhsa -mcpu=kaveri < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC -check-prefix=HSA-PROMOTE
4; RUN: llc -show-mc-encoding -mattr=-promote-alloca -verify-machineinstrs -march=amdgcn < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC
5; RUN: llc -show-mc-encoding -mattr=-promote-alloca -verify-machineinstrs -mtriple=amdgcn-amdhsa -mcpu=kaveri < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC -check-prefix=HSA-ALLOCA
6; RUN: llc -show-mc-encoding -mattr=+promote-alloca -verify-machineinstrs -march=amdgcn -mcpu=tonga < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC
7; RUN: llc -show-mc-encoding -mattr=-promote-alloca -verify-machineinstrs -march=amdgcn -mcpu=tonga < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC
8
9; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck -check-prefix=HSAOPT -check-prefix=OPT %s
10; RUN: opt -S -mtriple=amdgcn-unknown-unknown -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck -check-prefix=NOHSAOPT -check-prefix=OPT %s
11
12; HSAOPT: @mova_same_clause.stack = internal unnamed_addr addrspace(3) global [256 x [5 x i32]] undef, align 4
13; HSAOPT: @high_alignment.stack = internal unnamed_addr addrspace(3) global [256 x [8 x i32]] undef, align 16
14
15
16; FUNC-LABEL: {{^}}mova_same_clause:
17; OPT-LABEL: @mova_same_clause(
18
19; R600: LDS_WRITE
20; R600: LDS_WRITE
21; R600: LDS_READ
22; R600: LDS_READ
23
24; HSA-PROMOTE: .amd_kernel_code_t
25; HSA-PROMOTE: workgroup_group_segment_byte_size = 5120
26; HSA-PROMOTE: .end_amd_kernel_code_t
27
28; FIXME: These should be merged
29; HSA-PROMOTE: s_load_dword s{{[0-9]+}}, s[4:5], 0x1
30; HSA-PROMOTE: s_load_dword s{{[0-9]+}}, s[4:5], 0x2
31
32; SI-PROMOTE: ds_write_b32
33; SI-PROMOTE: ds_write_b32
34; SI-PROMOTE: ds_read_b32
35; SI-PROMOTE: ds_read_b32
36
37; HSA-ALLOCA: .amd_kernel_code_t
38; FIXME: Creating the emergency stack slots causes us to over-estimate scratch
39; by 4 bytes.
40; HSA-ALLOCA: workitem_private_segment_byte_size = 24
41; HSA-ALLOCA: .end_amd_kernel_code_t
42
43; HSA-ALLOCA: s_mov_b32 flat_scratch_lo, s7
44; HSA-ALLOCA: s_add_u32 s6, s6, s9
45; HSA-ALLOCA: s_lshr_b32 flat_scratch_hi, s6, 8
46
47; SI-ALLOCA: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x70,0xe0
48; SI-ALLOCA: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x70,0xe0
49
50
51; HSAOPT: [[DISPATCH_PTR:%[0-9]+]] = call noalias nonnull dereferenceable(64) i8 addrspace(2)* @llvm.amdgcn.dispatch.ptr()
52; HSAOPT: [[CAST_DISPATCH_PTR:%[0-9]+]] = bitcast i8 addrspace(2)* [[DISPATCH_PTR]] to i32 addrspace(2)*
53; HSAOPT: [[GEP0:%[0-9]+]] = getelementptr inbounds i32, i32 addrspace(2)* [[CAST_DISPATCH_PTR]], i64 1
54; HSAOPT: [[LDXY:%[0-9]+]] = load i32, i32 addrspace(2)* [[GEP0]], align 4, !invariant.load !0
55; HSAOPT: [[GEP1:%[0-9]+]] = getelementptr inbounds i32, i32 addrspace(2)* [[CAST_DISPATCH_PTR]], i64 2
56; HSAOPT: [[LDZU:%[0-9]+]] = load i32, i32 addrspace(2)* [[GEP1]], align 4, !range !1, !invariant.load !0
57; HSAOPT: [[EXTRACTY:%[0-9]+]] = lshr i32 [[LDXY]], 16
58
59; HSAOPT: [[WORKITEM_ID_X:%[0-9]+]] = call i32 @llvm.amdgcn.workitem.id.x(), !range !1
60; HSAOPT: [[WORKITEM_ID_Y:%[0-9]+]] = call i32 @llvm.amdgcn.workitem.id.y(), !range !1
61; HSAOPT: [[WORKITEM_ID_Z:%[0-9]+]] = call i32 @llvm.amdgcn.workitem.id.z(), !range !1
62
63; HSAOPT: [[Y_SIZE_X_Z_SIZE:%[0-9]+]] = mul nuw nsw i32 [[EXTRACTY]], [[LDZU]]
64; HSAOPT: [[YZ_X_XID:%[0-9]+]] = mul i32 [[Y_SIZE_X_Z_SIZE]], [[WORKITEM_ID_X]]
65; HSAOPT: [[Y_X_Z_SIZE:%[0-9]+]] = mul nuw nsw i32 [[WORKITEM_ID_Y]], [[LDZU]]
66; HSAOPT: [[ADD_YZ_X_X_YZ_SIZE:%[0-9]+]] = add i32 [[YZ_X_XID]], [[Y_X_Z_SIZE]]
67; HSAOPT: [[ADD_ZID:%[0-9]+]] = add i32 [[ADD_YZ_X_X_YZ_SIZE]], [[WORKITEM_ID_Z]]
68
69; HSAOPT: [[LOCAL_GEP:%[0-9]+]] = getelementptr inbounds [256 x [5 x i32]], [256 x [5 x i32]] addrspace(3)* @mova_same_clause.stack, i32 0, i32 [[ADD_ZID]]
70; HSAOPT: %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 {{%[0-9]+}}
71; HSAOPT: %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 {{%[0-9]+}}
72; HSAOPT: %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 0
73; HSAOPT: %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 1
74
75
76; NOHSAOPT: call i32 @llvm.r600.read.local.size.y(), !range !0
77; NOHSAOPT: call i32 @llvm.r600.read.local.size.z(), !range !0
78; NOHSAOPT: call i32 @llvm.amdgcn.workitem.id.x(), !range !0
79; NOHSAOPT: call i32 @llvm.amdgcn.workitem.id.y(), !range !0
80; NOHSAOPT: call i32 @llvm.amdgcn.workitem.id.z(), !range !0
81define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
82entry:
83  %stack = alloca [5 x i32], align 4
84  %0 = load i32, i32 addrspace(1)* %in, align 4
85  %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %0
86  store i32 4, i32* %arrayidx1, align 4
87  %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1
88  %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4
89  %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %1
90  store i32 5, i32* %arrayidx3, align 4
91  %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 0
92  %2 = load i32, i32* %arrayidx10, align 4
93  store i32 %2, i32 addrspace(1)* %out, align 4
94  %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 1
95  %3 = load i32, i32* %arrayidx12
96  %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1
97  store i32 %3, i32 addrspace(1)* %arrayidx13
98  ret void
99}
100
101; OPT-LABEL: @high_alignment(
102; OPT: getelementptr inbounds [256 x [8 x i32]], [256 x [8 x i32]] addrspace(3)* @high_alignment.stack, i32 0, i32 %{{[0-9]+}}
103define void @high_alignment(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
104entry:
105  %stack = alloca [8 x i32], align 16
106  %0 = load i32, i32 addrspace(1)* %in, align 4
107  %arrayidx1 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 %0
108  store i32 4, i32* %arrayidx1, align 4
109  %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1
110  %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4
111  %arrayidx3 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 %1
112  store i32 5, i32* %arrayidx3, align 4
113  %arrayidx10 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 0
114  %2 = load i32, i32* %arrayidx10, align 4
115  store i32 %2, i32 addrspace(1)* %out, align 4
116  %arrayidx12 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 1
117  %3 = load i32, i32* %arrayidx12
118  %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1
119  store i32 %3, i32 addrspace(1)* %arrayidx13
120  ret void
121}
122
123; FUNC-LABEL: {{^}}no_replace_inbounds_gep:
124; OPT-LABEL: @no_replace_inbounds_gep(
125; OPT: alloca [5 x i32]
126
127; SI-NOT: ds_write
128define void @no_replace_inbounds_gep(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
129entry:
130  %stack = alloca [5 x i32], align 4
131  %0 = load i32, i32 addrspace(1)* %in, align 4
132  %arrayidx1 = getelementptr [5 x i32], [5 x i32]* %stack, i32 0, i32 %0
133  store i32 4, i32* %arrayidx1, align 4
134  %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1
135  %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4
136  %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %1
137  store i32 5, i32* %arrayidx3, align 4
138  %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 0
139  %2 = load i32, i32* %arrayidx10, align 4
140  store i32 %2, i32 addrspace(1)* %out, align 4
141  %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 1
142  %3 = load i32, i32* %arrayidx12
143  %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1
144  store i32 %3, i32 addrspace(1)* %arrayidx13
145  ret void
146}
147
148; This test checks that the stack offset is calculated correctly for structs.
149; All register loads/stores should be optimized away, so there shouldn't be
150; any MOVA instructions.
151;
152; XXX: This generated code has unnecessary MOVs, we should be able to optimize
153; this.
154
155; FUNC-LABEL: {{^}}multiple_structs:
156; OPT-LABEL: @multiple_structs(
157
158; R600-NOT: MOVA_INT
159; SI-NOT: v_movrel
160; SI-NOT: v_movrel
161%struct.point = type { i32, i32 }
162
163define void @multiple_structs(i32 addrspace(1)* %out) {
164entry:
165  %a = alloca %struct.point
166  %b = alloca %struct.point
167  %a.x.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 0
168  %a.y.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 1
169  %b.x.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 0
170  %b.y.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 1
171  store i32 0, i32* %a.x.ptr
172  store i32 1, i32* %a.y.ptr
173  store i32 2, i32* %b.x.ptr
174  store i32 3, i32* %b.y.ptr
175  %a.indirect.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 0
176  %b.indirect.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 0
177  %a.indirect = load i32, i32* %a.indirect.ptr
178  %b.indirect = load i32, i32* %b.indirect.ptr
179  %0 = add i32 %a.indirect, %b.indirect
180  store i32 %0, i32 addrspace(1)* %out
181  ret void
182}
183
184; Test direct access of a private array inside a loop.  The private array
185; loads and stores should be lowered to copies, so there shouldn't be any
186; MOVA instructions.
187
188; FUNC-LABEL: {{^}}direct_loop:
189; R600-NOT: MOVA_INT
190; SI-NOT: v_movrel
191
192define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
193entry:
194  %prv_array_const = alloca [2 x i32]
195  %prv_array = alloca [2 x i32]
196  %a = load i32, i32 addrspace(1)* %in
197  %b_src_ptr = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1
198  %b = load i32, i32 addrspace(1)* %b_src_ptr
199  %a_dst_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0
200  store i32 %a, i32* %a_dst_ptr
201  %b_dst_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 1
202  store i32 %b, i32* %b_dst_ptr
203  br label %for.body
204
205for.body:
206  %inc = phi i32 [0, %entry], [%count, %for.body]
207  %x_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0
208  %x = load i32, i32* %x_ptr
209  %y_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0
210  %y = load i32, i32* %y_ptr
211  %xy = add i32 %x, %y
212  store i32 %xy, i32* %y_ptr
213  %count = add i32 %inc, 1
214  %done = icmp eq i32 %count, 4095
215  br i1 %done, label %for.end, label %for.body
216
217for.end:
218  %value_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0
219  %value = load i32, i32* %value_ptr
220  store i32 %value, i32 addrspace(1)* %out
221  ret void
222}
223
224; FUNC-LABEL: {{^}}short_array:
225
226; R600: MOVA_INT
227
228; SI-PROMOTE-DAG: buffer_store_short v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x68,0xe0
229; SI-PROMOTE-DAG: buffer_store_short v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:2 ; encoding: [0x02,0x10,0x68,0xe0
230; SI-PROMOTE: buffer_load_sshort v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}}
231define void @short_array(i32 addrspace(1)* %out, i32 %index) {
232entry:
233  %0 = alloca [2 x i16]
234  %1 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 0
235  %2 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 1
236  store i16 0, i16* %1
237  store i16 1, i16* %2
238  %3 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 %index
239  %4 = load i16, i16* %3
240  %5 = sext i16 %4 to i32
241  store i32 %5, i32 addrspace(1)* %out
242  ret void
243}
244
245; FUNC-LABEL: {{^}}char_array:
246
247; R600: MOVA_INT
248
249; SI-DAG: buffer_store_byte v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x60,0xe0
250; SI-DAG: buffer_store_byte v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:1 ; encoding: [0x01,0x10,0x60,0xe0
251define void @char_array(i32 addrspace(1)* %out, i32 %index) {
252entry:
253  %0 = alloca [2 x i8]
254  %1 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 0
255  %2 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 1
256  store i8 0, i8* %1
257  store i8 1, i8* %2
258  %3 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 %index
259  %4 = load i8, i8* %3
260  %5 = sext i8 %4 to i32
261  store i32 %5, i32 addrspace(1)* %out
262  ret void
263
264}
265
266
267; Test that two stack objects are not stored in the same register
268; The second stack object should be in T3.X
269; FUNC-LABEL: {{^}}no_overlap:
270; R600_CHECK: MOV
271; R600_CHECK: [[CHAN:[XYZW]]]+
272; R600-NOT: [[CHAN]]+
273; SI: v_mov_b32_e32 v3
274define void @no_overlap(i32 addrspace(1)* %out, i32 %in) {
275entry:
276  %0 = alloca [3 x i8], align 1
277  %1 = alloca [2 x i8], align 1
278  %2 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 0
279  %3 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 1
280  %4 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 2
281  %5 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 0
282  %6 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 1
283  store i8 0, i8* %2
284  store i8 1, i8* %3
285  store i8 2, i8* %4
286  store i8 1, i8* %5
287  store i8 0, i8* %6
288  %7 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 %in
289  %8 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 %in
290  %9 = load i8, i8* %7
291  %10 = load i8, i8* %8
292  %11 = add i8 %9, %10
293  %12 = sext i8 %11 to i32
294  store i32 %12, i32 addrspace(1)* %out
295  ret void
296}
297
298define void @char_array_array(i32 addrspace(1)* %out, i32 %index) {
299entry:
300  %alloca = alloca [2 x [2 x i8]]
301  %gep0 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 0
302  %gep1 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 1
303  store i8 0, i8* %gep0
304  store i8 1, i8* %gep1
305  %gep2 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 %index
306  %load = load i8, i8* %gep2
307  %sext = sext i8 %load to i32
308  store i32 %sext, i32 addrspace(1)* %out
309  ret void
310}
311
312define void @i32_array_array(i32 addrspace(1)* %out, i32 %index) {
313entry:
314  %alloca = alloca [2 x [2 x i32]]
315  %gep0 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 0
316  %gep1 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 1
317  store i32 0, i32* %gep0
318  store i32 1, i32* %gep1
319  %gep2 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 %index
320  %load = load i32, i32* %gep2
321  store i32 %load, i32 addrspace(1)* %out
322  ret void
323}
324
325define void @i64_array_array(i64 addrspace(1)* %out, i32 %index) {
326entry:
327  %alloca = alloca [2 x [2 x i64]]
328  %gep0 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 0
329  %gep1 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 1
330  store i64 0, i64* %gep0
331  store i64 1, i64* %gep1
332  %gep2 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 %index
333  %load = load i64, i64* %gep2
334  store i64 %load, i64 addrspace(1)* %out
335  ret void
336}
337
338%struct.pair32 = type { i32, i32 }
339
340define void @struct_array_array(i32 addrspace(1)* %out, i32 %index) {
341entry:
342  %alloca = alloca [2 x [2 x %struct.pair32]]
343  %gep0 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 0, i32 1
344  %gep1 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 1, i32 1
345  store i32 0, i32* %gep0
346  store i32 1, i32* %gep1
347  %gep2 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 %index, i32 0
348  %load = load i32, i32* %gep2
349  store i32 %load, i32 addrspace(1)* %out
350  ret void
351}
352
353define void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) {
354entry:
355  %alloca = alloca [2 x %struct.pair32]
356  %gep0 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 0, i32 1
357  %gep1 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 1, i32 0
358  store i32 0, i32* %gep0
359  store i32 1, i32* %gep1
360  %gep2 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 %index, i32 0
361  %load = load i32, i32* %gep2
362  store i32 %load, i32 addrspace(1)* %out
363  ret void
364}
365
366define void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind {
367entry:
368  %tmp = alloca [2 x i32]
369  %tmp1 = getelementptr [2 x i32], [2 x i32]* %tmp, i32 0, i32 0
370  %tmp2 = getelementptr [2 x i32], [2 x i32]* %tmp, i32 0, i32 1
371  store i32 0, i32* %tmp1
372  store i32 1, i32* %tmp2
373  %cmp = icmp eq i32 %in, 0
374  %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2
375  %load = load i32, i32* %sel
376  store i32 %load, i32 addrspace(1)* %out
377  ret void
378}
379
380; AMDGPUPromoteAlloca does not know how to handle ptrtoint.  When it
381; finds one, it should stop trying to promote.
382
383; FUNC-LABEL: ptrtoint:
384; SI-NOT: ds_write
385; SI: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen
386; SI: buffer_load_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:5 ;
387define void @ptrtoint(i32 addrspace(1)* %out, i32 %a, i32 %b) {
388  %alloca = alloca [16 x i32]
389  %tmp0 = getelementptr [16 x i32], [16 x i32]* %alloca, i32 0, i32 %a
390  store i32 5, i32* %tmp0
391  %tmp1 = ptrtoint [16 x i32]* %alloca to i32
392  %tmp2 = add i32 %tmp1, 5
393  %tmp3 = inttoptr i32 %tmp2 to i32*
394  %tmp4 = getelementptr i32, i32* %tmp3, i32 %b
395  %tmp5 = load i32, i32* %tmp4
396  store i32 %tmp5, i32 addrspace(1)* %out
397  ret void
398}
399
400; HSAOPT: !0 = !{}
401; HSAOPT: !1 = !{i32 0, i32 2048}
402
403; NOHSAOPT: !0 = !{i32 0, i32 2048}
404