switch-edge-weight.ll
6.11 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
; RUN: llc -mtriple=x86_64-- -print-after=finalize-isel %s -o /dev/null 2>&1 | FileCheck %s
declare void @foo(i32)
; CHECK-LABEL: test
define void @test(i32 %x) nounwind {
entry:
switch i32 %x, label %sw.default [
i32 1, label %sw.bb
i32 155, label %sw.bb
i32 156, label %sw.bb
i32 157, label %sw.bb
i32 158, label %sw.bb
i32 159, label %sw.bb
i32 1134, label %sw.bb
i32 1140, label %sw.bb
], !prof !1
sw.bb:
call void @foo(i32 0)
br label %sw.epilog
sw.default:
call void @foo(i32 1)
br label %sw.epilog
sw.epilog:
ret void
; Check if weights are correctly assigned to edges generated from switch
; statement.
;
; CHECK: bb.0{{[0-9a-zA-Z.]*}}:
; %bb.0 to %bb.4: [0, 1133] (65 = 60 + 5)
; %bb.0 to %bb.5: [1134, UINT32_MAX] (25 = 20 + 5)
; CHECK: successors: %bb.4(0x5c71c71c), %bb.5(0x238e38e4)
;
; CHECK: bb.4{{[0-9a-zA-Z.]*}}:
; %bb.4 to %bb.1: [155, 159] (50)
; %bb.4 to %bb.5: [0, 1133] - [155, 159] (15 = 10 + 5)
; CHECK: successors: %bb.1(0x62762762), %bb.7(0x1d89d89e)
;
; CHECK: bb.5{{[0-9a-zA-Z.]*}}:
; %bb.5 to %bb.1: {1140} (10)
; %bb.5 to %bb.6: [1134, UINT32_MAX] - {1140} (15 = 10 + 5)
; CHECK: successors: %bb.1(0x33333333), %bb.6(0x4ccccccd)
;
; CHECK: bb.6{{[0-9a-zA-Z.]*}}:
; %bb.6 to %bb.1: {1134} (10)
; %bb.6 to %bb.2: [1134, UINT32_MAX] - {1134, 1140} (5)
; CHECK: successors: %bb.1(0x55555555), %bb.2(0x2aaaaaab)
}
; CHECK-LABEL: test2
define void @test2(i32 %x) nounwind {
entry:
; In this switch statement, there is an edge from jump table to default
; statement.
switch i32 %x, label %sw.default [
i32 1, label %sw.bb
i32 10, label %sw.bb2
i32 11, label %sw.bb3
i32 12, label %sw.bb4
i32 13, label %sw.bb5
i32 14, label %sw.bb5
], !prof !3
sw.bb:
call void @foo(i32 0)
br label %sw.epilog
sw.bb2:
call void @foo(i32 2)
br label %sw.epilog
sw.bb3:
call void @foo(i32 3)
br label %sw.epilog
sw.bb4:
call void @foo(i32 4)
br label %sw.epilog
sw.bb5:
call void @foo(i32 5)
br label %sw.epilog
sw.default:
call void @foo(i32 1)
br label %sw.epilog
sw.epilog:
ret void
; Check if weights are correctly assigned to edges generated from switch
; statement.
;
; CHECK: bb.0{{[0-9a-zA-Z.]*}}:
; %bb.0 to %bb.6: {0} + [15, UINT32_MAX] (5)
; %bb.0 to %bb.8: [1, 14] (jump table) (65 = 60 + 5)
; CHECK: successors: %bb.6(0x09249249), %bb.8(0x76db6db7)
;
; CHECK: bb.8{{[0-9a-zA-Z.]*}}:
; %bb.8 to %bb.1: {1} (10)
; %bb.8 to %bb.6: [2, 9] (5)
; %bb.8 to %bb.2: {10} (10)
; %bb.8 to %bb.3: {11} (10)
; %bb.8 to %bb.4: {12} (10)
; %bb.8 to %bb.5: {13, 14} (20)
; CHECK: successors: %bb.1(0x13b13b14), %bb.6(0x09d89d8a), %bb.2(0x13b13b14), %bb.3(0x13b13b14), %bb.4(0x13b13b14), %bb.5(0x27627628)
}
; CHECK-LABEL: test3
define void @test3(i32 %x) nounwind {
entry:
; In this switch statement, there is no edge from jump table to default
; statement.
switch i32 %x, label %sw.default [
i32 10, label %sw.bb
i32 11, label %sw.bb2
i32 12, label %sw.bb3
i32 13, label %sw.bb4
i32 14, label %sw.bb5
], !prof !2
sw.bb:
call void @foo(i32 0)
br label %sw.epilog
sw.bb2:
call void @foo(i32 2)
br label %sw.epilog
sw.bb3:
call void @foo(i32 3)
br label %sw.epilog
sw.bb4:
call void @foo(i32 4)
br label %sw.epilog
sw.bb5:
call void @foo(i32 5)
br label %sw.epilog
sw.default:
call void @foo(i32 1)
br label %sw.epilog
sw.epilog:
ret void
; Check if weights are correctly assigned to edges generated from switch
; statement.
;
; CHECK: bb.0{{[0-9a-zA-Z.]*}}:
; %bb.0 to %bb.6: [0, 9] + [15, UINT32_MAX] {10}
; %bb.0 to %bb.8: [10, 14] (jump table) (50)
; CHECK: successors: %bb.6(0x15555555), %bb.8(0x6aaaaaab)
;
; CHECK: bb.8{{[0-9a-zA-Z.]*}}:
; %bb.8 to %bb.1: {10} (10)
; %bb.8 to %bb.2: {11} (10)
; %bb.8 to %bb.3: {12} (10)
; %bb.8 to %bb.4: {13} (10)
; %bb.8 to %bb.5: {14} (10)
; CHECK: successors: %bb.1(0x1999999a), %bb.2(0x1999999a), %bb.3(0x1999999a), %bb.4(0x1999999a), %bb.5(0x1999999a)
}
; CHECK-LABEL: test4
define void @test4(i32 %x) nounwind {
entry:
; In this switch statement, there is no edge from bit test to default basic
; block.
switch i32 %x, label %sw.default [
i32 1, label %sw.bb
i32 111, label %sw.bb2
i32 112, label %sw.bb3
i32 113, label %sw.bb3
i32 114, label %sw.bb2
i32 115, label %sw.bb2
], !prof !3
sw.bb:
call void @foo(i32 0)
br label %sw.epilog
sw.bb2:
call void @foo(i32 2)
br label %sw.epilog
sw.bb3:
call void @foo(i32 3)
br label %sw.epilog
sw.default:
call void @foo(i32 1)
br label %sw.epilog
sw.epilog:
ret void
; Check if weights are correctly assigned to edges generated from switch
; statement.
;
; CHECK: bb.0{{[0-9a-zA-Z.]*}}:
; %bb.0 to %bb.6: [0, 110] + [116, UINT32_MAX] (20)
; %bb.0 to %bb.7: [111, 115] (bit test) (50)
; CHECK: successors: %bb.6(0x24924925), %bb.7(0x5b6db6db)
;
; CHECK: bb.7{{[0-9a-zA-Z.]*}}:
; %bb.7 to %bb.2: {111, 114, 115} (30)
; %bb.7 to %bb.3: {112, 113} (20)
; CHECK: successors: %bb.2(0x4ccccccd), %bb.3(0x33333333)
}
; CHECK-LABEL: test5
define void @test5(i32 %x) nounwind {
entry:
; In this switch statement, there is an edge from jump table to default basic
; block.
switch i32 %x, label %sw.default [
i32 4, label %sw.bb
i32 20, label %sw.bb2
i32 28, label %sw.bb3
i32 36, label %sw.bb4
i32 124, label %sw.bb5
], !prof !2
sw.bb:
call void @foo(i32 0)
br label %sw.epilog
sw.bb2:
call void @foo(i32 1)
br label %sw.epilog
sw.bb3:
call void @foo(i32 2)
br label %sw.epilog
sw.bb4:
call void @foo(i32 3)
br label %sw.epilog
sw.bb5:
call void @foo(i32 4)
br label %sw.epilog
sw.default:
call void @foo(i32 5)
br label %sw.epilog
sw.epilog:
ret void
; Check if weights are correctly assigned to edges generated from switch
; statement.
;
; CHECK: bb.0{{[0-9a-zA-Z.]*}}:
; %bb.0 to %bb.6: [10, UINT32_MAX] (15)
; %bb.0 to %bb.8: [4, 20, 28, 36] (jump table) (45)
; CHECK: successors: %bb.8(0x20000001), %bb.9(0x5fffffff)
}
!1 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10}
!2 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10}
!3 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10}