aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/Profiling/load-branch-weights-ifs.ll
blob: ddbaf96916cfa37c08a47a8064a54d21900b1193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
; RUN: opt -insert-edge-profiling -o %t1 < %s
; RUN: rm -f %t1.prof_data
; RUN: lli -load %llvmshlibdir/libprofile_rt%shlibext %t1 \
; RUN:     -llvmprof-output %t1.prof_data
; RUN: opt -profile-file %t1.prof_data -profile-metadata-loader -S -o - < %s \
; RUN:     | FileCheck %s
; RUN: rm -f %t1.prof_data

; FIXME: profile_rt.dll could be built on win32.
; REQUIRES: loadable_module

;; func_mod - Branch taken 6 times in 7.
define i32 @func_mod(i32 %N) nounwind uwtable {
entry:
  %retval = alloca i32, align 4
  %N.addr = alloca i32, align 4
  store i32 %N, i32* %N.addr, align 4
  %0 = load i32* %N.addr, align 4
  %rem = srem i32 %0, 7
  %tobool = icmp ne i32 %rem, 0
  br i1 %tobool, label %if.then, label %if.else
; CHECK: br i1 %tobool, label %if.then, label %if.else, !prof !0

if.then:
  store i32 1, i32* %retval
  br label %return

if.else:
  store i32 0, i32* %retval
  br label %return

return:
  %1 = load i32* %retval
  ret i32 %1
}

;; func_const_true - conditional branch which 100% taken probability.
define i32 @func_const_true(i32 %N) nounwind uwtable {
entry:
  %retval = alloca i32, align 4
  %N.addr = alloca i32, align 4
  store i32 %N, i32* %N.addr, align 4
  %0 = load i32* %N.addr, align 4
  %cmp = icmp eq i32 %0, 1
  br i1 %cmp, label %if.then, label %if.end
; CHECK: br i1 %cmp, label %if.then, label %if.end, !prof !1

if.then:
  store i32 1, i32* %retval
  br label %return

if.end:
  store i32 0, i32* %retval
  br label %return

return:
  %1 = load i32* %retval
  ret i32 %1
}

;; func_const_true - conditional branch which 100% not-taken probability.
define i32 @func_const_false(i32 %N) nounwind uwtable {
entry:
  %retval = alloca i32, align 4
  %N.addr = alloca i32, align 4
  store i32 %N, i32* %N.addr, align 4
  %0 = load i32* %N.addr, align 4
  %cmp = icmp eq i32 %0, 1
  br i1 %cmp, label %if.then, label %if.end
; CHECK: br i1 %cmp, label %if.then, label %if.end, !prof !2

if.then:
  store i32 1, i32* %retval
  br label %return

if.end:
  store i32 0, i32* %retval
  br label %return

return:
  %1 = load i32* %retval
  ret i32 %1
}

define i32 @main(i32 %argc, i8** %argv) nounwind uwtable {
entry:
  %retval = alloca i32, align 4
  %argc.addr = alloca i32, align 4
  %argv.addr = alloca i8**, align 8
  %loop = alloca i32, align 4
  store i32 0, i32* %retval
  store i32 0, i32* %loop, align 4
  br label %for.cond

for.cond:
  %0 = load i32* %loop, align 4
  %cmp = icmp slt i32 %0, 7000
  br i1 %cmp, label %for.body, label %for.end
; CHECK: br i1 %cmp, label %for.body, label %for.end, !prof !3

for.body:
  %1 = load i32* %loop, align 4
  %call = call i32 @func_mod(i32 %1)
  br label %for.inc

for.inc:
  %2 = load i32* %loop, align 4
  %inc = add nsw i32 %2, 1
  store i32 %inc, i32* %loop, align 4
  br label %for.cond

for.end:
  %call1 = call i32 @func_const_true(i32 1)
  %call2 = call i32 @func_const_false(i32 0)
  ret i32 0
}

; CHECK: !0 = metadata !{metadata !"branch_weights", i32 6000, i32 1000}
; CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 0}
; CHECK: !2 = metadata !{metadata !"branch_weights", i32 0, i32 1}
; CHECK: !3 = metadata !{metadata !"branch_weights", i32 7000, i32 1}
; CHECK-NOT: !4