blob: 79778eebd802b7a3d358ed58eb9e3100df19346b [file] [log] [blame]
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +00001; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck %s -check-prefix=R600 -check-prefix=FUNC
Tom Stellard49f8bfd2015-01-06 18:00:21 +00002; RUN: llc -show-mc-encoding -mattr=+promote-alloca -verify-machineinstrs -march=amdgcn -mcpu=SI < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC
Tom Stellard7750f4e2015-12-15 23:15:25 +00003; 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
Tom Stellard49f8bfd2015-01-06 18:00:21 +00004; RUN: llc -show-mc-encoding -mattr=-promote-alloca -verify-machineinstrs -march=amdgcn -mcpu=SI < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC
Tom Stellarda4953072015-12-15 22:55:30 +00005; 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
Marek Olsakfa6607d2015-02-11 14:26:46 +00006; 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
Tom Stellardaad53762013-06-05 03:43:06 +00008
Matt Arsenault6995dd92014-06-27 03:55:55 +00009declare i32 @llvm.r600.read.tidig.x() nounwind readnone
10
Tom Stellard79243d92014-10-01 17:15:17 +000011; FUNC-LABEL: {{^}}mova_same_clause:
Tom Stellarde9373602014-01-22 19:24:14 +000012
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +000013; R600: LDS_WRITE
14; R600: LDS_WRITE
15; R600: LDS_READ
16; R600: LDS_READ
Tom Stellardaad53762013-06-05 03:43:06 +000017
Tom Stellard7750f4e2015-12-15 23:15:25 +000018; HSA-PROMOTE: .amd_kernel_code_t
19; HSA-PROMOTE: workgroup_group_segment_byte_size = 5120
20; HSA-PROMOTE: .end_amd_kernel_code_t
21
Tom Stellard326d6ec2014-11-05 14:50:53 +000022; SI-PROMOTE: ds_write_b32
23; SI-PROMOTE: ds_write_b32
24; SI-PROMOTE: ds_read_b32
25; SI-PROMOTE: ds_read_b32
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +000026
Tom Stellarda4953072015-12-15 22:55:30 +000027; HSA-ALLOCA: .amd_kernel_code_t
28; FIXME: Creating the emergency stack slots causes us to over-estimate scratch
29; by 4 bytes.
30; HSA-ALLOCA: workitem_private_segment_byte_size = 24
31; HSA-ALLOCA: .end_amd_kernel_code_t
32
Tom Stellard326d6ec2014-11-05 14:50:53 +000033; 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
34; 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
Tom Stellardaad53762013-06-05 03:43:06 +000035define void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) {
36entry:
37 %stack = alloca [5 x i32], align 4
David Blaikiea79ac142015-02-27 21:17:42 +000038 %0 = load i32, i32 addrspace(1)* %in, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000039 %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %0
Tom Stellardaad53762013-06-05 03:43:06 +000040 store i32 4, i32* %arrayidx1, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000041 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1
David Blaikiea79ac142015-02-27 21:17:42 +000042 %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000043 %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %1
Tom Stellardaad53762013-06-05 03:43:06 +000044 store i32 5, i32* %arrayidx3, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000045 %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +000046 %2 = load i32, i32* %arrayidx10, align 4
Tom Stellardaad53762013-06-05 03:43:06 +000047 store i32 %2, i32 addrspace(1)* %out, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000048 %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 1
David Blaikiea79ac142015-02-27 21:17:42 +000049 %3 = load i32, i32* %arrayidx12
David Blaikie79e6c742015-02-27 19:29:02 +000050 %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1
Tom Stellardaad53762013-06-05 03:43:06 +000051 store i32 %3, i32 addrspace(1)* %arrayidx13
52 ret void
53}
Tom Stellardd7458372013-06-07 20:52:05 +000054
55; This test checks that the stack offset is calculated correctly for structs.
56; All register loads/stores should be optimized away, so there shouldn't be
57; any MOVA instructions.
58;
59; XXX: This generated code has unnecessary MOVs, we should be able to optimize
60; this.
61
Tom Stellard79243d92014-10-01 17:15:17 +000062; FUNC-LABEL: {{^}}multiple_structs:
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +000063; R600-NOT: MOVA_INT
Tom Stellard326d6ec2014-11-05 14:50:53 +000064; SI-NOT: v_movrel
65; SI-NOT: v_movrel
Tom Stellardd7458372013-06-07 20:52:05 +000066%struct.point = type { i32, i32 }
67
68define void @multiple_structs(i32 addrspace(1)* %out) {
69entry:
70 %a = alloca %struct.point
71 %b = alloca %struct.point
David Blaikie79e6c742015-02-27 19:29:02 +000072 %a.x.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 0
73 %a.y.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 1
74 %b.x.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 0
75 %b.y.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 1
Tom Stellardd7458372013-06-07 20:52:05 +000076 store i32 0, i32* %a.x.ptr
77 store i32 1, i32* %a.y.ptr
78 store i32 2, i32* %b.x.ptr
79 store i32 3, i32* %b.y.ptr
David Blaikie79e6c742015-02-27 19:29:02 +000080 %a.indirect.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 0
81 %b.indirect.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +000082 %a.indirect = load i32, i32* %a.indirect.ptr
83 %b.indirect = load i32, i32* %b.indirect.ptr
Tom Stellardd7458372013-06-07 20:52:05 +000084 %0 = add i32 %a.indirect, %b.indirect
85 store i32 %0, i32 addrspace(1)* %out
86 ret void
87}
Tom Stellard26a3b672013-10-22 18:19:10 +000088
89; Test direct access of a private array inside a loop. The private array
90; loads and stores should be lowered to copies, so there shouldn't be any
91; MOVA instructions.
92
Tom Stellard79243d92014-10-01 17:15:17 +000093; FUNC-LABEL: {{^}}direct_loop:
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +000094; R600-NOT: MOVA_INT
Tom Stellard326d6ec2014-11-05 14:50:53 +000095; SI-NOT: v_movrel
Tom Stellard26a3b672013-10-22 18:19:10 +000096
97define void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) {
98entry:
99 %prv_array_const = alloca [2 x i32]
100 %prv_array = alloca [2 x i32]
David Blaikiea79ac142015-02-27 21:17:42 +0000101 %a = load i32, i32 addrspace(1)* %in
David Blaikie79e6c742015-02-27 19:29:02 +0000102 %b_src_ptr = getelementptr i32, i32 addrspace(1)* %in, i32 1
David Blaikiea79ac142015-02-27 21:17:42 +0000103 %b = load i32, i32 addrspace(1)* %b_src_ptr
David Blaikie79e6c742015-02-27 19:29:02 +0000104 %a_dst_ptr = getelementptr [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0
Tom Stellard26a3b672013-10-22 18:19:10 +0000105 store i32 %a, i32* %a_dst_ptr
David Blaikie79e6c742015-02-27 19:29:02 +0000106 %b_dst_ptr = getelementptr [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 1
Tom Stellard26a3b672013-10-22 18:19:10 +0000107 store i32 %b, i32* %b_dst_ptr
108 br label %for.body
109
110for.body:
111 %inc = phi i32 [0, %entry], [%count, %for.body]
David Blaikie79e6c742015-02-27 19:29:02 +0000112 %x_ptr = getelementptr [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +0000113 %x = load i32, i32* %x_ptr
David Blaikie79e6c742015-02-27 19:29:02 +0000114 %y_ptr = getelementptr [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +0000115 %y = load i32, i32* %y_ptr
Tom Stellard26a3b672013-10-22 18:19:10 +0000116 %xy = add i32 %x, %y
117 store i32 %xy, i32* %y_ptr
118 %count = add i32 %inc, 1
119 %done = icmp eq i32 %count, 4095
120 br i1 %done, label %for.end, label %for.body
121
122for.end:
David Blaikie79e6c742015-02-27 19:29:02 +0000123 %value_ptr = getelementptr [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +0000124 %value = load i32, i32* %value_ptr
Tom Stellard26a3b672013-10-22 18:19:10 +0000125 store i32 %value, i32 addrspace(1)* %out
126 ret void
127}
Tom Stellarde9373602014-01-22 19:24:14 +0000128
Tom Stellard79243d92014-10-01 17:15:17 +0000129; FUNC-LABEL: {{^}}short_array:
Tom Stellarde9373602014-01-22 19:24:14 +0000130
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +0000131; R600: MOVA_INT
Tom Stellarde9373602014-01-22 19:24:14 +0000132
Tom Stellard326d6ec2014-11-05 14:50:53 +0000133; 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
Matt Arsenaultfb13b222014-12-03 03:12:13 +0000134; 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
Tom Stellard326d6ec2014-11-05 14:50:53 +0000135; SI-PROMOTE: buffer_load_sshort v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}}
Tom Stellarde9373602014-01-22 19:24:14 +0000136define void @short_array(i32 addrspace(1)* %out, i32 %index) {
137entry:
138 %0 = alloca [2 x i16]
David Blaikie79e6c742015-02-27 19:29:02 +0000139 %1 = getelementptr [2 x i16], [2 x i16]* %0, i32 0, i32 0
140 %2 = getelementptr [2 x i16], [2 x i16]* %0, i32 0, i32 1
Tom Stellarde9373602014-01-22 19:24:14 +0000141 store i16 0, i16* %1
142 store i16 1, i16* %2
David Blaikie79e6c742015-02-27 19:29:02 +0000143 %3 = getelementptr [2 x i16], [2 x i16]* %0, i32 0, i32 %index
David Blaikiea79ac142015-02-27 21:17:42 +0000144 %4 = load i16, i16* %3
Tom Stellarde9373602014-01-22 19:24:14 +0000145 %5 = sext i16 %4 to i32
146 store i32 %5, i32 addrspace(1)* %out
147 ret void
148}
149
Tom Stellard79243d92014-10-01 17:15:17 +0000150; FUNC-LABEL: {{^}}char_array:
Tom Stellarde9373602014-01-22 19:24:14 +0000151
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +0000152; R600: MOVA_INT
Tom Stellarde9373602014-01-22 19:24:14 +0000153
Tom Stellard326d6ec2014-11-05 14:50:53 +0000154; 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
Matt Arsenaultfb13b222014-12-03 03:12:13 +0000155; 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
Tom Stellarde9373602014-01-22 19:24:14 +0000156define void @char_array(i32 addrspace(1)* %out, i32 %index) {
157entry:
158 %0 = alloca [2 x i8]
David Blaikie79e6c742015-02-27 19:29:02 +0000159 %1 = getelementptr [2 x i8], [2 x i8]* %0, i32 0, i32 0
160 %2 = getelementptr [2 x i8], [2 x i8]* %0, i32 0, i32 1
Tom Stellarde9373602014-01-22 19:24:14 +0000161 store i8 0, i8* %1
162 store i8 1, i8* %2
David Blaikie79e6c742015-02-27 19:29:02 +0000163 %3 = getelementptr [2 x i8], [2 x i8]* %0, i32 0, i32 %index
David Blaikiea79ac142015-02-27 21:17:42 +0000164 %4 = load i8, i8* %3
Tom Stellarde9373602014-01-22 19:24:14 +0000165 %5 = sext i8 %4 to i32
166 store i32 %5, i32 addrspace(1)* %out
167 ret void
168
169}
Tom Stellard27982b12014-01-22 19:24:19 +0000170
171; Make sure we don't overwrite workitem information with private memory
172
Tom Stellard79243d92014-10-01 17:15:17 +0000173; FUNC-LABEL: {{^}}work_item_info:
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +0000174; R600-NOT: MOV T0.X
Tom Stellard27982b12014-01-22 19:24:19 +0000175; Additional check in case the move ends up in the last slot
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +0000176; R600-NOT: MOV * TO.X
Tom Stellard27982b12014-01-22 19:24:19 +0000177
Tom Stellard326d6ec2014-11-05 14:50:53 +0000178; SI-NOT: v_mov_b32_e{{(32|64)}} v0
Tom Stellard27982b12014-01-22 19:24:19 +0000179define void @work_item_info(i32 addrspace(1)* %out, i32 %in) {
180entry:
181 %0 = alloca [2 x i32]
David Blaikie79e6c742015-02-27 19:29:02 +0000182 %1 = getelementptr [2 x i32], [2 x i32]* %0, i32 0, i32 0
183 %2 = getelementptr [2 x i32], [2 x i32]* %0, i32 0, i32 1
Tom Stellard27982b12014-01-22 19:24:19 +0000184 store i32 0, i32* %1
185 store i32 1, i32* %2
David Blaikie79e6c742015-02-27 19:29:02 +0000186 %3 = getelementptr [2 x i32], [2 x i32]* %0, i32 0, i32 %in
David Blaikiea79ac142015-02-27 21:17:42 +0000187 %4 = load i32, i32* %3
Tom Stellard27982b12014-01-22 19:24:19 +0000188 %5 = call i32 @llvm.r600.read.tidig.x()
189 %6 = add i32 %4, %5
190 store i32 %6, i32 addrspace(1)* %out
191 ret void
192}
193
Tom Stellard598f3942014-01-22 19:24:23 +0000194; Test that two stack objects are not stored in the same register
195; The second stack object should be in T3.X
Tom Stellard79243d92014-10-01 17:15:17 +0000196; FUNC-LABEL: {{^}}no_overlap:
Tom Stellard880a80a2014-06-17 16:53:14 +0000197; R600_CHECK: MOV
198; R600_CHECK: [[CHAN:[XYZW]]]+
Matt Arsenaultd0b6f3e2014-07-13 02:18:06 +0000199; R600-NOT: [[CHAN]]+
Tom Stellard326d6ec2014-11-05 14:50:53 +0000200; SI: v_mov_b32_e32 v3
Tom Stellard598f3942014-01-22 19:24:23 +0000201define void @no_overlap(i32 addrspace(1)* %out, i32 %in) {
202entry:
203 %0 = alloca [3 x i8], align 1
204 %1 = alloca [2 x i8], align 1
David Blaikie79e6c742015-02-27 19:29:02 +0000205 %2 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 0
206 %3 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 1
207 %4 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 2
208 %5 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 0
209 %6 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 1
Tom Stellard598f3942014-01-22 19:24:23 +0000210 store i8 0, i8* %2
211 store i8 1, i8* %3
212 store i8 2, i8* %4
213 store i8 1, i8* %5
214 store i8 0, i8* %6
David Blaikie79e6c742015-02-27 19:29:02 +0000215 %7 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 %in
216 %8 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 %in
David Blaikiea79ac142015-02-27 21:17:42 +0000217 %9 = load i8, i8* %7
218 %10 = load i8, i8* %8
Tom Stellard598f3942014-01-22 19:24:23 +0000219 %11 = add i8 %9, %10
220 %12 = sext i8 %11 to i32
221 store i32 %12, i32 addrspace(1)* %out
222 ret void
223}
224
Matt Arsenault6995dd92014-06-27 03:55:55 +0000225define void @char_array_array(i32 addrspace(1)* %out, i32 %index) {
226entry:
227 %alloca = alloca [2 x [2 x i8]]
David Blaikie79e6c742015-02-27 19:29:02 +0000228 %gep0 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 0
229 %gep1 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 1
Matt Arsenault6995dd92014-06-27 03:55:55 +0000230 store i8 0, i8* %gep0
231 store i8 1, i8* %gep1
David Blaikie79e6c742015-02-27 19:29:02 +0000232 %gep2 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 %index
David Blaikiea79ac142015-02-27 21:17:42 +0000233 %load = load i8, i8* %gep2
Matt Arsenault6995dd92014-06-27 03:55:55 +0000234 %sext = sext i8 %load to i32
235 store i32 %sext, i32 addrspace(1)* %out
236 ret void
237}
Tom Stellard598f3942014-01-22 19:24:23 +0000238
Matt Arsenault6995dd92014-06-27 03:55:55 +0000239define void @i32_array_array(i32 addrspace(1)* %out, i32 %index) {
240entry:
241 %alloca = alloca [2 x [2 x i32]]
David Blaikie79e6c742015-02-27 19:29:02 +0000242 %gep0 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 0
243 %gep1 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 1
Matt Arsenault6995dd92014-06-27 03:55:55 +0000244 store i32 0, i32* %gep0
245 store i32 1, i32* %gep1
David Blaikie79e6c742015-02-27 19:29:02 +0000246 %gep2 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 %index
David Blaikiea79ac142015-02-27 21:17:42 +0000247 %load = load i32, i32* %gep2
Matt Arsenault6995dd92014-06-27 03:55:55 +0000248 store i32 %load, i32 addrspace(1)* %out
249 ret void
250}
Tom Stellard598f3942014-01-22 19:24:23 +0000251
Matt Arsenault6995dd92014-06-27 03:55:55 +0000252define void @i64_array_array(i64 addrspace(1)* %out, i32 %index) {
253entry:
254 %alloca = alloca [2 x [2 x i64]]
David Blaikie79e6c742015-02-27 19:29:02 +0000255 %gep0 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 0
256 %gep1 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 1
Matt Arsenault6995dd92014-06-27 03:55:55 +0000257 store i64 0, i64* %gep0
258 store i64 1, i64* %gep1
David Blaikie79e6c742015-02-27 19:29:02 +0000259 %gep2 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 %index
David Blaikiea79ac142015-02-27 21:17:42 +0000260 %load = load i64, i64* %gep2
Matt Arsenault6995dd92014-06-27 03:55:55 +0000261 store i64 %load, i64 addrspace(1)* %out
262 ret void
263}
264
265%struct.pair32 = type { i32, i32 }
266
267define void @struct_array_array(i32 addrspace(1)* %out, i32 %index) {
268entry:
269 %alloca = alloca [2 x [2 x %struct.pair32]]
David Blaikie79e6c742015-02-27 19:29:02 +0000270 %gep0 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 0, i32 1
271 %gep1 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 1, i32 1
Matt Arsenault6995dd92014-06-27 03:55:55 +0000272 store i32 0, i32* %gep0
273 store i32 1, i32* %gep1
David Blaikie79e6c742015-02-27 19:29:02 +0000274 %gep2 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 %index, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +0000275 %load = load i32, i32* %gep2
Matt Arsenault6995dd92014-06-27 03:55:55 +0000276 store i32 %load, i32 addrspace(1)* %out
277 ret void
278}
279
280define void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) {
281entry:
282 %alloca = alloca [2 x %struct.pair32]
David Blaikie79e6c742015-02-27 19:29:02 +0000283 %gep0 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 0, i32 1
284 %gep1 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 1, i32 0
Matt Arsenault6995dd92014-06-27 03:55:55 +0000285 store i32 0, i32* %gep0
286 store i32 1, i32* %gep1
David Blaikie79e6c742015-02-27 19:29:02 +0000287 %gep2 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 %index, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +0000288 %load = load i32, i32* %gep2
Matt Arsenault6995dd92014-06-27 03:55:55 +0000289 store i32 %load, i32 addrspace(1)* %out
290 ret void
Matt Arsenault6995dd92014-06-27 03:55:55 +0000291}
Matt Arsenault642d2e72014-06-27 16:52:49 +0000292
293define void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind {
294entry:
295 %tmp = alloca [2 x i32]
David Blaikie79e6c742015-02-27 19:29:02 +0000296 %tmp1 = getelementptr [2 x i32], [2 x i32]* %tmp, i32 0, i32 0
297 %tmp2 = getelementptr [2 x i32], [2 x i32]* %tmp, i32 0, i32 1
Matt Arsenault642d2e72014-06-27 16:52:49 +0000298 store i32 0, i32* %tmp1
299 store i32 1, i32* %tmp2
300 %cmp = icmp eq i32 %in, 0
301 %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2
David Blaikiea79ac142015-02-27 21:17:42 +0000302 %load = load i32, i32* %sel
Matt Arsenault642d2e72014-06-27 16:52:49 +0000303 store i32 %load, i32 addrspace(1)* %out
304 ret void
305}
306
Tom Stellard5b2927f2014-10-31 20:52:04 +0000307; AMDGPUPromoteAlloca does not know how to handle ptrtoint. When it
308; finds one, it should stop trying to promote.
309
310; FUNC-LABEL: ptrtoint:
Tom Stellard326d6ec2014-11-05 14:50:53 +0000311; SI-NOT: ds_write
312; SI: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen
Tom Stellard78655fc2015-07-16 19:40:09 +0000313; SI: buffer_load_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ;
Tom Stellard5b2927f2014-10-31 20:52:04 +0000314define void @ptrtoint(i32 addrspace(1)* %out, i32 %a, i32 %b) {
315 %alloca = alloca [16 x i32]
David Blaikie79e6c742015-02-27 19:29:02 +0000316 %tmp0 = getelementptr [16 x i32], [16 x i32]* %alloca, i32 0, i32 %a
Tom Stellard5b2927f2014-10-31 20:52:04 +0000317 store i32 5, i32* %tmp0
318 %tmp1 = ptrtoint [16 x i32]* %alloca to i32
319 %tmp2 = add i32 %tmp1, 5
320 %tmp3 = inttoptr i32 %tmp2 to i32*
David Blaikie79e6c742015-02-27 19:29:02 +0000321 %tmp4 = getelementptr i32, i32* %tmp3, i32 %b
David Blaikiea79ac142015-02-27 21:17:42 +0000322 %tmp5 = load i32, i32* %tmp4
Tom Stellard5b2927f2014-10-31 20:52:04 +0000323 store i32 %tmp5, i32 addrspace(1)* %out
324 ret void
325}