1 ; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
3 ; In this test, the else clause is taken about 90% of the time. This was not
4 ; reflected in the probability computation because the weight is larger than
5 ; the branch weight cap (about 2 billion).
7 ; CHECK: edge %for.body -> %if.then probability is 0x0cccba45 / 0x80000000 = 10.00%
8 ; CHECK: edge %for.body -> %if.else probability is 0x733345bb / 0x80000000 = 90.00% [HOT edge]
10 @y = common global i64 0, align 8
11 @x = common global i64 0, align 8
12 @.str = private unnamed_addr constant [17 x i8] c"x = %lu\0Ay = %lu\0A\00", align 1
14 ; Function Attrs: inlinehint nounwind uwtable
15 define i32 @main() #0 {
17 %retval = alloca i32, align 4
18 %i = alloca i64, align 8
19 store i32 0, ptr %retval
20 store i64 0, ptr @y, align 8
21 store i64 0, ptr @x, align 8
22 call void @srand(i32 422304) #3
23 store i64 0, ptr %i, align 8
26 for.cond: ; preds = %for.inc, %entry
27 %0 = load i64, ptr %i, align 8
28 %cmp = icmp ult i64 %0, 13000000000
29 br i1 %cmp, label %for.body, label %for.end, !prof !1
31 for.body: ; preds = %for.cond
32 %call = call i32 @rand() #3
33 %conv = sitofp i32 %call to double
34 %mul = fmul double %conv, 1.000000e+02
35 %div = fdiv double %mul, 0x41E0000000000000
36 %cmp1 = fcmp ogt double %div, 9.000000e+01
37 br i1 %cmp1, label %if.then, label %if.else, !prof !2
39 if.then: ; preds = %for.body
40 %1 = load i64, ptr @x, align 8
42 store i64 %inc, ptr @x, align 8
45 if.else: ; preds = %for.body
46 %2 = load i64, ptr @y, align 8
48 store i64 %inc3, ptr @y, align 8
51 if.end: ; preds = %if.else, %if.then
54 for.inc: ; preds = %if.end
55 %3 = load i64, ptr %i, align 8
57 store i64 %inc4, ptr %i, align 8
60 for.end: ; preds = %for.cond
61 %4 = load i64, ptr @x, align 8
62 %5 = load i64, ptr @y, align 8
63 %call5 = call i32 (ptr, ...) @printf(ptr @.str, i64 %4, i64 %5)
67 ; Function Attrs: nounwind
68 declare void @srand(i32) #1
70 ; Function Attrs: nounwind
71 declare i32 @rand() #1
73 declare i32 @printf(ptr, ...) #2
75 attributes #0 = { inlinehint nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "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" }
76 attributes #1 = { nounwind "less-precise-fpmad"="false" "frame-pointer"="all" "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" }
77 attributes #2 = { "less-precise-fpmad"="false" "frame-pointer"="all" "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" }
78 attributes #3 = { nounwind }
82 !0 = !{!"clang version 3.7.0 (trunk 236218) (llvm/trunk 236235)"}
83 !1 = !{!"branch_weights", i32 -1044967295, i32 1}
84 !2 = !{!"branch_weights", i32 433323762, i32 -394957723}