1; RUN: opt < %s -analyze -branch-prob | FileCheck %s
2; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
3
4; In this test, the else clause is taken about 90% of the time. This was not
5; reflected in the probability computation because the weight is larger than
6; the branch weight cap (about 2 billion).
7;
8; CHECK: edge for.body -> if.then probability is 0x0cccba45 / 0x80000000 = 10.00%
9; CHECK: edge for.body -> if.else probability is 0x733345bb / 0x80000000 = 90.00% [HOT edge]
10
11@y = common global i64 0, align 8
12@x = common global i64 0, align 8
13@.str = private unnamed_addr constant [17 x i8] c"x = %lu\0Ay = %lu\0A\00", align 1
14
15; Function Attrs: inlinehint nounwind uwtable
16define i32 @main() #0 {
17entry:
18  %retval = alloca i32, align 4
19  %i = alloca i64, align 8
20  store i32 0, i32* %retval
21  store i64 0, i64* @y, align 8
22  store i64 0, i64* @x, align 8
23  call void @srand(i32 422304) #3
24  store i64 0, i64* %i, align 8
25  br label %for.cond
26
27for.cond:                                         ; preds = %for.inc, %entry
28  %0 = load i64, i64* %i, align 8
29  %cmp = icmp ult i64 %0, 13000000000
30  br i1 %cmp, label %for.body, label %for.end, !prof !1
31
32for.body:                                         ; preds = %for.cond
33  %call = call i32 @rand() #3
34  %conv = sitofp i32 %call to double
35  %mul = fmul double %conv, 1.000000e+02
36  %div = fdiv double %mul, 0x41E0000000000000
37  %cmp1 = fcmp ogt double %div, 9.000000e+01
38  br i1 %cmp1, label %if.then, label %if.else, !prof !2
39
40if.then:                                          ; preds = %for.body
41  %1 = load i64, i64* @x, align 8
42  %inc = add i64 %1, 1
43  store i64 %inc, i64* @x, align 8
44  br label %if.end
45
46if.else:                                          ; preds = %for.body
47  %2 = load i64, i64* @y, align 8
48  %inc3 = add i64 %2, 1
49  store i64 %inc3, i64* @y, align 8
50  br label %if.end
51
52if.end:                                           ; preds = %if.else, %if.then
53  br label %for.inc
54
55for.inc:                                          ; preds = %if.end
56  %3 = load i64, i64* %i, align 8
57  %inc4 = add i64 %3, 1
58  store i64 %inc4, i64* %i, align 8
59  br label %for.cond
60
61for.end:                                          ; preds = %for.cond
62  %4 = load i64, i64* @x, align 8
63  %5 = load i64, i64* @y, align 8
64  %call5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0), i64 %4, i64 %5)
65  ret i32 0
66}
67
68; Function Attrs: nounwind
69declare void @srand(i32) #1
70
71; Function Attrs: nounwind
72declare i32 @rand() #1
73
74declare i32 @printf(i8*, ...) #2
75
76attributes #0 = { inlinehint nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
77attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
78attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
79attributes #3 = { nounwind }
80
81!llvm.ident = !{!0}
82
83!0 = !{!"clang version 3.7.0 (trunk 236218) (llvm/trunk 236235)"}
84!1 = !{!"branch_weights", i32 -1044967295, i32 1}
85!2 = !{!"branch_weights", i32 433323762, i32 -394957723}
86