xref: /llvm-project/llvm/test/CodeGen/X86/sink-blockfreq.ll (revision 57c33acac8c74eb071ede35d819918d8bd00e45b)
1; RUN: llc -disable-preheader-prot=true -disable-machine-licm -machine-sink-bfi=true -mtriple=x86_64-apple-darwin < %s | FileCheck %s -check-prefix=MSINK_BFI
2; RUN: llc -disable-preheader-prot=true -disable-machine-licm -machine-sink-bfi=false -mtriple=x86_64-apple-darwin < %s | FileCheck %s -check-prefix=MSINK_NOBFI
3; RUN: llc -disable-preheader-prot=true -disable-machine-licm -machine-sink-bfi=true -force-pgso -mtriple=x86_64-apple-darwin < %s | FileCheck %s -check-prefix=MSINK_NOBFI
4
5; Test that by changing BlockFrequencyInfo we change the order in which
6; machine-sink looks for successor blocks. By not using BFI, both G and B
7; have the same loop depth and no instructions is sinked - B is selected but
8; can't be used as to avoid breaking a non profitable critical edge. By using
9; BFI, "mul" is sinked into the less frequent block G.
10define i32 @sink_freqinfo(i32 %a, i32 %b) nounwind uwtable ssp !prof !14 {
11; MSINK_BFI-LABEL: sink_freqinfo
12; MSINK_BFI: jl
13; MSINK_BFI-NEXT: ## %bb.
14; MSINK_BFI-NEXT: imull
15
16; MSINK_NOBFI-LABEL: sink_freqinfo
17; MSINK_NOBFI: imull
18; MSINK_NOBFI: jl
19entry:
20  br label %B
21
22B:
23  %ee = phi i32 [ 0, %entry ], [ %inc, %F ]
24  %xx = sub i32 %a, %ee
25  %cond0 = icmp slt i32 %xx, 0
26  br i1 %cond0, label %F, label %exit, !prof !15
27
28F:
29  %inc = add nsw i32 %xx, 2
30  %aa = mul nsw i32 %b, %inc
31  %exitcond = icmp slt i32 %inc, %a
32  br i1 %exitcond, label %B, label %G, !prof !16
33
34G:
35  %ii = add nsw i32 %aa, %a
36  %ll = add i32 %b, 45
37  %exitcond2 = icmp sge i32 %ii, %b
38  br i1 %exitcond2, label %G, label %exit, !prof !17
39
40exit:
41  ret i32 0
42}
43
44!llvm.module.flags = !{!0}
45!0 = !{i32 1, !"ProfileSummary", !1}
46!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
47!2 = !{!"ProfileFormat", !"InstrProf"}
48!3 = !{!"TotalCount", i64 10000}
49!4 = !{!"MaxCount", i64 10}
50!5 = !{!"MaxInternalCount", i64 1}
51!6 = !{!"MaxFunctionCount", i64 1000}
52!7 = !{!"NumCounts", i64 3}
53!8 = !{!"NumFunctions", i64 3}
54!9 = !{!"DetailedSummary", !10}
55!10 = !{!11, !12, !13}
56!11 = !{i32 10000, i64 100, i32 1}
57!12 = !{i32 999000, i64 100, i32 1}
58!13 = !{i32 999999, i64 1, i32 2}
59!14 = !{!"function_entry_count", i64 1000}
60!15 = !{!"branch_weights", i32 4, i32 1}
61!16 = !{!"branch_weights", i32 128, i32 1}
62!17 = !{!"branch_weights", i32 1, i32 1}
63