1 ; RUN: opt -S -bdce -instsimplify < %s | FileCheck %s
2 ; RUN: opt -S -instsimplify < %s | FileCheck %s -check-prefix=CHECK-IO
3 target datalayout = "E-m:e-i64:64-n32:64"
4 target triple = "powerpc64-unknown-linux-gnu"
6 ; Function Attrs: nounwind readnone
7 define signext i32 @bar(i32 signext %x) #0 {
9 %call = tail call signext i32 @foo(i32 signext 5) #0
10 %and = and i32 %call, 4
12 %call1 = tail call signext i32 @foo(i32 signext 3) #0
13 %and2 = and i32 %call1, 8
14 %or3 = or i32 %or, %and2
15 %call4 = tail call signext i32 @foo(i32 signext 2) #0
16 %and5 = and i32 %call4, 16
17 %or6 = or i32 %or3, %and5
18 %call7 = tail call signext i32 @foo(i32 signext 1) #0
19 %and8 = and i32 %call7, 32
20 %or9 = or i32 %or6, %and8
21 %call10 = tail call signext i32 @foo(i32 signext 0) #0
22 %and11 = and i32 %call10, 64
23 %or12 = or i32 %or9, %and11
24 %call13 = tail call signext i32 @foo(i32 signext 4) #0
25 %and14 = and i32 %call13, 128
26 %or15 = or i32 %or12, %and14
27 %shr = ashr i32 %or15, 4
31 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
32 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
33 ; CHECK: tail call signext i32 @foo(i32 signext 2)
34 ; CHECK: tail call signext i32 @foo(i32 signext 1)
35 ; CHECK: tail call signext i32 @foo(i32 signext 0)
36 ; CHECK: tail call signext i32 @foo(i32 signext 4)
39 ; Check that instsimplify is not doing this all on its own.
40 ; CHECK-IO-LABEL: @bar
41 ; CHECK-IO: tail call signext i32 @foo(i32 signext 5)
42 ; CHECK-IO: tail call signext i32 @foo(i32 signext 3)
43 ; CHECK-IO: tail call signext i32 @foo(i32 signext 2)
44 ; CHECK-IO: tail call signext i32 @foo(i32 signext 1)
45 ; CHECK-IO: tail call signext i32 @foo(i32 signext 0)
46 ; CHECK-IO: tail call signext i32 @foo(i32 signext 4)
50 ; Function Attrs: nounwind readnone
51 declare signext i32 @foo(i32 signext) #0
53 ; Function Attrs: nounwind readnone
54 define signext i32 @far(i32 signext %x) #1 {
56 %call = tail call signext i32 @goo(i32 signext 5) #1
57 %and = and i32 %call, 4
59 %call1 = tail call signext i32 @goo(i32 signext 3) #1
60 %and2 = and i32 %call1, 8
61 %or3 = or i32 %or, %and2
62 %call4 = tail call signext i32 @goo(i32 signext 2) #1
63 %and5 = and i32 %call4, 16
64 %or6 = or i32 %or3, %and5
65 %call7 = tail call signext i32 @goo(i32 signext 1) #1
66 %and8 = and i32 %call7, 32
67 %or9 = or i32 %or6, %and8
68 %call10 = tail call signext i32 @goo(i32 signext 0) #1
69 %and11 = and i32 %call10, 64
70 %or12 = or i32 %or9, %and11
71 %call13 = tail call signext i32 @goo(i32 signext 4) #1
72 %and14 = and i32 %call13, 128
73 %or15 = or i32 %or12, %and14
74 %shr = ashr i32 %or15, 4
78 ; Calls to foo(5) and foo(3) are still there, but their results are not used.
79 ; CHECK: tail call signext i32 @goo(i32 signext 5)
80 ; CHECK-NEXT: tail call signext i32 @goo(i32 signext 3)
81 ; CHECK-NEXT: tail call signext i32 @goo(i32 signext 2)
82 ; CHECK: tail call signext i32 @goo(i32 signext 1)
83 ; CHECK: tail call signext i32 @goo(i32 signext 0)
84 ; CHECK: tail call signext i32 @goo(i32 signext 4)
87 ; Check that instsimplify is not doing this all on its own.
88 ; CHECK-IO-LABEL: @far
89 ; CHECK-IO: tail call signext i32 @goo(i32 signext 5)
90 ; CHECK-IO: tail call signext i32 @goo(i32 signext 3)
91 ; CHECK-IO: tail call signext i32 @goo(i32 signext 2)
92 ; CHECK-IO: tail call signext i32 @goo(i32 signext 1)
93 ; CHECK-IO: tail call signext i32 @goo(i32 signext 0)
94 ; CHECK-IO: tail call signext i32 @goo(i32 signext 4)
98 declare signext i32 @goo(i32 signext) #1
100 ; Function Attrs: nounwind readnone
101 define signext i32 @tar1(i32 signext %x) #0 {
103 %call = tail call signext i32 @foo(i32 signext 5) #0
104 %and = and i32 %call, 33554432
105 %or = or i32 %and, %x
106 %call1 = tail call signext i32 @foo(i32 signext 3) #0
107 %and2 = and i32 %call1, 67108864
108 %or3 = or i32 %or, %and2
109 %call4 = tail call signext i32 @foo(i32 signext 2) #0
110 %and5 = and i32 %call4, 16
111 %or6 = or i32 %or3, %and5
112 %call7 = tail call signext i32 @foo(i32 signext 1) #0
113 %and8 = and i32 %call7, 32
114 %or9 = or i32 %or6, %and8
115 %call10 = tail call signext i32 @foo(i32 signext 0) #0
116 %and11 = and i32 %call10, 64
117 %or12 = or i32 %or9, %and11
118 %call13 = tail call signext i32 @foo(i32 signext 4) #0
119 %and14 = and i32 %call13, 128
120 %or15 = or i32 %or12, %and14
121 %bs = tail call i32 @llvm.bswap.i32(i32 %or15) #0
122 %shr = ashr i32 %bs, 4
126 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
127 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
128 ; CHECK: tail call signext i32 @foo(i32 signext 2)
129 ; CHECK: tail call signext i32 @foo(i32 signext 1)
130 ; CHECK: tail call signext i32 @foo(i32 signext 0)
131 ; CHECK: tail call signext i32 @foo(i32 signext 4)
135 ; Function Attrs: nounwind readnone
136 declare i32 @llvm.bswap.i32(i32) #0
138 ; Function Attrs: nounwind readnone
139 define signext i32 @tim(i32 signext %x) #0 {
141 %call = tail call signext i32 @foo(i32 signext 5) #0
142 %and = and i32 %call, 536870912
143 %or = or i32 %and, %x
144 %call1 = tail call signext i32 @foo(i32 signext 3) #0
145 %and2 = and i32 %call1, 1073741824
146 %or3 = or i32 %or, %and2
147 %call4 = tail call signext i32 @foo(i32 signext 2) #0
148 %and5 = and i32 %call4, 16
149 %or6 = or i32 %or3, %and5
150 %call7 = tail call signext i32 @foo(i32 signext 1) #0
151 %and8 = and i32 %call7, 32
152 %or9 = or i32 %or6, %and8
153 %call10 = tail call signext i32 @foo(i32 signext 0) #0
154 %and11 = and i32 %call10, 64
155 %or12 = or i32 %or9, %and11
156 %call13 = tail call signext i32 @foo(i32 signext 4) #0
157 %and14 = and i32 %call13, 128
158 %or15 = or i32 %or12, %and14
159 %bs = tail call i32 @llvm.bitreverse.i32(i32 %or15) #0
160 %shr = ashr i32 %bs, 4
164 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
165 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
166 ; CHECK: tail call signext i32 @foo(i32 signext 2)
167 ; CHECK: tail call signext i32 @foo(i32 signext 1)
168 ; CHECK: tail call signext i32 @foo(i32 signext 0)
169 ; CHECK: tail call signext i32 @foo(i32 signext 4)
173 ; Function Attrs: nounwind readnone
174 declare i32 @llvm.bitreverse.i32(i32) #0
176 ; Function Attrs: nounwind readnone
177 define signext i32 @tar2(i32 signext %x) #0 {
179 %call = tail call signext i32 @foo(i32 signext 5) #0
180 %and = and i32 %call, 33554432
181 %or = or i32 %and, %x
182 %call1 = tail call signext i32 @foo(i32 signext 3) #0
183 %and2 = and i32 %call1, 67108864
184 %or3 = or i32 %or, %and2
185 %call4 = tail call signext i32 @foo(i32 signext 2) #0
186 %and5 = and i32 %call4, 16
187 %or6 = or i32 %or3, %and5
188 %call7 = tail call signext i32 @foo(i32 signext 1) #0
189 %and8 = and i32 %call7, 32
190 %or9 = or i32 %or6, %and8
191 %call10 = tail call signext i32 @foo(i32 signext 0) #0
192 %and11 = and i32 %call10, 64
193 %or12 = or i32 %or9, %and11
194 %call13 = tail call signext i32 @foo(i32 signext 4) #0
195 %and14 = and i32 %call13, 128
196 %or15 = or i32 %or12, %and14
197 %shl = shl i32 %or15, 10
201 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
202 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
203 ; CHECK: tail call signext i32 @foo(i32 signext 2)
204 ; CHECK: tail call signext i32 @foo(i32 signext 1)
205 ; CHECK: tail call signext i32 @foo(i32 signext 0)
206 ; CHECK: tail call signext i32 @foo(i32 signext 4)
210 ; Function Attrs: nounwind readnone
211 define signext i32 @tar3(i32 signext %x) #0 {
213 %call = tail call signext i32 @foo(i32 signext 5) #0
214 %and = and i32 %call, 33554432
215 %or = or i32 %and, %x
216 %call1 = tail call signext i32 @foo(i32 signext 3) #0
217 %and2 = and i32 %call1, 67108864
218 %or3 = or i32 %or, %and2
219 %call4 = tail call signext i32 @foo(i32 signext 2) #0
220 %and5 = and i32 %call4, 16
221 %or6 = or i32 %or3, %and5
222 %call7 = tail call signext i32 @foo(i32 signext 1) #0
223 %and8 = and i32 %call7, 32
224 %or9 = or i32 %or6, %and8
225 %call10 = tail call signext i32 @foo(i32 signext 0) #0
226 %and11 = and i32 %call10, 64
227 %or12 = or i32 %or9, %and11
228 %call13 = tail call signext i32 @foo(i32 signext 4) #0
229 %and14 = and i32 %call13, 128
230 %or15 = or i32 %or12, %and14
231 %add = add i32 %or15, 5
232 %shl = shl i32 %add, 10
236 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
237 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
238 ; CHECK: tail call signext i32 @foo(i32 signext 2)
239 ; CHECK: tail call signext i32 @foo(i32 signext 1)
240 ; CHECK: tail call signext i32 @foo(i32 signext 0)
241 ; CHECK: tail call signext i32 @foo(i32 signext 4)
245 ; Function Attrs: nounwind readnone
246 define signext i32 @tar4(i32 signext %x) #0 {
248 %call = tail call signext i32 @foo(i32 signext 5) #0
249 %and = and i32 %call, 33554432
250 %or = or i32 %and, %x
251 %call1 = tail call signext i32 @foo(i32 signext 3) #0
252 %and2 = and i32 %call1, 67108864
253 %or3 = or i32 %or, %and2
254 %call4 = tail call signext i32 @foo(i32 signext 2) #0
255 %and5 = and i32 %call4, 16
256 %or6 = or i32 %or3, %and5
257 %call7 = tail call signext i32 @foo(i32 signext 1) #0
258 %and8 = and i32 %call7, 32
259 %or9 = or i32 %or6, %and8
260 %call10 = tail call signext i32 @foo(i32 signext 0) #0
261 %and11 = and i32 %call10, 64
262 %or12 = or i32 %or9, %and11
263 %call13 = tail call signext i32 @foo(i32 signext 4) #0
264 %and14 = and i32 %call13, 128
265 %or15 = or i32 %or12, %and14
266 %sub = sub i32 %or15, 5
267 %shl = shl i32 %sub, 10
271 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
272 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
273 ; CHECK: tail call signext i32 @foo(i32 signext 2)
274 ; CHECK: tail call signext i32 @foo(i32 signext 1)
275 ; CHECK: tail call signext i32 @foo(i32 signext 0)
276 ; CHECK: tail call signext i32 @foo(i32 signext 4)
280 ; Function Attrs: nounwind readnone
281 define signext i32 @tar5(i32 signext %x) #0 {
283 %call = tail call signext i32 @foo(i32 signext 5) #0
284 %and = and i32 %call, 33554432
285 %or = or i32 %and, %x
286 %call1 = tail call signext i32 @foo(i32 signext 3) #0
287 %and2 = and i32 %call1, 67108864
288 %or3 = or i32 %or, %and2
289 %call4 = tail call signext i32 @foo(i32 signext 2) #0
290 %and5 = and i32 %call4, 16
291 %or6 = or i32 %or3, %and5
292 %call7 = tail call signext i32 @foo(i32 signext 1) #0
293 %and8 = and i32 %call7, 32
294 %or9 = or i32 %or6, %and8
295 %call10 = tail call signext i32 @foo(i32 signext 0) #0
296 %and11 = and i32 %call10, 64
297 %or12 = or i32 %or9, %and11
298 %call13 = tail call signext i32 @foo(i32 signext 4) #0
299 %and14 = and i32 %call13, 128
300 %or15 = or i32 %or12, %and14
301 %xor = xor i32 %or15, 5
302 %shl = shl i32 %xor, 10
306 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
307 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
308 ; CHECK: tail call signext i32 @foo(i32 signext 2)
309 ; CHECK: tail call signext i32 @foo(i32 signext 1)
310 ; CHECK: tail call signext i32 @foo(i32 signext 0)
311 ; CHECK: tail call signext i32 @foo(i32 signext 4)
315 ; Function Attrs: nounwind readnone
316 define signext i32 @tar7(i32 signext %x, i1 %b) #0 {
318 %call = tail call signext i32 @foo(i32 signext 5) #0
319 %and = and i32 %call, 33554432
320 %or = or i32 %and, %x
321 %call1 = tail call signext i32 @foo(i32 signext 3) #0
322 %and2 = and i32 %call1, 67108864
323 %or3 = or i32 %or, %and2
324 %call4 = tail call signext i32 @foo(i32 signext 2) #0
325 %and5 = and i32 %call4, 16
326 %or6 = or i32 %or3, %and5
327 %call7 = tail call signext i32 @foo(i32 signext 1) #0
328 %and8 = and i32 %call7, 32
329 %or9 = or i32 %or6, %and8
330 %call10 = tail call signext i32 @foo(i32 signext 0) #0
331 %and11 = and i32 %call10, 64
332 %or12 = or i32 %or9, %and11
333 %call13 = tail call signext i32 @foo(i32 signext 4) #0
334 %and14 = and i32 %call13, 128
335 %or15 = or i32 %or12, %and14
336 %v = select i1 %b, i32 %or15, i32 5
337 %shl = shl i32 %v, 10
341 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
342 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
343 ; CHECK: tail call signext i32 @foo(i32 signext 2)
344 ; CHECK: tail call signext i32 @foo(i32 signext 1)
345 ; CHECK: tail call signext i32 @foo(i32 signext 0)
346 ; CHECK: tail call signext i32 @foo(i32 signext 4)
350 ; Function Attrs: nounwind readnone
351 define signext i16 @tar8(i32 signext %x) #0 {
353 %call = tail call signext i32 @foo(i32 signext 5) #0
354 %and = and i32 %call, 33554432
355 %or = or i32 %and, %x
356 %call1 = tail call signext i32 @foo(i32 signext 3) #0
357 %and2 = and i32 %call1, 67108864
358 %or3 = or i32 %or, %and2
359 %call4 = tail call signext i32 @foo(i32 signext 2) #0
360 %and5 = and i32 %call4, 16
361 %or6 = or i32 %or3, %and5
362 %call7 = tail call signext i32 @foo(i32 signext 1) #0
363 %and8 = and i32 %call7, 32
364 %or9 = or i32 %or6, %and8
365 %call10 = tail call signext i32 @foo(i32 signext 0) #0
366 %and11 = and i32 %call10, 64
367 %or12 = or i32 %or9, %and11
368 %call13 = tail call signext i32 @foo(i32 signext 4) #0
369 %and14 = and i32 %call13, 128
370 %or15 = or i32 %or12, %and14
371 %tr = trunc i32 %or15 to i16
375 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 5)
376 ; CHECK-NOT: tail call signext i32 @foo(i32 signext 3)
377 ; CHECK: tail call signext i32 @foo(i32 signext 2)
378 ; CHECK: tail call signext i32 @foo(i32 signext 1)
379 ; CHECK: tail call signext i32 @foo(i32 signext 0)
380 ; CHECK: tail call signext i32 @foo(i32 signext 4)
384 attributes #0 = { nounwind readnone }
385 attributes #1 = { nounwind }