ctrloops-hot-exit.ll
5.03 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 < %s | FileCheck %s
; If there is an exit edge known to be frequently taken,
; we should not transform this loop.
; A loop having a hot exit edge (exit in false branch)
define signext i64 @func() {
; CHECK: @func
; CHECK-NOT: mtctr
; CHECK-NOT: bdnz
entry:
%a = alloca [1000 x i32], align 4
%0 = bitcast [1000 x i32]* %a to i8*
br label %for.body
for.body:
%i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
%b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
%arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
%1 = load i32, i32* %arrayidx, align 4
%tobool = icmp eq i32 %1, 0
br i1 %tobool, label %if.end, label %cleanup, !prof !1
if.end:
%xor = xor i64 %i.013, %b.012
%inc = add nuw nsw i64 %i.013, 1
%cmp = icmp ult i64 %inc, 1000
br i1 %cmp, label %for.body, label %cleanup
cleanup:
%res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
ret i64 %res
}
; A loop having a cold exit edge (exit in false branch)
define signext i64 @func2() {
; CHECK: @func2
; CHECK: mtctr
; CHECK: bdnz
entry:
%a = alloca [1000 x i32], align 4
%0 = bitcast [1000 x i32]* %a to i8*
br label %for.body
for.body:
%i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
%b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
%arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
%1 = load i32, i32* %arrayidx, align 4
%tobool = icmp eq i32 %1, 0
br i1 %tobool, label %if.end, label %cleanup, !prof !2
if.end:
%xor = xor i64 %i.013, %b.012
%inc = add nuw nsw i64 %i.013, 1
%cmp = icmp ult i64 %inc, 1000
br i1 %cmp, label %for.body, label %cleanup
cleanup:
%res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
ret i64 %res
}
; A loop having an exit edge without profile data (exit in false branch)
define signext i64 @func3() {
; CHECK: @func3
; CHECK: mtctr
; CHECK: bdnz
entry:
%a = alloca [1000 x i32], align 4
%0 = bitcast [1000 x i32]* %a to i8*
br label %for.body
for.body:
%i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
%b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
%arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
%1 = load i32, i32* %arrayidx, align 4
%tobool = icmp eq i32 %1, 0
br i1 %tobool, label %if.end, label %cleanup
if.end:
%xor = xor i64 %i.013, %b.012
%inc = add nuw nsw i64 %i.013, 1
%cmp = icmp ult i64 %inc, 1000
br i1 %cmp, label %for.body, label %cleanup
cleanup:
%res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
ret i64 %res
}
; A loop having a hot exit edge (exit in true branch)
define signext i64 @func4() {
; CHECK: @func4
; CHECK-NOT: mtctr
; CHECK-NOT: bdnz
entry:
%a = alloca [1000 x i32], align 4
%0 = bitcast [1000 x i32]* %a to i8*
br label %for.body
for.body:
%i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
%b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
%arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
%1 = load i32, i32* %arrayidx, align 4
%tobool = icmp ne i32 %1, 0
br i1 %tobool, label %cleanup, label %if.end, !prof !2
if.end:
%xor = xor i64 %i.013, %b.012
%inc = add nuw nsw i64 %i.013, 1
%cmp = icmp ult i64 %inc, 1000
br i1 %cmp, label %for.body, label %cleanup
cleanup:
%res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
ret i64 %res
}
; A loop having a cold exit edge (exit in true branch)
define signext i64 @func5() {
; CHECK: @func5
; CHECK: mtctr
; CHECK: bdnz
entry:
%a = alloca [1000 x i32], align 4
%0 = bitcast [1000 x i32]* %a to i8*
br label %for.body
for.body:
%i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
%b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
%arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
%1 = load i32, i32* %arrayidx, align 4
%tobool = icmp ne i32 %1, 0
br i1 %tobool, label %cleanup, label %if.end, !prof !1
if.end:
%xor = xor i64 %i.013, %b.012
%inc = add nuw nsw i64 %i.013, 1
%cmp = icmp ult i64 %inc, 1000
br i1 %cmp, label %for.body, label %cleanup
cleanup:
%res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
ret i64 %res
}
; A loop having an exit edge without profile data (exit in true branch)
define signext i64 @func6() {
; CHECK: @func6
; CHECK: mtctr
; CHECK: bdnz
entry:
%a = alloca [1000 x i32], align 4
%0 = bitcast [1000 x i32]* %a to i8*
br label %for.body
for.body:
%i.013 = phi i64 [ 0, %entry ], [ %inc, %if.end ]
%b.012 = phi i64 [ 0, %entry ], [ %xor, %if.end ]
%arrayidx = getelementptr inbounds [1000 x i32], [1000 x i32]* %a, i64 0, i64 %i.013
%1 = load i32, i32* %arrayidx, align 4
%tobool = icmp ne i32 %1, 0
br i1 %tobool, label %cleanup, label %if.end
if.end:
%xor = xor i64 %i.013, %b.012
%inc = add nuw nsw i64 %i.013, 1
%cmp = icmp ult i64 %inc, 1000
br i1 %cmp, label %for.body, label %cleanup
cleanup:
%res = phi i64 [ %b.012, %for.body ], [ %xor, %if.end ]
ret i64 %res
}
!1 = !{!"branch_weights", i32 1, i32 2000}
!2 = !{!"branch_weights", i32 2000, i32 1}