1; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions | FileCheck %s -check-prefix=MFS-DEFAULTS
2; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions -mfs-psi-cutoff=0 -mfs-count-threshold=2000 | FileCheck %s --dump-input=always -check-prefix=MFS-OPTS1
3; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions -mfs-psi-cutoff=950000 | FileCheck %s -check-prefix=MFS-OPTS2
4
5define void @foo1(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
6;; Check that cold block is moved to .text.split.
7; MFS-DEFAULTS-LABEL: foo1
8; MFS-DEFAULTS:       .section        .text.split.foo1
9; MFS-DEFAULTS-NEXT:  foo1.cold:
10; MFS-DEFAULTS-NOT:   callq   bar
11; MFS-DEFAULTS-NEXT:  callq   baz
12  br i1 %0, label %2, label %4, !prof !17
13
142:                                                ; preds = %1
15  %3 = call i32 @bar()
16  br label %6
17
184:                                                ; preds = %1
19  %5 = call i32 @baz()
20  br label %6
21
226:                                                ; preds = %4, %2
23  %7 = tail call i32 @qux()
24  ret void
25}
26
27define void @foo2(i1 zeroext %0) nounwind !prof !23 !section_prefix !16 {
28;; Check that function marked unlikely is not split.
29; MFS-DEFAULTS-LABEL: foo2
30; MFS-DEFAULTS-NOT:   foo2.cold:
31  br i1 %0, label %2, label %4, !prof !17
32
332:                                                ; preds = %1
34  %3 = call i32 @bar()
35  br label %6
36
374:                                                ; preds = %1
38  %5 = call i32 @baz()
39  br label %6
40
416:                                                ; preds = %4, %2
42  %7 = tail call i32 @qux()
43  ret void
44}
45
46define void @foo3(i1 zeroext %0) nounwind !section_prefix !15 {
47;; Check that function without profile data is not split.
48; MFS-DEFAULTS-LABEL: foo3
49; MFS-DEFAULTS-NOT:   foo3.cold:
50  br i1 %0, label %2, label %4
51
522:                                                ; preds = %1
53  %3 = call i32 @bar()
54  br label %6
55
564:                                                ; preds = %1
57  %5 = call i32 @baz()
58  br label %6
59
606:                                                ; preds = %4, %2
61  %7 = tail call i32 @qux()
62  ret void
63}
64
65define void @foo4(i1 zeroext %0, i1 zeroext %1) nounwind !prof !20 {
66;; Check that count threshold works.
67; MFS-OPTS1-LABEL: foo4
68; MFS-OPTS1:       .section        .text.split.foo4
69; MFS-OPTS1-NEXT:  foo4.cold:
70; MFS-OPTS1-NOT:   callq    bar
71; MFS-OPTS1-NOT:   callq    baz
72; MFS-OPTS1-NEXT:  callq    bam
73  br i1 %0, label %3, label %7, !prof !18
74
753:
76  %4 = call i32 @bar()
77  br label %7
78
795:
80  %6 = call i32 @baz()
81  br label %7
82
837:
84  br i1 %1, label %8, label %10, !prof !19
85
868:
87  %9 = call i32 @bam()
88  br label %12
89
9010:
91  %11 = call i32 @baz()
92  br label %12
93
9412:
95  %13 = tail call i32 @qux()
96  ret void
97}
98
99define void @foo5(i1 zeroext %0, i1 zeroext %1) nounwind !prof !20 {
100;; Check that profile summary info cutoff works.
101; MFS-OPTS2-LABEL: foo5
102; MFS-OPTS2:       .section        .text.split.foo5
103; MFS-OPTS2-NEXT:       foo5.cold:
104; MFS-OPTS2-NOT:   callq    bar
105; MFS-OPTS2-NOT:   callq    baz
106; MFS-OPTS2-NEXT:  callq    bam
107  br i1 %0, label %3, label %7, !prof !21
108
1093:
110  %4 = call i32 @bar()
111  br label %7
112
1135:
114  %6 = call i32 @baz()
115  br label %7
116
1177:
118  br i1 %1, label %8, label %10, !prof !22
119
1208:
121  %9 = call i32 @bam()
122  br label %12
123
12410:
125  %11 = call i32 @baz()
126  br label %12
127
12812:
129  %13 = call i32 @qux()
130  ret void
131}
132
133define void @foo6(i1 zeroext %0) nounwind section "nosplit" !prof !14 {
134;; Check that function with section attribute is not split.
135; MFS-DEFAULTS-LABEL: foo6
136; MFS-DEFAULTS-NOT:   foo6.cold:
137  br i1 %0, label %2, label %4, !prof !17
138
1392:                                                ; preds = %1
140  %3 = call i32 @bar()
141  br label %6
142
1434:                                                ; preds = %1
144  %5 = call i32 @baz()
145  br label %6
146
1476:                                                ; preds = %4, %2
148  %7 = tail call i32 @qux()
149  ret void
150}
151
152define i32 @foo7(i1 zeroext %0) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) !prof !14 {
153;; Check that cold ehpads are not split out.
154; MFS-DEFAULTS-LABEL: foo7
155; MFS-DEFAULTS:       .section        .text.split.foo7,"ax",@progbits
156; MFS-DEFAULTS-NEXT:  foo7.cold:
157; MFS-DEFAULTS-NOT:   callq   _Unwind_Resume
158; MFS-DEFAULTS:       callq   baz
159entry:
160  invoke void @_Z1fv()
161          to label %try.cont unwind label %lpad
162
163lpad:
164  %1 = landingpad { i8*, i32 }
165          cleanup
166          catch i8* bitcast (i8** @_ZTIi to i8*)
167  resume { i8*, i32 } %1
168
169try.cont:
170  br i1 %0, label %2, label %4, !prof !17
171
1722:                                                ; preds = try.cont
173  %3 = call i32 @bar()
174  br label %6
175
1764:                                                ; preds = %1
177  %5 = call i32 @baz()
178  br label %6
179
1806:                                                ; preds = %4, %2
181  %7 = tail call i32 @qux()
182  ret i32 %7
183}
184
185declare i32 @bar()
186declare i32 @baz()
187declare i32 @bam()
188declare i32 @qux()
189declare void @_Z1fv()
190declare i32 @__gxx_personality_v0(...)
191
192@_ZTIi = external constant i8*
193
194!llvm.module.flags = !{!0}
195!0 = !{i32 1, !"ProfileSummary", !1}
196!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
197!2 = !{!"ProfileFormat", !"InstrProf"}
198!3 = !{!"TotalCount", i64 10000}
199!4 = !{!"MaxCount", i64 10}
200!5 = !{!"MaxInternalCount", i64 1}
201!6 = !{!"MaxFunctionCount", i64 1000}
202!7 = !{!"NumCounts", i64 3}
203!8 = !{!"NumFunctions", i64 5}
204!9 = !{!"DetailedSummary", !10}
205!10 = !{!11, !12, !13}
206!11 = !{i32 10000, i64 100, i32 1}
207!12 = !{i32 999900, i64 100, i32 1}
208!13 = !{i32 999999, i64 1, i32 2}
209!14 = !{!"function_entry_count", i64 7000}
210!15 = !{!"function_section_prefix", !"hot"}
211!16 = !{!"function_section_prefix", !"unlikely"}
212!17 = !{!"branch_weights", i32 7000, i32 0}
213!18 = !{!"branch_weights", i32 3000, i32 4000}
214!19 = !{!"branch_weights", i32 1000, i32 6000}
215!20 = !{!"function_entry_count", i64 10000}
216!21 = !{!"branch_weights", i32 6000, i32 4000}
217!22 = !{!"branch_weights", i32 80, i32 9920}
218!23 = !{!"function_entry_count", i64 7}
219