Revert 239644.
[oota-llvm.git] / test / CodeGen / R600 / cgp-addressing-modes.ll
1 ; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown < %s | FileCheck -check-prefix=OPT %s
2 ; RUN: llc -march=amdgcn -mcpu=bonaire -mattr=-promote-alloca < %s | FileCheck -check-prefix=GCN %s
3
4 declare i32 @llvm.r600.read.tidig.x() #0
5
6 ; OPT-LABEL: @test_sink_global_small_offset_i32(
7 ; OPT-NOT: getelementptr i32, i32 addrspace(1)* %in
8 ; OPT: br i1
9 ; OPT: ptrtoint
10
11 ; GCN-LABEL: {{^}}test_sink_global_small_offset_i32:
12 ; GCN: {{^}}BB0_2:
13 define void @test_sink_global_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %cond) {
14 entry:
15   %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
16   %in.gep = getelementptr i32, i32 addrspace(1)* %in, i64 7
17   %tmp0 = icmp eq i32 %cond, 0
18   br i1 %tmp0, label %endif, label %if
19
20 if:
21   %tmp1 = load i32, i32 addrspace(1)* %in.gep
22   br label %endif
23
24 endif:
25   %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
26   store i32 %x, i32 addrspace(1)* %out.gep
27   br label %done
28
29 done:
30   ret void
31 }
32
33 ; OPT-LABEL: @test_sink_global_small_max_i32_ds_offset(
34 ; OPT: %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 65535
35 ; OPT: br i1
36
37 ; GCN-LABEL: {{^}}test_sink_global_small_max_i32_ds_offset:
38 ; GCN: s_and_saveexec_b64
39 ; GCN: buffer_load_sbyte {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, s{{[0-9]+$}}
40 ; GCN: {{^}}BB1_2:
41 ; GCN: s_or_b64 exec
42 define void @test_sink_global_small_max_i32_ds_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in, i32 %cond) {
43 entry:
44   %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 99999
45   %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 65535
46   %tmp0 = icmp eq i32 %cond, 0
47   br i1 %tmp0, label %endif, label %if
48
49 if:
50   %tmp1 = load i8, i8 addrspace(1)* %in.gep
51   %tmp2 = sext i8 %tmp1 to i32
52   br label %endif
53
54 endif:
55   %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
56   store i32 %x, i32 addrspace(1)* %out.gep
57   br label %done
58
59 done:
60   ret void
61 }
62
63 ; GCN-LABEL: {{^}}test_sink_global_small_max_mubuf_offset:
64 ; GCN: s_and_saveexec_b64
65 ; GCN: buffer_load_sbyte {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:4095{{$}}
66 ; GCN: {{^}}BB2_2:
67 ; GCN: s_or_b64 exec
68 define void @test_sink_global_small_max_mubuf_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in, i32 %cond) {
69 entry:
70   %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 1024
71   %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 4095
72   %tmp0 = icmp eq i32 %cond, 0
73   br i1 %tmp0, label %endif, label %if
74
75 if:
76   %tmp1 = load i8, i8 addrspace(1)* %in.gep
77   %tmp2 = sext i8 %tmp1 to i32
78   br label %endif
79
80 endif:
81   %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
82   store i32 %x, i32 addrspace(1)* %out.gep
83   br label %done
84
85 done:
86   ret void
87 }
88
89 ; GCN-LABEL: {{^}}test_sink_global_small_max_plus_1_mubuf_offset:
90 ; GCN: s_and_saveexec_b64
91 ; GCN: buffer_load_sbyte {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, s{{[0-9]+$}}
92 ; GCN: {{^}}BB3_2:
93 ; GCN: s_or_b64 exec
94 define void @test_sink_global_small_max_plus_1_mubuf_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in, i32 %cond) {
95 entry:
96   %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 99999
97   %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 4096
98   %tmp0 = icmp eq i32 %cond, 0
99   br i1 %tmp0, label %endif, label %if
100
101 if:
102   %tmp1 = load i8, i8 addrspace(1)* %in.gep
103   %tmp2 = sext i8 %tmp1 to i32
104   br label %endif
105
106 endif:
107   %x = phi i32 [ %tmp2, %if ], [ 0, %entry ]
108   store i32 %x, i32 addrspace(1)* %out.gep
109   br label %done
110
111 done:
112   ret void
113 }
114
115 ; OPT-LABEL: @test_no_sink_flat_small_offset_i32(
116 ; OPT: getelementptr i32, i32 addrspace(4)* %in
117 ; OPT: br i1
118 ; OPT-NOT: ptrtoint
119
120 ; GCN-LABEL: {{^}}test_no_sink_flat_small_offset_i32:
121 ; GCN: flat_load_dword
122 ; GCN: {{^}}BB4_2:
123
124 define void @test_no_sink_flat_small_offset_i32(i32 addrspace(4)* %out, i32 addrspace(4)* %in, i32 %cond) {
125 entry:
126   %out.gep = getelementptr i32, i32 addrspace(4)* %out, i64 999999
127   %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 7
128   %tmp0 = icmp eq i32 %cond, 0
129   br i1 %tmp0, label %endif, label %if
130
131 if:
132   %tmp1 = load i32, i32 addrspace(4)* %in.gep
133   br label %endif
134
135 endif:
136   %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
137   store i32 %x, i32 addrspace(4)* %out.gep
138   br label %done
139
140 done:
141   ret void
142 }
143
144 ; OPT-LABEL: @test_sink_scratch_small_offset_i32(
145 ; OPT-NOT:  getelementptr [512 x i32]
146 ; OPT: br i1
147 ; OPT: ptrtoint
148
149 ; GCN-LABEL: {{^}}test_sink_scratch_small_offset_i32:
150 ; GCN: s_and_saveexec_b64
151 ; GCN: buffer_store_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen offset:4092{{$}}
152 ; GCN: buffer_load_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen offset:4092{{$}}
153 ; GCN: {{^}}BB5_2:
154 define void @test_sink_scratch_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %cond, i32 %arg) {
155 entry:
156   %alloca = alloca [512 x i32], align 4
157   %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998
158   %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999
159   %add.arg = add i32 %arg, 8
160   %alloca.gep = getelementptr [512 x i32], [512 x i32]* %alloca, i32 0, i32 1023
161   %tmp0 = icmp eq i32 %cond, 0
162   br i1 %tmp0, label %endif, label %if
163
164 if:
165   store volatile i32 123, i32* %alloca.gep
166   %tmp1 = load volatile i32, i32* %alloca.gep
167   br label %endif
168
169 endif:
170   %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
171   store i32 %x, i32 addrspace(1)* %out.gep.0
172   %load = load volatile i32, i32* %alloca.gep
173   store i32 %load, i32 addrspace(1)* %out.gep.1
174   br label %done
175
176 done:
177   ret void
178 }
179
180 ; OPT-LABEL: @test_no_sink_scratch_large_offset_i32(
181 ; OPT: %alloca.gep = getelementptr [512 x i32], [512 x i32]* %alloca, i32 0, i32 1024
182 ; OPT: br i1
183 ; OPT-NOT: ptrtoint
184
185 ; GCN-LABEL: {{^}}test_no_sink_scratch_large_offset_i32:
186 ; GCN: s_and_saveexec_b64
187 ; GCN: buffer_store_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen{{$}}
188 ; GCN: buffer_load_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen{{$}}
189 ; GCN: {{^}}BB6_2:
190 define void @test_no_sink_scratch_large_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %cond, i32 %arg) {
191 entry:
192   %alloca = alloca [512 x i32], align 4
193   %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998
194   %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999
195   %add.arg = add i32 %arg, 8
196   %alloca.gep = getelementptr [512 x i32], [512 x i32]* %alloca, i32 0, i32 1024
197   %tmp0 = icmp eq i32 %cond, 0
198   br i1 %tmp0, label %endif, label %if
199
200 if:
201   store volatile i32 123, i32* %alloca.gep
202   %tmp1 = load volatile i32, i32* %alloca.gep
203   br label %endif
204
205 endif:
206   %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
207   store i32 %x, i32 addrspace(1)* %out.gep.0
208   %load = load volatile i32, i32* %alloca.gep
209   store i32 %load, i32 addrspace(1)* %out.gep.1
210   br label %done
211
212 done:
213   ret void
214 }
215
216 ; GCN-LABEL: {{^}}test_sink_global_vreg_sreg_i32:
217 ; GCN: s_and_saveexec_b64
218 ; GCN: buffer_load_dword {{v[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}}
219 ; GCN: {{^}}BB7_2:
220 define void @test_sink_global_vreg_sreg_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %offset, i32 %cond) {
221 entry:
222   %offset.ext = zext i32 %offset to i64
223   %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999
224   %in.gep = getelementptr i32, i32 addrspace(1)* %in, i64 %offset.ext
225   %tmp0 = icmp eq i32 %cond, 0
226   br i1 %tmp0, label %endif, label %if
227
228 if:
229   %tmp1 = load i32, i32 addrspace(1)* %in.gep
230   br label %endif
231
232 endif:
233   %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
234   store i32 %x, i32 addrspace(1)* %out.gep
235   br label %done
236
237 done:
238   ret void
239 }
240
241 attributes #0 = { nounwind readnone }
242 attributes #1 = { nounwind }