• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -simplifycfg -sink-common-insts -S | FileCheck -enable-var-scope %s
2; RUN: opt < %s -passes='simplify-cfg<sink-common-insts>' -S | FileCheck -enable-var-scope %s
3
4define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
5entry:
6  br i1 %flag, label %if.then, label %if.else
7
8; CHECK-LABEL: test1
9; CHECK: add
10; CHECK: select
11; CHECK: icmp
12; CHECK-NOT: br
13if.then:
14  %cmp = icmp uge i32 %blksA, %nblks
15  %frombool1 = zext i1 %cmp to i8
16  br label %if.end
17
18if.else:
19  %add = add i32 %nblks, %blksB
20  %cmp2 = icmp ule i32 %add, %blksA
21  %frombool3 = zext i1 %cmp2 to i8
22  br label %if.end
23
24if.end:
25  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
26  %tobool4 = icmp ne i8 %obeys.0, 0
27  ret i1 %tobool4
28}
29
30define zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
31entry:
32  br i1 %flag, label %if.then, label %if.else
33
34; CHECK-LABEL: test2
35; CHECK: add
36; CHECK: select
37; CHECK: icmp
38; CHECK-NOT: br
39if.then:
40  %cmp = icmp uge i32 %blksA, %nblks
41  %frombool1 = zext i1 %cmp to i8
42  br label %if.end
43
44if.else:
45  %add = add i32 %nblks, %blksB
46  %cmp2 = icmp uge i32 %blksA, %add
47  %frombool3 = zext i1 %cmp2 to i8
48  br label %if.end
49
50if.end:
51  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
52  %tobool4 = icmp ne i8 %obeys.0, 0
53  ret i1 %tobool4
54}
55
56declare i32 @foo(i32, i32) nounwind readnone
57
58define i32 @test3(i1 zeroext %flag, i32 %x, i32 %y) {
59entry:
60  br i1 %flag, label %if.then, label %if.else
61
62if.then:
63  %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone
64  %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone
65  br label %if.end
66
67if.else:
68  %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone
69  %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone
70  br label %if.end
71
72if.end:
73  %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ]
74  %yy = phi i32 [ %y0, %if.then ], [ %y1, %if.else ]
75  %ret = add i32 %xx, %yy
76  ret i32 %ret
77}
78
79; CHECK-LABEL: test3
80; CHECK: select
81; CHECK: call
82; CHECK: call
83; CHECK: add
84; CHECK-NOT: br
85
86define i32 @test4(i1 zeroext %flag, i32 %x, i32* %y) {
87entry:
88  br i1 %flag, label %if.then, label %if.else
89
90if.then:
91  %a = add i32 %x, 5
92  store i32 %a, i32* %y
93  br label %if.end
94
95if.else:
96  %b = add i32 %x, 7
97  store i32 %b, i32* %y
98  br label %if.end
99
100if.end:
101  ret i32 1
102}
103
104; CHECK-LABEL: test4
105; CHECK: select
106; CHECK: store
107; CHECK-NOT: store
108
109define i32 @test5(i1 zeroext %flag, i32 %x, i32* %y) {
110entry:
111  br i1 %flag, label %if.then, label %if.else
112
113if.then:
114  %a = add i32 %x, 5
115  store volatile i32 %a, i32* %y
116  br label %if.end
117
118if.else:
119  %b = add i32 %x, 7
120  store i32 %b, i32* %y
121  br label %if.end
122
123if.end:
124  ret i32 1
125}
126
127; CHECK-LABEL: test5
128; CHECK: store volatile
129; CHECK: store
130
131define i32 @test6(i1 zeroext %flag, i32 %x, i32* %y) {
132entry:
133  br i1 %flag, label %if.then, label %if.else
134
135if.then:
136  %a = add i32 %x, 5
137  store volatile i32 %a, i32* %y
138  br label %if.end
139
140if.else:
141  %b = add i32 %x, 7
142  store volatile i32 %b, i32* %y
143  br label %if.end
144
145if.end:
146  ret i32 1
147}
148
149; CHECK-LABEL: test6
150; CHECK: select
151; CHECK: store volatile
152; CHECK-NOT: store
153
154define i32 @test7(i1 zeroext %flag, i32 %x, i32* %y) {
155entry:
156  br i1 %flag, label %if.then, label %if.else
157
158if.then:
159  %z = load volatile i32, i32* %y
160  %a = add i32 %z, 5
161  store volatile i32 %a, i32* %y
162  br label %if.end
163
164if.else:
165  %w = load volatile i32, i32* %y
166  %b = add i32 %w, 7
167  store volatile i32 %b, i32* %y
168  br label %if.end
169
170if.end:
171  ret i32 1
172}
173
174; CHECK-LABEL: test7
175; CHECK-DAG: select
176; CHECK-DAG: load volatile
177; CHECK: store volatile
178; CHECK-NOT: load
179; CHECK-NOT: store
180
181; %z and %w are in different blocks. We shouldn't sink the add because
182; there may be intervening memory instructions.
183define i32 @test8(i1 zeroext %flag, i32 %x, i32* %y) {
184entry:
185  %z = load volatile i32, i32* %y
186  br i1 %flag, label %if.then, label %if.else
187
188if.then:
189  %a = add i32 %z, 5
190  store volatile i32 %a, i32* %y
191  br label %if.end
192
193if.else:
194  %w = load volatile i32, i32* %y
195  %b = add i32 %w, 7
196  store volatile i32 %b, i32* %y
197  br label %if.end
198
199if.end:
200  ret i32 1
201}
202
203; CHECK-LABEL: test8
204; CHECK: add
205; CHECK: add
206
207; The extra store in %if.then means %z and %w are not equivalent.
208define i32 @test9(i1 zeroext %flag, i32 %x, i32* %y, i32* %p) {
209entry:
210  br i1 %flag, label %if.then, label %if.else
211
212if.then:
213  store i32 7, i32* %p
214  %z = load volatile i32, i32* %y
215  store i32 6, i32* %p
216  %a = add i32 %z, 5
217  store volatile i32 %a, i32* %y
218  br label %if.end
219
220if.else:
221  %w = load volatile i32, i32* %y
222  %b = add i32 %w, 7
223  store volatile i32 %b, i32* %y
224  br label %if.end
225
226if.end:
227  ret i32 1
228}
229
230; CHECK-LABEL: test9
231; CHECK: add
232; CHECK: add
233
234%struct.anon = type { i32, i32 }
235
236; The GEP indexes a struct type so cannot have a variable last index.
237define i32 @test10(i1 zeroext %flag, i32 %x, i32* %y, %struct.anon* %s) {
238entry:
239  br i1 %flag, label %if.then, label %if.else
240
241if.then:
242  %dummy = add i32 %x, 5
243  %gepa = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 0
244  store volatile i32 %x, i32* %gepa
245  br label %if.end
246
247if.else:
248  %dummy1 = add i32 %x, 6
249  %gepb = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1
250  store volatile i32 %x, i32* %gepb
251  br label %if.end
252
253if.end:
254  ret i32 1
255}
256
257; CHECK-LABEL: test10
258; CHECK: getelementptr
259; CHECK: getelementptr
260; CHECK: phi
261; CHECK: store volatile
262
263; The shufflevector's mask operand cannot be merged in a PHI.
264define i32 @test11(i1 zeroext %flag, i32 %w, <2 x i32> %x, <2 x i32> %y) {
265entry:
266  br i1 %flag, label %if.then, label %if.else
267
268if.then:
269  %dummy = add i32 %w, 5
270  %sv1 = shufflevector <2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 0, i32 1>
271  br label %if.end
272
273if.else:
274  %dummy1 = add i32 %w, 6
275  %sv2 = shufflevector <2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 1, i32 0>
276  br label %if.end
277
278if.end:
279  %p = phi <2 x i32> [ %sv1, %if.then ], [ %sv2, %if.else ]
280  ret i32 1
281}
282
283; CHECK-LABEL: test11
284; CHECK: shufflevector
285; CHECK: shufflevector
286
287; We can't common an intrinsic!
288define i32 @test12(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) {
289entry:
290  br i1 %flag, label %if.then, label %if.else
291
292if.then:
293  %dummy = add i32 %w, 5
294  %sv1 = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
295  br label %if.end
296
297if.else:
298  %dummy1 = add i32 %w, 6
299  %sv2 = call i32 @llvm.cttz.i32(i32 %x, i1 false)
300  br label %if.end
301
302if.end:
303  %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ]
304  ret i32 1
305}
306
307declare i32 @llvm.ctlz.i32(i32 %x, i1 immarg) readnone
308declare i32 @llvm.cttz.i32(i32 %x, i1 immarg) readnone
309
310; CHECK-LABEL: test12
311; CHECK: call i32 @llvm.ctlz
312; CHECK: call i32 @llvm.cttz
313
314; The TBAA metadata should be properly combined.
315define i32 @test13(i1 zeroext %flag, i32 %x, i32* %y) {
316entry:
317  br i1 %flag, label %if.then, label %if.else
318
319if.then:
320  %z = load volatile i32, i32* %y
321  %a = add i32 %z, 5
322  store volatile i32 %a, i32* %y, !tbaa !3
323  br label %if.end
324
325if.else:
326  %w = load volatile i32, i32* %y
327  %b = add i32 %w, 7
328  store volatile i32 %b, i32* %y, !tbaa !4
329  br label %if.end
330
331if.end:
332  ret i32 1
333}
334
335!0 = !{ !"an example type tree" }
336!1 = !{ !"int", !0 }
337!2 = !{ !"float", !0 }
338!3 = !{ !"const float", !2, i64 0 }
339!4 = !{ !"special float", !2, i64 1 }
340
341; CHECK-LABEL: test13
342; CHECK-DAG: select
343; CHECK-DAG: load volatile
344; CHECK: store volatile {{.*}}, !tbaa ![[$TBAA:[0-9]]]
345; CHECK-NOT: load
346; CHECK-NOT: store
347
348; The call should be commoned.
349define i32 @test13a(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) {
350entry:
351  br i1 %flag, label %if.then, label %if.else
352
353if.then:
354  %sv1 = call i32 @bar(i32 %x)
355  br label %if.end
356
357if.else:
358  %sv2 = call i32 @bar(i32 %y)
359  br label %if.end
360
361if.end:
362  %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ]
363  ret i32 1
364}
365declare i32 @bar(i32)
366
367; CHECK-LABEL: test13a
368; CHECK: %[[x:.*]] = select i1 %flag
369; CHECK: call i32 @bar(i32 %[[x]])
370
371; The load should be commoned.
372define i32 @test14(i1 zeroext %flag, i32 %w, i32 %x, i32 %y, %struct.anon* %s) {
373entry:
374  br i1 %flag, label %if.then, label %if.else
375
376if.then:
377  %dummy = add i32 %x, 1
378  %gepa = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1
379  %sv1 = load i32, i32* %gepa
380  %cmp1 = icmp eq i32 %sv1, 56
381  br label %if.end
382
383if.else:
384  %dummy2 = add i32 %x, 4
385  %gepb = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1
386  %sv2 = load i32, i32* %gepb
387  %cmp2 = icmp eq i32 %sv2, 57
388  call void @llvm.dbg.value(metadata i32 0, metadata !9, metadata !DIExpression()), !dbg !11
389  br label %if.end
390
391if.end:
392  %p = phi i1 [ %cmp1, %if.then ], [ %cmp2, %if.else ]
393  ret i32 1
394}
395
396declare void @llvm.dbg.value(metadata, metadata, metadata)
397!llvm.module.flags = !{!5, !6}
398!llvm.dbg.cu = !{!7}
399
400!5 = !{i32 2, !"Dwarf Version", i32 4}
401!6 = !{i32 2, !"Debug Info Version", i32 3}
402!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !10)
403!8 = distinct !DISubprogram(name: "foo", unit: !7)
404!9 = !DILocalVariable(name: "b", line: 1, arg: 2, scope: !8)
405!10 = !DIFile(filename: "a.c", directory: "a/b")
406!11 = !DILocation(line: 1, column: 14, scope: !8)
407
408; CHECK-LABEL: test14
409; CHECK: getelementptr
410; CHECK: load
411; CHECK-NOT: load
412
413; The load should be commoned.
414define i32 @test15(i1 zeroext %flag, i32 %w, i32 %x, i32 %y, %struct.anon* %s) {
415entry:
416  br i1 %flag, label %if.then, label %if.else
417
418if.then:
419  %dummy = add i32 %x, 1
420  %gepa = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 0
421  %sv1 = load i32, i32* %gepa
422  %ext1 = zext i32 %sv1 to i64
423  %cmp1 = icmp eq i64 %ext1, 56
424  br label %if.end
425
426if.else:
427  %dummy2 = add i32 %x, 4
428  %gepb = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1
429  %sv2 = load i32, i32* %gepb
430  %ext2 = zext i32 %sv2 to i64
431  %cmp2 = icmp eq i64 %ext2, 57
432  br label %if.end
433
434if.end:
435  %p = phi i1 [ %cmp1, %if.then ], [ %cmp2, %if.else ]
436  ret i32 1
437}
438
439; CHECK-LABEL: test15
440; CHECK: getelementptr
441; CHECK: load
442; CHECK-NOT: load
443
444define zeroext i1 @test_crash(i1 zeroext %flag, i32* %i4, i32* %m, i32* %n) {
445entry:
446  br i1 %flag, label %if.then, label %if.else
447
448if.then:
449  %tmp1 = load i32, i32* %i4
450  %tmp2 = add i32 %tmp1, -1
451  store i32 %tmp2, i32* %i4
452  br label %if.end
453
454if.else:
455  %tmp3 = load i32, i32* %m
456  %tmp4 = load i32, i32* %n
457  %tmp5 = add i32 %tmp3, %tmp4
458  store i32 %tmp5, i32* %i4
459  br label %if.end
460
461if.end:
462  ret i1 true
463}
464
465; CHECK-LABEL: test_crash
466; No checks for test_crash - just ensure it doesn't crash!
467
468define zeroext i1 @test16(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks) {
469
470entry:
471  br i1 %flag, label %if.then, label %if.else
472
473if.then:
474  %cmp = icmp uge i32 %blksA, %nblks
475  %frombool1 = zext i1 %cmp to i8
476  br label %if.end
477
478if.else:
479  br i1 %flag2, label %if.then2, label %if.end
480
481if.then2:
482  %add = add i32 %nblks, %blksB
483  %cmp2 = icmp ule i32 %add, %blksA
484  %frombool3 = zext i1 %cmp2 to i8
485  br label %if.end
486
487if.end:
488  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ 0, %if.else ]
489  %tobool4 = icmp ne i8 %obeys.0, 0
490  ret i1 %tobool4
491}
492
493; CHECK-LABEL: test16
494; CHECK: zext
495; CHECK: zext
496
497define zeroext i1 @test16a(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks, i8* %p) {
498
499entry:
500  br i1 %flag, label %if.then, label %if.else
501
502if.then:
503  %cmp = icmp uge i32 %blksA, %nblks
504  %frombool1 = zext i1 %cmp to i8
505  store i8 %frombool1, i8* %p
506  br label %if.end
507
508if.else:
509  br i1 %flag2, label %if.then2, label %if.end
510
511if.then2:
512  %add = add i32 %nblks, %blksB
513  %cmp2 = icmp ule i32 %add, %blksA
514  %frombool3 = zext i1 %cmp2 to i8
515  store i8 %frombool3, i8* %p
516  br label %if.end
517
518if.end:
519  ret i1 true
520}
521
522; CHECK-LABEL: test16a
523; CHECK: zext
524; CHECK-NOT: zext
525
526define zeroext i1 @test17(i32 %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
527entry:
528  switch i32 %flag, label %if.end [
529    i32 0, label %if.then
530    i32 1, label %if.then2
531  ]
532
533if.then:
534  %cmp = icmp uge i32 %blksA, %nblks
535  %frombool1 = call i8 @i1toi8(i1 %cmp)
536  br label %if.end
537
538if.then2:
539  %add = add i32 %nblks, %blksB
540  %cmp2 = icmp ule i32 %add, %blksA
541  %frombool3 = call i8 @i1toi8(i1 %cmp2)
542  br label %if.end
543
544if.end:
545  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ 0, %entry ]
546  %tobool4 = icmp ne i8 %obeys.0, 0
547  ret i1 %tobool4
548}
549declare i8 @i1toi8(i1)
550
551; CHECK-LABEL: test17
552; CHECK: if.then:
553; CHECK-NEXT: icmp uge
554; CHECK-NEXT: br label %[[x:.*]]
555
556; CHECK: if.then2:
557; CHECK-NEXT: add
558; CHECK-NEXT: icmp ule
559; CHECK-NEXT: br label %[[x]]
560
561; CHECK: [[x]]:
562; CHECK-NEXT: %[[y:.*]] = phi i1 [ %cmp
563; CHECK-NEXT: %[[z:.*]] = call i8 @i1toi8(i1 %[[y]])
564; CHECK-NEXT: br label %if.end
565
566; CHECK: if.end:
567; CHECK-NEXT: phi i8
568; CHECK-DAG: [ %[[z]], %[[x]] ]
569; CHECK-DAG: [ 0, %entry ]
570
571define zeroext i1 @test18(i32 %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
572entry:
573  switch i32 %flag, label %if.then3 [
574    i32 0, label %if.then
575    i32 1, label %if.then2
576  ]
577
578if.then:
579  %cmp = icmp uge i32 %blksA, %nblks
580  %frombool1 = zext i1 %cmp to i8
581  br label %if.end
582
583if.then2:
584  %add = add i32 %nblks, %blksB
585  %cmp2 = icmp ule i32 %add, %blksA
586  %frombool3 = zext i1 %cmp2 to i8
587  br label %if.end
588
589if.then3:
590  %add2 = add i32 %nblks, %blksA
591  %cmp3 = icmp ule i32 %add2, %blksA
592  %frombool4 = zext i1 %cmp3 to i8
593  br label %if.end
594
595if.end:
596  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.then2 ], [ %frombool4, %if.then3 ]
597  %tobool4 = icmp ne i8 %obeys.0, 0
598  ret i1 %tobool4
599}
600
601; CHECK-LABEL: test18
602; CHECK: if.end:
603; CHECK-NEXT: %[[x:.*]] = phi i1
604; CHECK-DAG: [ %cmp, %if.then ]
605; CHECK-DAG: [ %cmp2, %if.then2 ]
606; CHECK-DAG: [ %cmp3, %if.then3 ]
607; CHECK-NEXT: zext i1 %[[x]] to i8
608
609define i32 @test_pr30188(i1 zeroext %flag, i32 %x) {
610entry:
611  %y = alloca i32
612  %z = alloca i32
613  br i1 %flag, label %if.then, label %if.else
614
615if.then:
616  store i32 %x, i32* %y
617  br label %if.end
618
619if.else:
620  store i32 %x, i32* %z
621  br label %if.end
622
623if.end:
624  ret i32 1
625}
626
627; CHECK-LABEL: test_pr30188
628; CHECK-NOT: select
629; CHECK: store
630; CHECK: store
631
632define i32 @test_pr30188a(i1 zeroext %flag, i32 %x) {
633entry:
634  %y = alloca i32
635  %z = alloca i32
636  br i1 %flag, label %if.then, label %if.else
637
638if.then:
639  call void @g()
640  %one = load i32, i32* %y
641  %two = add i32 %one, 2
642  store i32 %two, i32* %y
643  br label %if.end
644
645if.else:
646  %three = load i32, i32* %z
647  %four = add i32 %three, 2
648  store i32 %four, i32* %y
649  br label %if.end
650
651if.end:
652  ret i32 1
653}
654
655; CHECK-LABEL: test_pr30188a
656; CHECK-NOT: select
657; CHECK: load
658; CHECK: load
659; CHECK: store
660
661; The phi is confusing - both add instructions are used by it, but
662; not on their respective unconditional arcs. It should not be
663; optimized.
664define void @test_pr30292(i1 %cond, i1 %cond2, i32 %a, i32 %b) {
665entry:
666  %add1 = add i32 %a, 1
667  br label %succ
668
669one:
670  br i1 %cond, label %two, label %succ
671
672two:
673  call void @g()
674  %add2 = add i32 %a, 1
675  br label %succ
676
677succ:
678  %p = phi i32 [ 0, %entry ], [ %add1, %one ], [ %add2, %two ]
679  br label %one
680}
681declare void @g()
682
683; CHECK-LABEL: test_pr30292
684; CHECK: phi i32 [ 0, %entry ], [ %add1, %succ ], [ %add2, %two ]
685
686define zeroext i1 @test_pr30244(i1 zeroext %flag, i1 zeroext %flag2, i32 %blksA, i32 %blksB, i32 %nblks) {
687
688entry:
689  %p = alloca i8
690  br i1 %flag, label %if.then, label %if.else
691
692if.then:
693  %cmp = icmp uge i32 %blksA, %nblks
694  %frombool1 = zext i1 %cmp to i8
695  store i8 %frombool1, i8* %p
696  br label %if.end
697
698if.else:
699  br i1 %flag2, label %if.then2, label %if.end
700
701if.then2:
702  %add = add i32 %nblks, %blksB
703  %cmp2 = icmp ule i32 %add, %blksA
704  %frombool3 = zext i1 %cmp2 to i8
705  store i8 %frombool3, i8* %p
706  br label %if.end
707
708if.end:
709  ret i1 true
710}
711
712; CHECK-LABEL: @test_pr30244
713; CHECK: store
714; CHECK: store
715
716define i32 @test_pr30373a(i1 zeroext %flag, i32 %x, i32 %y) {
717entry:
718  br i1 %flag, label %if.then, label %if.else
719
720if.then:
721  %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone
722  %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone
723  %z0 = lshr i32 %y0, 8
724  br label %if.end
725
726if.else:
727  %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone
728  %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone
729  %z1 = lshr exact i32 %y1, 8
730  br label %if.end
731
732if.end:
733  %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ]
734  %yy = phi i32 [ %z0, %if.then ], [ %z1, %if.else ]
735  %ret = add i32 %xx, %yy
736  ret i32 %ret
737}
738
739; CHECK-LABEL: test_pr30373a
740; CHECK: lshr
741; CHECK-NOT: exact
742; CHECK: }
743
744define i32 @test_pr30373b(i1 zeroext %flag, i32 %x, i32 %y) {
745entry:
746  br i1 %flag, label %if.then, label %if.else
747
748if.then:
749  %x0 = call i32 @foo(i32 %x, i32 0) nounwind readnone
750  %y0 = call i32 @foo(i32 %x, i32 1) nounwind readnone
751  %z0 = lshr exact i32 %y0, 8
752  br label %if.end
753
754if.else:
755  %x1 = call i32 @foo(i32 %y, i32 0) nounwind readnone
756  %y1 = call i32 @foo(i32 %y, i32 1) nounwind readnone
757  %z1 = lshr i32 %y1, 8
758  br label %if.end
759
760if.end:
761  %xx = phi i32 [ %x0, %if.then ], [ %x1, %if.else ]
762  %yy = phi i32 [ %z0, %if.then ], [ %z1, %if.else ]
763  %ret = add i32 %xx, %yy
764  ret i32 %ret
765}
766
767; CHECK-LABEL: test_pr30373b
768; CHECK: lshr
769; CHECK-NOT: exact
770; CHECK: }
771
772
773; FIXME:  Should turn into select
774; CHECK-LABEL: @allow_intrinsic_remove_constant(
775; CHECK: %sv1 = call float @llvm.fma.f32(float %dummy, float 2.000000e+00, float 1.000000e+00)
776; CHECK: %sv2 = call float @llvm.fma.f32(float 2.000000e+00, float %dummy1, float 1.000000e+00)
777define float @allow_intrinsic_remove_constant(i1 zeroext %flag, float %w, float %x, float %y) {
778entry:
779  br i1 %flag, label %if.then, label %if.else
780
781if.then:
782  %dummy = fadd float %w, 4.0
783  %sv1 = call float @llvm.fma.f32(float %dummy, float 2.0, float 1.0)
784  br label %if.end
785
786if.else:
787  %dummy1 = fadd float %w, 8.0
788  %sv2 = call float @llvm.fma.f32(float 2.0, float %dummy1, float 1.0)
789  br label %if.end
790
791if.end:
792  %p = phi float [ %sv1, %if.then ], [ %sv2, %if.else ]
793  ret float %p
794}
795
796declare float @llvm.fma.f32(float, float, float)
797
798; CHECK-LABEL: @no_remove_constant_immarg(
799; CHECK: call i32 @llvm.ctlz.i32(i32 %x, i1 true)
800; CHECK: call i32 @llvm.ctlz.i32(i32 %x, i1 false)
801define i32 @no_remove_constant_immarg(i1 zeroext %flag, i32 %w, i32 %x, i32 %y) {
802entry:
803  br i1 %flag, label %if.then, label %if.else
804
805if.then:
806  %dummy = add i32 %w, 5
807  %sv1 = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
808  br label %if.end
809
810if.else:
811  %dummy1 = add i32 %w, 6
812  %sv2 = call i32 @llvm.ctlz.i32(i32 %x, i1 false)
813  br label %if.end
814
815if.end:
816  %p = phi i32 [ %sv1, %if.then ], [ %sv2, %if.else ]
817  ret i32 1
818}
819
820declare void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture readonly, i64, i1)
821
822; Make sure a memcpy size isn't replaced with a variable
823; CHECK-LABEL: @no_replace_memcpy_size(
824; CHECK: call void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 1024, i1 false)
825; CHECK: call void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 4096, i1 false)
826define void @no_replace_memcpy_size(i1 zeroext %flag, i8 addrspace(1)* %dst, i8 addrspace(1)* %src) {
827entry:
828  br i1 %flag, label %if.then, label %if.else
829
830if.then:
831  call void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 1024, i1 false)
832  br label %if.end
833
834if.else:
835  call void @llvm.memcpy.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 4096, i1 false)
836  br label %if.end
837
838if.end:
839  ret void
840}
841
842declare void @llvm.memmove.p1i8.p1i8.i64(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture readonly, i64, i1)
843
844; Make sure a memmove size isn't replaced with a variable
845; CHECK-LABEL: @no_replace_memmove_size(
846; CHECK: call void @llvm.memmove.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 1024, i1 false)
847; CHECK: call void @llvm.memmove.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 4096, i1 false)
848define void @no_replace_memmove_size(i1 zeroext %flag, i8 addrspace(1)* %dst, i8 addrspace(1)* %src) {
849entry:
850  br i1 %flag, label %if.then, label %if.else
851
852if.then:
853  call void @llvm.memmove.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 1024, i1 false)
854  br label %if.end
855
856if.else:
857  call void @llvm.memmove.p1i8.p1i8.i64(i8 addrspace(1)* %dst, i8 addrspace(1)* %src, i64 4096, i1 false)
858  br label %if.end
859
860if.end:
861  ret void
862}
863
864declare void @llvm.memset.p1i8.i64(i8 addrspace(1)* nocapture, i8, i64, i1)
865
866; Make sure a memset size isn't replaced with a variable
867; CHECK-LABEL: @no_replace_memset_size(
868; CHECK: call void @llvm.memset.p1i8.i64(i8 addrspace(1)* %dst, i8 0, i64 1024, i1 false)
869; CHECK: call void @llvm.memset.p1i8.i64(i8 addrspace(1)* %dst, i8 0, i64 4096, i1 false)
870define void @no_replace_memset_size(i1 zeroext %flag, i8 addrspace(1)* %dst) {
871entry:
872  br i1 %flag, label %if.then, label %if.else
873
874if.then:
875  call void @llvm.memset.p1i8.i64(i8 addrspace(1)* %dst, i8 0, i64 1024, i1 false)
876  br label %if.end
877
878if.else:
879  call void @llvm.memset.p1i8.i64(i8 addrspace(1)* %dst, i8 0, i64 4096, i1 false)
880  br label %if.end
881
882if.end:
883  ret void
884}
885
886; Check that simplifycfg doesn't sink and merge inline-asm instructions.
887
888define i32 @test_inline_asm1(i32 %c, i32 %r6) {
889entry:
890  %tobool = icmp eq i32 %c, 0
891  br i1 %tobool, label %if.else, label %if.then
892
893if.then:
894  %0 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 8)
895  br label %if.end
896
897if.else:
898  %1 = call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 6)
899  br label %if.end
900
901if.end:
902  %r6.addr.0 = phi i32 [ %0, %if.then ], [ %1, %if.else ]
903  ret i32 %r6.addr.0
904}
905
906; CHECK-LABEL: @test_inline_asm1(
907; CHECK: call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 8)
908; CHECK: call i32 asm "rorl $2, $0", "=&r,0,n,~{dirflag},~{fpsr},~{flags}"(i32 %r6, i32 6)
909
910declare i32 @call_target()
911
912define void @test_operand_bundles(i1 %cond, i32* %ptr) {
913entry:
914  br i1 %cond, label %left, label %right
915
916left:
917  %val0 = call i32 @call_target() [ "deopt"(i32 10) ]
918  store i32 %val0, i32* %ptr
919  br label %merge
920
921right:
922  %val1 = call i32 @call_target() [ "deopt"(i32 20) ]
923  store i32 %val1, i32* %ptr
924  br label %merge
925
926merge:
927  ret void
928}
929
930; CHECK-LABEL: @test_operand_bundles(
931; CHECK: left:
932; CHECK-NEXT:   %val0 = call i32 @call_target() [ "deopt"(i32 10) ]
933; CHECK: right:
934; CHECK-NEXT:   %val1 = call i32 @call_target() [ "deopt"(i32 20) ]
935
936%T = type {i32, i32}
937
938define i32 @test_insertvalue(i1 zeroext %flag, %T %P) {
939entry:
940  br i1 %flag, label %if.then, label %if.else
941
942if.then:
943  %t1 = insertvalue %T %P, i32 0, 0
944  br label %if.end
945
946if.else:
947  %t2 = insertvalue %T %P, i32 1, 0
948  br label %if.end
949
950if.end:
951  %t = phi %T [%t1, %if.then], [%t2, %if.else]
952  ret i32 1
953}
954
955; CHECK-LABEL: @test_insertvalue
956; CHECK: select
957; CHECK: insertvalue
958; CHECK-NOT: insertvalue
959
960
961declare void @baz(i32)
962
963define void @test_sink_void_calls(i32 %x) {
964entry:
965  switch i32 %x, label %default [
966    i32 0, label %bb0
967    i32 1, label %bb1
968    i32 2, label %bb2
969    i32 3, label %bb3
970    i32 4, label %bb4
971  ]
972bb0:
973  call void @baz(i32 12)
974  br label %return
975bb1:
976  call void @baz(i32 34)
977  br label %return
978bb2:
979  call void @baz(i32 56)
980  br label %return
981bb3:
982  call void @baz(i32 78)
983  br label %return
984bb4:
985  call void @baz(i32 90)
986  br label %return
987default:
988  unreachable
989return:
990  ret void
991
992; Check that the calls get sunk to the return block.
993; We would previously not sink calls without uses, see PR41259.
994; CHECK-LABEL: @test_sink_void_calls
995; CHECK-NOT: call
996; CHECK-LABEL: return:
997; CHECK: phi
998; CHECK: call
999; CHECK-NOT: call
1000; CHECK: ret
1001}
1002
1003; CHECK-LABEL: @test_not_sink_lifetime_marker
1004; CHECK-NOT: select
1005; CHECK: call void @llvm.lifetime.end
1006; CHECK: call void @llvm.lifetime.end
1007define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
1008entry:
1009  %y = alloca i32
1010  %z = alloca i32
1011  br i1 %flag, label %if.then, label %if.else
1012
1013if.then:
1014  %y.cast = bitcast i32* %y to i8*
1015  call void @llvm.lifetime.end.p0i8(i64 4, i8* %y.cast)
1016  br label %if.end
1017
1018if.else:
1019  %z.cast = bitcast i32* %z to i8*
1020  call void @llvm.lifetime.end.p0i8(i64 4, i8* %z.cast)
1021  br label %if.end
1022
1023if.end:
1024  ret i32 1
1025}
1026
1027declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
1028declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
1029
1030; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
1031; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
1032; CHECK: ![[TEXT]] = !{!"an example type tree"}
1033