f030775d535429de11aad3cce4a8a92ea04a5e14
[oota-llvm.git] / test / CodeGen / Generic / MachineBranchProb.ll
1 ; RUN: llc < %s -print-machineinstrs=expand-isel-pseudos -o /dev/null 2>&1 | FileCheck %s
2
3 ; ARM & AArch64 run an extra SimplifyCFG which disrupts this test.
4 ; XFAIL: arm,aarch64
5
6 ; Make sure we have the correct weight attached to each successor.
7 define i32 @test2(i32 %x) nounwind uwtable readnone ssp {
8 ; CHECK-LABEL: Machine code for function test2:
9 entry:
10   %conv = sext i32 %x to i64
11   switch i64 %conv, label %return [
12     i64 0, label %sw.bb
13     i64 1, label %sw.bb
14     i64 4, label %sw.bb
15     i64 5, label %sw.bb1
16   ], !prof !0
17 ; CHECK: BB#0: derived from LLVM BB %entry
18 ; CHECK: Successors according to CFG: BB#2(64) BB#4(14)
19 ; CHECK: BB#4: derived from LLVM BB %entry
20 ; CHECK: Successors according to CFG: BB#1(10) BB#5(4)
21 ; CHECK: BB#5: derived from LLVM BB %entry
22 ; CHECK: Successors according to CFG: BB#1(4) BB#3(7)
23
24 sw.bb:
25   br label %return
26
27 sw.bb1:
28   br label %return
29
30 return:
31   %retval.0 = phi i32 [ 5, %sw.bb1 ], [ 1, %sw.bb ], [ 0, %entry ]
32   ret i32 %retval.0
33 }
34
35 !0 = !{!"branch_weights", i32 7, i32 6, i32 4, i32 4, i32 64}
36
37
38 declare void @g(i32)
39 define void @left_leaning_weight_balanced_tree(i32 %x) {
40 entry:
41   switch i32 %x, label %return [
42     i32 0,  label %bb0
43     i32 10, label %bb1
44     i32 20, label %bb2
45     i32 30, label %bb3
46     i32 40, label %bb4
47     i32 50, label %bb5
48   ], !prof !1
49 bb0: tail call void @g(i32 0) br label %return
50 bb1: tail call void @g(i32 1) br label %return
51 bb2: tail call void @g(i32 2) br label %return
52 bb3: tail call void @g(i32 3) br label %return
53 bb4: tail call void @g(i32 4) br label %return
54 bb5: tail call void @g(i32 5) br label %return
55 return: ret void
56
57 ; Check that we set branch weights on the pivot cmp instruction correctly.
58 ; Cases {0,10,20,30} go on the left with weight 13; cases {40,50} go on the
59 ; right with weight 20.
60 ;
61 ; CHECK-LABEL: Machine code for function left_leaning_weight_balanced_tree:
62 ; CHECK: BB#0: derived from LLVM BB %entry
63 ; CHECK-NOT: Successors
64 ; CHECK: Successors according to CFG: BB#8(13) BB#9(20)
65 }
66
67 !1 = !{!"branch_weights",
68   ; Default:
69   i32 1,
70   ; Case 0, 10, 20:
71   i32 10, i32 1, i32 1,
72   ; Case 30, 40, 50:
73   i32 1, i32 10, i32 10}