1 ;; See also llvm/unittests/Transforms/Utils/CodeLayoutTest.cpp
2 ; RUN: llc -mcpu=corei7 -mtriple=x86_64-linux -enable-ext-tsp-block-placement=1 < %s | FileCheck %s
4 define void @func1a() {
5 ; Test that the algorithm positions the most likely successor first
23 ; CHECK-LABEL: func1a:
29 %call = call zeroext i1 @a()
30 br i1 %call, label %b1, label %b2, !prof !1
44 define void @func1b() {
45 ; Test that the algorithm prefers many fallthroughs even in the presence of
64 ; CHECK-LABEL: func1b:
70 %call = call zeroext i1 @a()
71 br i1 %call, label %b1, label %b2, !prof !2
85 define void @func2() !prof !3 {
86 ; Test that the algorithm positions the hot chain continuously
88 ; +----+ [7] +-------+
89 ; | b1 | <----- | b0 |
112 ; CHECK-LABEL: func2:
123 %call = call zeroext i1 @a()
124 br i1 %call, label %b1, label %b3, !prof !4
147 %call2 = call zeroext i1 @a()
148 br i1 %call2, label %b2, label %b4, !prof !5
152 define void @func3() !prof !6 {
153 ; A larger test where it is beneficial for locality to break the loop
161 ; +----+ [177] +---------------------------+
162 ; | b5 | <------- | b1 |
163 ; +----+ +---------------------------+
165 ; | [196] | [124] | [70]
167 ; +----+ [70] +--------+ | |
168 ; | b4 | <------- | b2 | | |
169 ; +----+ +--------+ | |
177 ; +-----------------------------------+
179 ; CHECK-LABEL: func3:
209 %call = call zeroext i1 @a()
210 br i1 %call, label %b5, label %b2, !prof !7
217 %call2 = call zeroext i1 @a()
218 br i1 %call2, label %b3, label %b4, !prof !8
268 define void @func_loop() !prof !9 {
269 ; Test that the algorithm can rotate loops in the presence of profile data.
277 ; +--------+ 16 +--------+
278 ; | if.then| <---- | header | <+
279 ; +--------+ +--------+ |
290 ; +------------> | if.end | -+
299 ; CHECK-LABEL: func_loop:
310 %call = call zeroext i1 @a()
311 br i1 %call, label %if.then, label %if.else, !prof !10
323 %call2 = call zeroext i1 @a()
324 br i1 %call2, label %header, label %end
330 define void @func4() !prof !11 {
331 ; Test verifying that chains can be split in order to improve the objective
332 ; by creating more fallthroughs
356 ; CHECK-LABEL: func4:
364 %call2 = call zeroext i1 @a()
365 br i1 %call2, label %b1, label %b2, !prof !12
369 %call = call zeroext i1 @a()
370 br i1 %call, label %b2, label %b3, !prof !13
381 declare zeroext i1 @a()
390 !1 = !{!"branch_weights", i32 40, i32 100}
391 !2 = !{!"branch_weights", i32 80, i32 100}
392 !3 = !{!"function_entry_count", i64 2200}
393 !4 = !{!"branch_weights", i32 700, i32 1500}
394 !5 = !{!"branch_weights", i32 1500, i32 3100}
395 !6 = !{!"function_entry_count", i64 177}
396 !7 = !{!"branch_weights", i32 177, i32 196}
397 !8 = !{!"branch_weights", i32 125, i32 70}
398 !9 = !{!"function_entry_count", i64 1}
399 !10 = !{!"branch_weights", i32 16, i32 16}
400 !11 = !{!"function_entry_count", i64 1}
401 !12 = !{!"branch_weights", i32 27, i32 0}
402 !13 = !{!"branch_weights", i32 17, i32 10}