xref: /llvm-project/llvm/test/Transforms/CodeExtractor/PartialInlineHighCost.ll (revision 3528e63d89305907b3d6e0f59f7b03b94a12dacc)
1; The outlined region has high frequency  and the outlining
2; call sequence is expensive (input, output, multiple exit etc)
3; RUN: opt < %s -passes=partial-inliner -max-num-inline-blocks=2 -S | FileCheck %s
4; RUN: opt < %s -passes=partial-inliner -skip-partial-inlining-cost-analysis -max-num-inline-blocks=2 -S | FileCheck  --check-prefix=NOCOST %s
5
6
7; Function Attrs: nounwind
8define i32 @bar_hot_outline_region(i32 %arg) local_unnamed_addr #0 {
9bb:
10  %tmp = icmp slt i32 %arg, 0
11  br i1 %tmp, label %bb1, label %bb16, !prof !1
12
13bb1:                                              ; preds = %bb
14  %tmp2 = tail call i32 (...) @foo() #0
15  %tmp3 = tail call i32 (...) @foo() #0
16  %tmp4 = tail call i32 (...) @foo() #0
17  %tmp5 = tail call i32 (...) @foo() #0
18  %tmp6 = tail call i32 (...) @foo() #0
19  %tmp7 = tail call i32 (...) @foo() #0
20  %tmp8 = add nsw i32 %arg, 1
21  %tmp9 = tail call i32 @goo(i32 %tmp8) #0
22  %tmp10 = tail call i32 (...) @foo() #0
23  %tmp11 = icmp eq i32 %tmp10, 0
24  br i1 %tmp11, label %bb12, label %bb16
25
26bb12:                                             ; preds = %bb1
27  %tmp13 = tail call i32 (...) @foo() #0
28  %tmp14 = icmp eq i32 %tmp13, 0
29  %tmp15 = select i1 %tmp14, i32 0, i32 3
30  br label %bb16
31
32bb16:                                             ; preds = %bb12, %bb1, %bb
33  %tmp17 = phi i32 [ 2, %bb1 ], [ %tmp15, %bb12 ], [ 0, %bb ]
34  ret i32 %tmp17
35}
36
37define i32 @bar_cold_outline_region(i32 %arg) local_unnamed_addr #0 {
38bb:
39  %tmp = icmp slt i32 %arg, 0
40  br i1 %tmp, label %bb1, label %bb16, !prof !2
41
42bb1:                                              ; preds = %bb
43  %tmp2 = tail call i32 (...) @foo() #0
44  %tmp3 = tail call i32 (...) @foo() #0
45  %tmp4 = tail call i32 (...) @foo() #0
46  %tmp5 = tail call i32 (...) @foo() #0
47  %tmp6 = tail call i32 (...) @foo() #0
48  %tmp7 = tail call i32 (...) @foo() #0
49  %tmp8 = add nsw i32 %arg, 1
50  %tmp9 = tail call i32 @goo(i32 %tmp8) #0
51  %tmp10 = tail call i32 (...) @foo() #0
52  %tmp11 = icmp eq i32 %tmp10, 0
53  br i1 %tmp11, label %bb12, label %bb16
54
55bb12:                                             ; preds = %bb1
56  %tmp13 = tail call i32 (...) @foo() #0
57  %tmp14 = icmp eq i32 %tmp13, 0
58  %tmp15 = select i1 %tmp14, i32 0, i32 3
59  br label %bb16
60
61bb16:                                             ; preds = %bb12, %bb1, %bb
62  %tmp17 = phi i32 [ 2, %bb1 ], [ %tmp15, %bb12 ], [ 0, %bb ]
63  ret i32 %tmp17
64}
65
66; Function Attrs: nounwind
67declare i32 @foo(...) local_unnamed_addr #0
68
69; Function Attrs: nounwind
70declare i32 @goo(i32) local_unnamed_addr #0
71
72; Function Attrs: nounwind
73define i32 @dummy_caller(i32 %arg) local_unnamed_addr #0 {
74bb:
75; CHECK-LABEL: @dummy_caller
76; CHECK-NOT: br i1
77; CHECK-NOT: call{{.*}}bar_hot_outline_region.
78; NOCOST-LABEL: @dummy_caller
79; NOCOST: br i1
80; NOCOST: call{{.*}}bar_hot_outline_region.
81
82  %tmp = tail call i32 @bar_hot_outline_region(i32 %arg)
83  ret i32 %tmp
84}
85
86define i32 @dummy_caller2(i32 %arg) local_unnamed_addr #0 {
87bb:
88; CHECK-LABEL: @dummy_caller2
89; CHECK: br i1
90; CHECK: call{{.*}}bar_cold_outline_region.
91; NOCOST-LABEL: @dummy_caller2
92; NOCOST: br i1
93; NOCOST: call{{.*}}bar_cold_outline_region.
94
95  %tmp = tail call i32 @bar_cold_outline_region(i32 %arg)
96  ret i32 %tmp
97}
98
99attributes #0 = { nounwind }
100
101!llvm.ident = !{!0}
102
103!0 = !{!"clang version 5.0.0 (trunk 301898)"}
104!1 = !{!"branch_weights", i32 2000, i32 1}
105!2 = !{!"branch_weights", i32 1, i32 100}
106