1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -post-RA-scheduler=true -disable-cgp-delete-phis | FileCheck %s
4 declare dso_local void @bar(i32)
5 declare dso_local void @car(i32)
6 declare dso_local void @dar(i32)
7 declare dso_local void @ear(i32)
8 declare dso_local void @far(i32)
11 @GHJK = dso_local global i32 0
12 @HABC = dso_local global i32 0
14 ; BranchFolding should tail-merge the stores since they all precede
15 ; direct branches to the same place.
17 define dso_local void @tail_merge_me() nounwind {
18 ; CHECK-LABEL: tail_merge_me:
19 ; CHECK: # %bb.0: # %entry
20 ; CHECK-NEXT: pushq %rax
21 ; CHECK-NEXT: callq qux@PLT
22 ; CHECK-NEXT: testb $1, %al
23 ; CHECK-NEXT: je .LBB0_1
24 ; CHECK-NEXT: # %bb.6: # %A
25 ; CHECK-NEXT: xorl %edi, %edi
26 ; CHECK-NEXT: callq bar
27 ; CHECK-NEXT: jmp .LBB0_4
28 ; CHECK-NEXT: .LBB0_1: # %next
29 ; CHECK-NEXT: callq qux@PLT
30 ; CHECK-NEXT: testb $1, %al
31 ; CHECK-NEXT: je .LBB0_3
32 ; CHECK-NEXT: # %bb.2: # %B
33 ; CHECK-NEXT: movl $1, %edi
34 ; CHECK-NEXT: callq car
35 ; CHECK-NEXT: jmp .LBB0_4
36 ; CHECK-NEXT: .LBB0_3: # %C
37 ; CHECK-NEXT: movl $2, %edi
38 ; CHECK-NEXT: callq dar
39 ; CHECK-NEXT: .LBB0_4: # %M
40 ; CHECK-NEXT: movl $0, GHJK(%rip)
41 ; CHECK-NEXT: movl $1, HABC(%rip)
42 ; CHECK-NEXT: callq qux@PLT
43 ; CHECK-NEXT: testb $1, %al
44 ; CHECK-NEXT: je .LBB0_5
45 ; CHECK-NEXT: # %bb.7: # %return
46 ; CHECK-NEXT: movl $1000, %edi # imm = 0x3E8
47 ; CHECK-NEXT: callq ear
48 ; CHECK-NEXT: popq %rax
50 ; CHECK-NEXT: .LBB0_5: # %altret
51 ; CHECK-NEXT: movl $1001, %edi # imm = 0x3E9
52 ; CHECK-NEXT: callq far
53 ; CHECK-NEXT: popq %rax
57 br i1 %a, label %A, label %next
60 br i1 %b, label %B, label %C
64 store i32 0, ptr @GHJK
69 store i32 0, ptr @GHJK
74 store i32 0, ptr @GHJK
78 store i32 1, ptr @HABC
80 br i1 %c, label %return, label %altret
83 call void @ear(i32 1000)
86 call void @far(i32 1001)
90 declare ptr @choose(ptr, ptr)
92 ; BranchFolding should tail-duplicate the indirect jump to avoid
93 ; redundant branching.
95 define dso_local void @tail_duplicate_me() nounwind {
96 ; CHECK-LABEL: tail_duplicate_me:
97 ; CHECK: # %bb.0: # %entry
98 ; CHECK-NEXT: pushq %rbp
99 ; CHECK-NEXT: pushq %rbx
100 ; CHECK-NEXT: pushq %rax
101 ; CHECK-NEXT: callq qux@PLT
102 ; CHECK-NEXT: movl $.Ltmp0, %edi
103 ; CHECK-NEXT: movl $.Ltmp1, %esi
104 ; CHECK-NEXT: movl %eax, %ebp
105 ; CHECK-NEXT: callq choose@PLT
106 ; CHECK-NEXT: movq %rax, %rbx
107 ; CHECK-NEXT: testb $1, %bpl
108 ; CHECK-NEXT: je .LBB1_1
109 ; CHECK-NEXT: # %bb.7: # %A
110 ; CHECK-NEXT: xorl %edi, %edi
111 ; CHECK-NEXT: callq bar
112 ; CHECK-NEXT: movl $0, GHJK(%rip)
113 ; CHECK-NEXT: jmpq *%rbx
114 ; CHECK-NEXT: .Ltmp0: # Block address taken
115 ; CHECK-NEXT: .LBB1_4: # %return
116 ; CHECK-NEXT: movl $1000, %edi # imm = 0x3E8
117 ; CHECK-NEXT: callq ear
118 ; CHECK-NEXT: jmp .LBB1_5
119 ; CHECK-NEXT: .LBB1_1: # %next
120 ; CHECK-NEXT: callq qux@PLT
121 ; CHECK-NEXT: testb $1, %al
122 ; CHECK-NEXT: je .LBB1_3
123 ; CHECK-NEXT: # %bb.2: # %B
124 ; CHECK-NEXT: movl $1, %edi
125 ; CHECK-NEXT: callq car
126 ; CHECK-NEXT: movl $0, GHJK(%rip)
127 ; CHECK-NEXT: jmpq *%rbx
128 ; CHECK-NEXT: .Ltmp1: # Block address taken
129 ; CHECK-NEXT: .LBB1_6: # %altret
130 ; CHECK-NEXT: movl $1001, %edi # imm = 0x3E9
131 ; CHECK-NEXT: callq far
132 ; CHECK-NEXT: .LBB1_5: # %return
133 ; CHECK-NEXT: addq $8, %rsp
134 ; CHECK-NEXT: popq %rbx
135 ; CHECK-NEXT: popq %rbp
137 ; CHECK-NEXT: .LBB1_3: # %C
138 ; CHECK-NEXT: movl $2, %edi
139 ; CHECK-NEXT: callq dar
140 ; CHECK-NEXT: movl $0, GHJK(%rip)
141 ; CHECK-NEXT: jmpq *%rbx
144 %c = call ptr @choose(ptr blockaddress(@tail_duplicate_me, %return),
145 ptr blockaddress(@tail_duplicate_me, %altret))
146 br i1 %a, label %A, label %next
149 br i1 %b, label %B, label %C
152 call void @bar(i32 0)
153 store i32 0, ptr @GHJK
157 call void @car(i32 1)
158 store i32 0, ptr @GHJK
162 call void @dar(i32 2)
163 store i32 0, ptr @GHJK
167 indirectbr ptr %c, [label %return, label %altret]
170 call void @ear(i32 1000)
173 call void @far(i32 1001)
177 ; BranchFolding shouldn't try to merge the tails of two blocks
178 ; with only a branch in common, regardless of the fallthrough situation.
180 define i1 @dont_merge_oddly(ptr %result) nounwind {
181 ; CHECK-LABEL: dont_merge_oddly:
182 ; CHECK: # %bb.0: # %entry
183 ; CHECK-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
184 ; CHECK-NEXT: movss {{.*#+}} xmm2 = mem[0],zero,zero,zero
185 ; CHECK-NEXT: movss {{.*#+}} xmm0 = mem[0],zero,zero,zero
186 ; CHECK-NEXT: ucomiss %xmm1, %xmm2
187 ; CHECK-NEXT: jbe .LBB2_3
188 ; CHECK-NEXT: # %bb.1: # %bb
189 ; CHECK-NEXT: ucomiss %xmm0, %xmm1
190 ; CHECK-NEXT: ja .LBB2_4
191 ; CHECK-NEXT: .LBB2_2: # %bb30
192 ; CHECK-NEXT: movb $1, %al
194 ; CHECK-NEXT: .LBB2_3: # %bb21
195 ; CHECK-NEXT: ucomiss %xmm0, %xmm2
196 ; CHECK-NEXT: jbe .LBB2_2
197 ; CHECK-NEXT: .LBB2_4: # %bb26
198 ; CHECK-NEXT: xorl %eax, %eax
201 %tmp4 = getelementptr float, ptr %result, i32 2
202 %tmp5 = load float, ptr %tmp4, align 4
203 %tmp7 = getelementptr float, ptr %result, i32 4
204 %tmp8 = load float, ptr %tmp7, align 4
205 %tmp10 = getelementptr float, ptr %result, i32 6
206 %tmp11 = load float, ptr %tmp10, align 4
207 %tmp12 = fcmp olt float %tmp8, %tmp11
208 br i1 %tmp12, label %bb, label %bb21
211 %tmp23469 = fcmp olt float %tmp5, %tmp8
212 br i1 %tmp23469, label %bb26, label %bb30
215 %tmp23 = fcmp olt float %tmp5, %tmp11
216 br i1 %tmp23, label %bb26, label %bb30
225 ; Do any-size tail-merging when two candidate blocks will both require
226 ; an unconditional jump to complete a two-way conditional branch.
228 ; This test only works when register allocation happens to use %rax for both
232 %struct.lang_decl = type opaque
233 %struct.rtx_def = type { i16, i8, i8, [1 x %union.rtunion] }
234 %struct.tree_decl = type { [24 x i8], ptr, i32, ptr, i32, i8, i8, i8, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %union..2anon, %0, ptr, ptr }
235 %union..2anon = type { i32 }
236 %union.rtunion = type { ptr }
237 %union.tree_node = type { %struct.tree_decl }
239 define fastcc void @c_expand_expr_stmt(ptr %expr) nounwind {
240 ; CHECK-LABEL: c_expand_expr_stmt:
241 ; CHECK: # %bb.0: # %entry
242 ; CHECK-NEXT: pushq %rbx
243 ; CHECK-NEXT: xorl %eax, %eax
244 ; CHECK-NEXT: testb %al, %al
245 ; CHECK-NEXT: jne .LBB3_9
246 ; CHECK-NEXT: # %bb.1: # %entry
247 ; CHECK-NEXT: movzbl 0, %ebx
248 ; CHECK-NEXT: xorl %eax, %eax
249 ; CHECK-NEXT: testb %al, %al
250 ; CHECK-NEXT: jne .LBB3_8
251 ; CHECK-NEXT: # %bb.2: # %bb.i
252 ; CHECK-NEXT: xorl %eax, %eax
253 ; CHECK-NEXT: testb %al, %al
254 ; CHECK-NEXT: je .LBB3_8
255 ; CHECK-NEXT: # %bb.3: # %lvalue_p.exit
256 ; CHECK-NEXT: movq 0, %rax
257 ; CHECK-NEXT: movzbl (%rax), %ecx
258 ; CHECK-NEXT: testl %ecx, %ecx
259 ; CHECK-NEXT: je .LBB3_10
260 ; CHECK-NEXT: # %bb.4: # %lvalue_p.exit
261 ; CHECK-NEXT: cmpl $2, %ecx
262 ; CHECK-NEXT: jne .LBB3_15
263 ; CHECK-NEXT: # %bb.5: # %bb.i1
264 ; CHECK-NEXT: movq 32(%rax), %rax
265 ; CHECK-NEXT: movzbl 16(%rax), %ecx
266 ; CHECK-NEXT: testl %ecx, %ecx
267 ; CHECK-NEXT: je .LBB3_13
268 ; CHECK-NEXT: # %bb.6: # %bb.i1
269 ; CHECK-NEXT: cmpl $2, %ecx
270 ; CHECK-NEXT: jne .LBB3_15
271 ; CHECK-NEXT: # %bb.7: # %bb.i.i
272 ; CHECK-NEXT: xorl %edi, %edi
273 ; CHECK-NEXT: callq lvalue_p@PLT
274 ; CHECK-NEXT: testl %eax, %eax
275 ; CHECK-NEXT: setne %al
276 ; CHECK-NEXT: jmp .LBB3_16
277 ; CHECK-NEXT: .LBB3_8: # %bb1
278 ; CHECK-NEXT: cmpb $23, %bl
279 ; CHECK-NEXT: .LBB3_9: # %bb3
280 ; CHECK-NEXT: .LBB3_15:
281 ; CHECK-NEXT: xorl %eax, %eax
282 ; CHECK-NEXT: jmp .LBB3_16
283 ; CHECK-NEXT: .LBB3_10: # %bb2.i3
284 ; CHECK-NEXT: movq 8(%rax), %rax
285 ; CHECK-NEXT: movzbl 16(%rax), %ecx
286 ; CHECK-NEXT: xorl %eax, %eax
287 ; CHECK-NEXT: cmpl $23, %ecx
288 ; CHECK-NEXT: je .LBB3_16
289 ; CHECK-NEXT: # %bb.11: # %bb2.i3
290 ; CHECK-NEXT: cmpl $16, %ecx
291 ; CHECK-NEXT: je .LBB3_16
292 ; CHECK-NEXT: jmp .LBB3_9
293 ; CHECK-NEXT: .LBB3_13: # %bb2.i.i2
294 ; CHECK-NEXT: movq 8(%rax), %rax
295 ; CHECK-NEXT: movzbl 16(%rax), %ecx
296 ; CHECK-NEXT: xorl %eax, %eax
297 ; CHECK-NEXT: cmpl $16, %ecx
298 ; CHECK-NEXT: je .LBB3_16
299 ; CHECK-NEXT: # %bb.14: # %bb2.i.i2
300 ; CHECK-NEXT: cmpl $23, %ecx
301 ; CHECK-NEXT: jne .LBB3_9
302 ; CHECK-NEXT: .LBB3_16: # %lvalue_p.exit4
303 ; CHECK-NEXT: testb %al, %al
304 ; CHECK-NEXT: jne .LBB3_9
305 ; CHECK-NEXT: # %bb.17: # %lvalue_p.exit4
306 ; CHECK-NEXT: testb %bl, %bl
308 %tmp4 = load i8, ptr null, align 8 ; <i8> [#uses=3]
309 switch i8 %tmp4, label %bb3 [
314 switch i32 undef, label %bb1 [
320 switch i32 undef, label %bb1 [
321 i32 0, label %lvalue_p.exit
327 lvalue_p.exit: ; preds = %bb.i
328 %tmp21 = load ptr, ptr null, align 8 ; <ptr> [#uses=3]
329 %tmp22 = getelementptr inbounds %union.tree_node, ptr %tmp21, i64 0, i32 0, i32 0, i64 0 ; <ptr> [#uses=1]
330 %tmp23 = load i8, ptr %tmp22, align 8 ; <i8> [#uses=1]
331 %tmp24 = zext i8 %tmp23 to i32 ; <i32> [#uses=1]
332 switch i32 %tmp24, label %lvalue_p.exit4 [
337 bb.i1: ; preds = %lvalue_p.exit
338 %tmp25 = getelementptr inbounds %union.tree_node, ptr %tmp21, i64 0, i32 0, i32 2 ; <ptr> [#uses=1]
339 %tmp27 = load ptr, ptr %tmp25, align 8 ; <ptr> [#uses=2]
340 %tmp28 = getelementptr inbounds %union.tree_node, ptr %tmp27, i64 0, i32 0, i32 0, i64 16 ; <ptr> [#uses=1]
341 %tmp29 = load i8, ptr %tmp28, align 8 ; <i8> [#uses=1]
342 %tmp30 = zext i8 %tmp29 to i32 ; <i32> [#uses=1]
343 switch i32 %tmp30, label %lvalue_p.exit4 [
344 i32 0, label %bb2.i.i2
348 bb.i.i: ; preds = %bb.i1
349 %tmp34 = tail call fastcc i32 @lvalue_p(ptr null) nounwind ; <i32> [#uses=1]
350 %phitmp = icmp ne i32 %tmp34, 0 ; <i1> [#uses=1]
351 br label %lvalue_p.exit4
353 bb2.i.i2: ; preds = %bb.i1
354 %tmp35 = getelementptr inbounds %union.tree_node, ptr %tmp27, i64 0, i32 0, i32 0, i64 8 ; <ptr> [#uses=1]
355 %tmp37 = load ptr, ptr %tmp35, align 8 ; <ptr> [#uses=1]
356 %tmp38 = getelementptr inbounds %union.tree_node, ptr %tmp37, i64 0, i32 0, i32 0, i64 16 ; <ptr> [#uses=1]
357 %tmp39 = load i8, ptr %tmp38, align 8 ; <i8> [#uses=1]
358 switch i8 %tmp39, label %bb2 [
359 i8 16, label %lvalue_p.exit4
360 i8 23, label %lvalue_p.exit4
363 bb2.i3: ; preds = %lvalue_p.exit
364 %tmp40 = getelementptr inbounds %union.tree_node, ptr %tmp21, i64 0, i32 0, i32 0, i64 8 ; <ptr> [#uses=1]
365 %tmp42 = load ptr, ptr %tmp40, align 8 ; <ptr> [#uses=1]
366 %tmp43 = getelementptr inbounds %union.tree_node, ptr %tmp42, i64 0, i32 0, i32 0, i64 16 ; <ptr> [#uses=1]
367 %tmp44 = load i8, ptr %tmp43, align 8 ; <i8> [#uses=1]
368 switch i8 %tmp44, label %bb2 [
369 i8 16, label %lvalue_p.exit4
370 i8 23, label %lvalue_p.exit4
373 lvalue_p.exit4: ; preds = %bb2.i3, %bb2.i3, %bb2.i.i2, %bb2.i.i2, %bb.i.i, %bb.i1, %lvalue_p.exit
374 %tmp45 = phi i1 [ %phitmp, %bb.i.i ], [ false, %bb2.i.i2 ], [ false, %bb2.i.i2 ], [ false, %bb.i1 ], [ false, %bb2.i3 ], [ false, %bb2.i3 ], [ false, %lvalue_p.exit ] ; <i1> [#uses=1]
375 %tmp46 = icmp eq i8 %tmp4, 0 ; <i1> [#uses=1]
376 %or.cond = or i1 %tmp45, %tmp46 ; <i1> [#uses=1]
377 br i1 %or.cond, label %bb2, label %bb3
379 bb1: ; preds = %bb2.i.i, %bb.i, %bb
380 %.old = icmp eq i8 %tmp4, 23 ; <i1> [#uses=1]
381 br i1 %.old, label %bb2, label %bb3
383 bb2: ; preds = %bb1, %lvalue_p.exit4, %bb2.i3, %bb2.i.i2
386 bb3: ; preds = %bb2, %bb1, %lvalue_p.exit4, %bb2.i, %entry
387 %expr_addr.0 = phi ptr [ null, %bb2 ], [ %expr, %bb2.i ], [ %expr, %entry ], [ %expr, %bb1 ], [ %expr, %lvalue_p.exit4 ] ; <ptr> [#uses=0]
391 declare fastcc i32 @lvalue_p(ptr nocapture) nounwind readonly
393 declare fastcc ptr @default_conversion(ptr) nounwind
396 ; If one tail merging candidate falls through into the other,
397 ; tail merging is likely profitable regardless of how few
398 ; instructions are involved. This function should have only
399 ; one ret instruction.
401 define dso_local void @foo(ptr %V) nounwind {
403 ; CHECK: # %bb.0: # %entry
404 ; CHECK-NEXT: testq %rdi, %rdi
405 ; CHECK-NEXT: je .LBB4_2
406 ; CHECK-NEXT: # %bb.1: # %bb
407 ; CHECK-NEXT: pushq %rax
408 ; CHECK-NEXT: callq func
409 ; CHECK-NEXT: popq %rax
410 ; CHECK-NEXT: .LBB4_2: # %return
413 %t0 = icmp eq ptr %V, null
414 br i1 %t0, label %return, label %bb
424 declare dso_local void @func()
426 ; one - One instruction may be tail-duplicated even with optsize.
428 @XYZ = external dso_local global i32
430 declare dso_local void @tail_call_me()
432 define dso_local void @one(i32 %v) nounwind optsize {
434 ; CHECK: # %bb.0: # %entry
435 ; CHECK-NEXT: testl %edi, %edi
436 ; CHECK-NEXT: je .LBB5_3
437 ; CHECK-NEXT: # %bb.1: # %bby
438 ; CHECK-NEXT: cmpl $16, %edi
439 ; CHECK-NEXT: je .LBB5_4
440 ; CHECK-NEXT: # %bb.2: # %bb7
441 ; CHECK-NEXT: jmp tail_call_me # TAILCALL
442 ; CHECK-NEXT: .LBB5_3: # %bbx
443 ; CHECK-NEXT: cmpl $128, %edi
444 ; CHECK-NEXT: jne tail_call_me # TAILCALL
445 ; CHECK-NEXT: .LBB5_4: # %return
448 %0 = icmp eq i32 %v, 0
449 br i1 %0, label %bbx, label %bby
452 switch i32 %v, label %bb7 [
453 i32 16, label %return
457 tail call void @tail_call_me()
461 switch i32 %v, label %bb12 [
462 i32 128, label %return
466 tail call void @tail_call_me()
473 define dso_local void @one_pgso(i32 %v) nounwind !prof !14 {
474 ; CHECK-LABEL: one_pgso:
475 ; CHECK: # %bb.0: # %entry
476 ; CHECK-NEXT: testl %edi, %edi
477 ; CHECK-NEXT: je .LBB6_3
478 ; CHECK-NEXT: # %bb.1: # %bby
479 ; CHECK-NEXT: cmpl $16, %edi
480 ; CHECK-NEXT: je .LBB6_4
481 ; CHECK-NEXT: # %bb.2: # %bb7
482 ; CHECK-NEXT: jmp tail_call_me # TAILCALL
483 ; CHECK-NEXT: .LBB6_3: # %bbx
484 ; CHECK-NEXT: cmpl $128, %edi
485 ; CHECK-NEXT: jne tail_call_me # TAILCALL
486 ; CHECK-NEXT: .LBB6_4: # %return
489 %0 = icmp eq i32 %v, 0
490 br i1 %0, label %bbx, label %bby
493 switch i32 %v, label %bb7 [
494 i32 16, label %return
498 tail call void @tail_call_me()
502 switch i32 %v, label %bb12 [
503 i32 128, label %return
507 tail call void @tail_call_me()
514 ; two - Same as one, but with two instructions in the common
515 ; tail instead of one. This is too much to be merged, given
516 ; the optsize attribute.
518 define dso_local void @two() nounwind optsize {
520 ; CHECK: # %bb.0: # %entry
521 ; CHECK-NEXT: xorl %eax, %eax
522 ; CHECK-NEXT: testb %al, %al
523 ; CHECK-NEXT: xorl %eax, %eax
524 ; CHECK-NEXT: testb %al, %al
525 ; CHECK-NEXT: je .LBB7_1
526 ; CHECK-NEXT: # %bb.2: # %return
528 ; CHECK-NEXT: .LBB7_1: # %bb7
529 ; CHECK-NEXT: movl $0, XYZ(%rip)
530 ; CHECK-NEXT: movl $1, XYZ(%rip)
532 %0 = icmp eq i32 undef, 0
533 br i1 %0, label %bbx, label %bby
536 switch i32 undef, label %bb7 [
537 i32 16, label %return
541 store volatile i32 0, ptr @XYZ
542 store volatile i32 1, ptr @XYZ
546 switch i32 undef, label %bb12 [
547 i32 128, label %return
551 store volatile i32 0, ptr @XYZ
552 store volatile i32 1, ptr @XYZ
559 define dso_local void @two_pgso() nounwind !prof !14 {
560 ; CHECK-LABEL: two_pgso:
561 ; CHECK: # %bb.0: # %entry
562 ; CHECK-NEXT: xorl %eax, %eax
563 ; CHECK-NEXT: testb %al, %al
564 ; CHECK-NEXT: xorl %eax, %eax
565 ; CHECK-NEXT: testb %al, %al
566 ; CHECK-NEXT: je .LBB8_1
567 ; CHECK-NEXT: # %bb.2: # %return
569 ; CHECK-NEXT: .LBB8_1: # %bb7
570 ; CHECK-NEXT: movl $0, XYZ(%rip)
571 ; CHECK-NEXT: movl $1, XYZ(%rip)
573 %0 = icmp eq i32 undef, 0
574 br i1 %0, label %bbx, label %bby
577 switch i32 undef, label %bb7 [
578 i32 16, label %return
582 store volatile i32 0, ptr @XYZ
583 store volatile i32 1, ptr @XYZ
587 switch i32 undef, label %bb12 [
588 i32 128, label %return
592 store volatile i32 0, ptr @XYZ
593 store volatile i32 1, ptr @XYZ
600 ; two_minsize - Same as two, but with minsize instead of optsize.
602 define dso_local void @two_minsize() nounwind minsize {
603 ; CHECK-LABEL: two_minsize:
604 ; CHECK: # %bb.0: # %entry
605 ; CHECK-NEXT: xorl %eax, %eax
606 ; CHECK-NEXT: testb %al, %al
607 ; CHECK-NEXT: xorl %eax, %eax
608 ; CHECK-NEXT: testb %al, %al
609 ; CHECK-NEXT: je .LBB9_1
610 ; CHECK-NEXT: # %bb.2: # %return
612 ; CHECK-NEXT: .LBB9_1: # %bb7
613 ; CHECK-NEXT: movl $0, XYZ(%rip)
614 ; CHECK-NEXT: movl $1, XYZ(%rip)
616 %0 = icmp eq i32 undef, 0
617 br i1 %0, label %bbx, label %bby
620 switch i32 undef, label %bb7 [
621 i32 16, label %return
625 store volatile i32 0, ptr @XYZ
626 store volatile i32 1, ptr @XYZ
630 switch i32 undef, label %bb12 [
631 i32 128, label %return
635 store volatile i32 0, ptr @XYZ
636 store volatile i32 1, ptr @XYZ
643 ; two_nosize - Same as two, but without the optsize attribute.
644 ; Now two instructions are enough to be tail-duplicated.
646 define dso_local void @two_nosize(i32 %x, i32 %y, i32 %z) nounwind {
647 ; CHECK-LABEL: two_nosize:
648 ; CHECK: # %bb.0: # %entry
649 ; CHECK-NEXT: testl %edi, %edi
650 ; CHECK-NEXT: je .LBB10_3
651 ; CHECK-NEXT: # %bb.1: # %bby
652 ; CHECK-NEXT: testl %esi, %esi
653 ; CHECK-NEXT: je .LBB10_4
654 ; CHECK-NEXT: # %bb.2: # %bb7
655 ; CHECK-NEXT: movl $0, XYZ(%rip)
656 ; CHECK-NEXT: jmp tail_call_me # TAILCALL
657 ; CHECK-NEXT: .LBB10_3: # %bbx
658 ; CHECK-NEXT: cmpl $-1, %edx
659 ; CHECK-NEXT: je .LBB10_4
660 ; CHECK-NEXT: # %bb.5: # %bb12
661 ; CHECK-NEXT: movl $0, XYZ(%rip)
662 ; CHECK-NEXT: jmp tail_call_me # TAILCALL
663 ; CHECK-NEXT: .LBB10_4: # %return
666 %0 = icmp eq i32 %x, 0
667 br i1 %0, label %bbx, label %bby
670 switch i32 %y, label %bb7 [
675 store volatile i32 0, ptr @XYZ
676 tail call void @tail_call_me()
680 switch i32 %z, label %bb12 [
681 i32 -1, label %return
685 store volatile i32 0, ptr @XYZ
686 tail call void @tail_call_me()
693 ; Tail-merging should merge the two ret instructions since one side
694 ; can fall-through into the ret and the other side has to branch anyway.
696 define i64 @TESTE(i64 %parami, i64 %paraml) nounwind readnone {
697 ; CHECK-LABEL: TESTE:
698 ; CHECK: # %bb.0: # %entry
699 ; CHECK-NEXT: testq %rdi, %rdi
700 ; CHECK-NEXT: movl $1, %eax
701 ; CHECK-NEXT: cmovgq %rdi, %rax
702 ; CHECK-NEXT: testq %rsi, %rsi
703 ; CHECK-NEXT: jle .LBB11_2
704 ; CHECK-NEXT: # %bb.1: # %bb.nph
705 ; CHECK-NEXT: imulq %rdi, %rsi
706 ; CHECK-NEXT: movq %rsi, %rax
707 ; CHECK-NEXT: .LBB11_2: # %for.end
710 %cmp = icmp slt i64 %parami, 1 ; <i1> [#uses=1]
711 %varx.0 = select i1 %cmp, i64 1, i64 %parami ; <i64> [#uses=1]
712 %cmp410 = icmp slt i64 %paraml, 1 ; <i1> [#uses=1]
713 br i1 %cmp410, label %for.end, label %bb.nph
715 bb.nph: ; preds = %entry
716 %tmp15 = mul i64 %paraml, %parami ; <i64> [#uses=1]
719 for.end: ; preds = %entry
723 ; We should tail merge small blocks that don't end in a tail call or return
724 ; instruction. Those blocks are typically unreachable and will be placed
725 ; out-of-line after the main return, so we should try to eliminate as many of
728 declare dso_local void @abort()
729 define dso_local void @merge_aborts() {
730 ; CHECK-LABEL: merge_aborts:
731 ; CHECK: # %bb.0: # %entry
732 ; CHECK-NEXT: pushq %rax
733 ; CHECK-NEXT: .cfi_def_cfa_offset 16
734 ; CHECK-NEXT: callq qux@PLT
735 ; CHECK-NEXT: testb $1, %al
736 ; CHECK-NEXT: je .LBB12_5
737 ; CHECK-NEXT: # %bb.1: # %cont1
738 ; CHECK-NEXT: callq qux@PLT
739 ; CHECK-NEXT: testb $1, %al
740 ; CHECK-NEXT: je .LBB12_5
741 ; CHECK-NEXT: # %bb.2: # %cont2
742 ; CHECK-NEXT: callq qux@PLT
743 ; CHECK-NEXT: testb $1, %al
744 ; CHECK-NEXT: je .LBB12_5
745 ; CHECK-NEXT: # %bb.3: # %cont3
746 ; CHECK-NEXT: callq qux@PLT
747 ; CHECK-NEXT: testb $1, %al
748 ; CHECK-NEXT: je .LBB12_5
749 ; CHECK-NEXT: # %bb.4: # %cont4
750 ; CHECK-NEXT: popq %rax
751 ; CHECK-NEXT: .cfi_def_cfa_offset 8
753 ; CHECK-NEXT: .LBB12_5: # %abort1
754 ; CHECK-NEXT: .cfi_def_cfa_offset 16
755 ; CHECK-NEXT: callq abort
758 br i1 %c1, label %cont1, label %abort1
764 br i1 %c2, label %cont2, label %abort2
770 br i1 %c3, label %cont3, label %abort3
776 br i1 %c4, label %cont4, label %abort4
784 ; Use alternating abort functions so that the blocks we wish to merge are not
785 ; layout successors during branch folding.
787 declare dso_local void @alt_abort()
789 define dso_local void @merge_alternating_aborts() {
790 ; CHECK-LABEL: merge_alternating_aborts:
791 ; CHECK: # %bb.0: # %entry
792 ; CHECK-NEXT: pushq %rax
793 ; CHECK-NEXT: .cfi_def_cfa_offset 16
794 ; CHECK-NEXT: callq qux@PLT
795 ; CHECK-NEXT: testb $1, %al
796 ; CHECK-NEXT: je .LBB13_5
797 ; CHECK-NEXT: # %bb.1: # %cont1
798 ; CHECK-NEXT: callq qux@PLT
799 ; CHECK-NEXT: testb $1, %al
800 ; CHECK-NEXT: je .LBB13_6
801 ; CHECK-NEXT: # %bb.2: # %cont2
802 ; CHECK-NEXT: callq qux@PLT
803 ; CHECK-NEXT: testb $1, %al
804 ; CHECK-NEXT: je .LBB13_5
805 ; CHECK-NEXT: # %bb.3: # %cont3
806 ; CHECK-NEXT: callq qux@PLT
807 ; CHECK-NEXT: testb $1, %al
808 ; CHECK-NEXT: je .LBB13_6
809 ; CHECK-NEXT: # %bb.4: # %cont4
810 ; CHECK-NEXT: popq %rax
811 ; CHECK-NEXT: .cfi_def_cfa_offset 8
813 ; CHECK-NEXT: .LBB13_5: # %abort1
814 ; CHECK-NEXT: .cfi_def_cfa_offset 16
815 ; CHECK-NEXT: callq abort
816 ; CHECK-NEXT: .LBB13_6: # %abort2
817 ; CHECK-NEXT: callq alt_abort
820 br i1 %c1, label %cont1, label %abort1
826 br i1 %c2, label %cont2, label %abort2
828 call void @alt_abort()
832 br i1 %c3, label %cont3, label %abort3
838 br i1 %c4, label %cont4, label %abort4
840 call void @alt_abort()
846 ; This triggers a situation where a new block (bb4 is split) is created and then
847 ; would be passed to the PGSO interface llvm::shouldOptimizeForSize().
848 @GV = dso_local global i32 0
849 define dso_local void @bfi_new_block_pgso(i32 %c) nounwind {
850 ; CHECK-LABEL: bfi_new_block_pgso:
851 ; CHECK: # %bb.0: # %entry
852 ; CHECK-NEXT: testl %edi, %edi
853 ; CHECK-NEXT: je .LBB14_6
854 ; CHECK-NEXT: # %bb.1: # %bb1
855 ; CHECK-NEXT: pushq %rax
856 ; CHECK-NEXT: cmpl $16, %edi
857 ; CHECK-NEXT: je .LBB14_3
858 ; CHECK-NEXT: # %bb.2: # %bb1
859 ; CHECK-NEXT: cmpl $17, %edi
860 ; CHECK-NEXT: je .LBB14_4
861 ; CHECK-NEXT: # %bb.5: # %bb4
862 ; CHECK-NEXT: popq %rax
863 ; CHECK-NEXT: jmp tail_call_me # TAILCALL
864 ; CHECK-NEXT: .LBB14_6: # %bb5
865 ; CHECK-NEXT: cmpl $128, %edi
866 ; CHECK-NEXT: jne tail_call_me # TAILCALL
867 ; CHECK-NEXT: # %bb.7: # %return
869 ; CHECK-NEXT: .LBB14_3: # %bb3
870 ; CHECK-NEXT: movl $0, GV(%rip)
871 ; CHECK-NEXT: .LBB14_4: # %bb4
872 ; CHECK-NEXT: callq func
873 ; CHECK-NEXT: popq %rax
874 ; CHECK-NEXT: jmp tail_call_me # TAILCALL
876 %0 = icmp eq i32 %c, 0
877 br i1 %0, label %bb5, label %bb1
880 switch i32 %c, label %bb4 [
895 tail call void @tail_call_me()
899 switch i32 %c, label %bb6 [
900 i32 128, label %return
904 tail call void @tail_call_me()
911 !llvm.module.flags = !{!0}
912 !0 = !{i32 1, !"ProfileSummary", !1}
913 !1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
914 !2 = !{!"ProfileFormat", !"InstrProf"}
915 !3 = !{!"TotalCount", i64 10000}
916 !4 = !{!"MaxCount", i64 10}
917 !5 = !{!"MaxInternalCount", i64 1}
918 !6 = !{!"MaxFunctionCount", i64 1000}
919 !7 = !{!"NumCounts", i64 3}
920 !8 = !{!"NumFunctions", i64 3}
921 !9 = !{!"DetailedSummary", !10}
922 !10 = !{!11, !12, !13}
923 !11 = !{i32 10000, i64 100, i32 1}
924 !12 = !{i32 999000, i64 100, i32 1}
925 !13 = !{i32 999999, i64 1, i32 2}
926 !14 = !{!"function_entry_count", i64 0}