xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/switch-edge-weight.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=x86-64 -print-machineinstrs=expand-isel-pseudos %s -o /dev/null 2>&1 | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Workerdeclare void @foo(i32)
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workerdefine void @test(i32 %x) nounwind {
8*9880d681SAndroid Build Coastguard Workerentry:
9*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %sw.default [
10*9880d681SAndroid Build Coastguard Worker    i32 1, label %sw.bb
11*9880d681SAndroid Build Coastguard Worker    i32 155, label %sw.bb
12*9880d681SAndroid Build Coastguard Worker    i32 156, label %sw.bb
13*9880d681SAndroid Build Coastguard Worker    i32 157, label %sw.bb
14*9880d681SAndroid Build Coastguard Worker    i32 158, label %sw.bb
15*9880d681SAndroid Build Coastguard Worker    i32 159, label %sw.bb
16*9880d681SAndroid Build Coastguard Worker    i32 1134, label %sw.bb
17*9880d681SAndroid Build Coastguard Worker    i32 1140, label %sw.bb
18*9880d681SAndroid Build Coastguard Worker  ], !prof !1
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Workersw.bb:
21*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 0)
22*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Workersw.default:
25*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 1)
26*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Workersw.epilog:
29*9880d681SAndroid Build Coastguard Worker  ret void
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker; Check if weights are correctly assigned to edges generated from switch
32*9880d681SAndroid Build Coastguard Worker; statement.
33*9880d681SAndroid Build Coastguard Worker;
34*9880d681SAndroid Build Coastguard Worker; CHECK: BB#0:
35*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#4: [0, 1133] (65 = 60 + 5)
36*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#5: [1134, UINT32_MAX] (25 = 20 + 5)
37*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#4({{[0-9a-fx/= ]+}}72.22%) BB#5({{[0-9a-fx/= ]+}}27.78%)
38*9880d681SAndroid Build Coastguard Worker;
39*9880d681SAndroid Build Coastguard Worker; CHECK: BB#4:
40*9880d681SAndroid Build Coastguard Worker; BB#4 to BB#1: [155, 159] (50)
41*9880d681SAndroid Build Coastguard Worker; BB#4 to BB#5: [0, 1133] - [155, 159] (15 = 10 + 5)
42*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#1({{[0-9a-fx/= ]+}}76.92%) BB#7({{[0-9a-fx/= ]+}}23.08%)
43*9880d681SAndroid Build Coastguard Worker;
44*9880d681SAndroid Build Coastguard Worker; CHECK: BB#5:
45*9880d681SAndroid Build Coastguard Worker; BB#5 to BB#1: {1140} (10)
46*9880d681SAndroid Build Coastguard Worker; BB#5 to BB#6: [1134, UINT32_MAX] - {1140} (15 = 10 + 5)
47*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#1({{[0-9a-fx/= ]+}}40.00%) BB#6({{[0-9a-fx/= ]+}}60.00%)
48*9880d681SAndroid Build Coastguard Worker;
49*9880d681SAndroid Build Coastguard Worker; CHECK: BB#6:
50*9880d681SAndroid Build Coastguard Worker; BB#6 to BB#1: {1134} (10)
51*9880d681SAndroid Build Coastguard Worker; BB#6 to BB#2: [1134, UINT32_MAX] - {1134, 1140} (5)
52*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#1({{[0-9a-fx/= ]+}}66.67%) BB#2({{[0-9a-fx/= ]+}}33.33%)
53*9880d681SAndroid Build Coastguard Worker}
54*9880d681SAndroid Build Coastguard Worker
55*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Workerdefine void @test2(i32 %x) nounwind {
58*9880d681SAndroid Build Coastguard Workerentry:
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Worker; In this switch statement, there is an edge from jump table to default
61*9880d681SAndroid Build Coastguard Worker; statement.
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %sw.default [
64*9880d681SAndroid Build Coastguard Worker    i32 1, label %sw.bb
65*9880d681SAndroid Build Coastguard Worker    i32 10, label %sw.bb2
66*9880d681SAndroid Build Coastguard Worker    i32 11, label %sw.bb3
67*9880d681SAndroid Build Coastguard Worker    i32 12, label %sw.bb4
68*9880d681SAndroid Build Coastguard Worker    i32 13, label %sw.bb5
69*9880d681SAndroid Build Coastguard Worker    i32 14, label %sw.bb5
70*9880d681SAndroid Build Coastguard Worker  ], !prof !3
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Workersw.bb:
73*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 0)
74*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Workersw.bb2:
77*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 2)
78*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Workersw.bb3:
81*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 3)
82*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
83*9880d681SAndroid Build Coastguard Worker
84*9880d681SAndroid Build Coastguard Workersw.bb4:
85*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 4)
86*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
87*9880d681SAndroid Build Coastguard Worker
88*9880d681SAndroid Build Coastguard Workersw.bb5:
89*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 5)
90*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
91*9880d681SAndroid Build Coastguard Worker
92*9880d681SAndroid Build Coastguard Workersw.default:
93*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 1)
94*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Workersw.epilog:
97*9880d681SAndroid Build Coastguard Worker  ret void
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Worker; Check if weights are correctly assigned to edges generated from switch
100*9880d681SAndroid Build Coastguard Worker; statement.
101*9880d681SAndroid Build Coastguard Worker;
102*9880d681SAndroid Build Coastguard Worker; CHECK: BB#0:
103*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#6: {0} + [15, UINT32_MAX] (5)
104*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#8: [1, 14] (jump table) (65 = 60 + 5)
105*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#6({{[0-9a-fx/= ]+}}7.14%) BB#8({{[0-9a-fx/= ]+}}92.86%
106*9880d681SAndroid Build Coastguard Worker;
107*9880d681SAndroid Build Coastguard Worker; CHECK: BB#8:
108*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#1: {1} (10)
109*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#6: [2, 9] (5)
110*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#2: {10} (10)
111*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#3: {11} (10)
112*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#4: {12} (10)
113*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#5: {13, 14} (20)
114*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#1({{[0-9a-fx/= ]+}}15.38%) BB#6({{[0-9a-fx/= ]+}}7.69%) BB#2({{[0-9a-fx/= ]+}}15.38%) BB#3({{[0-9a-fx/= ]+}}15.38%) BB#4({{[0-9a-fx/= ]+}}15.38%) BB#5({{[0-9a-fx/= ]+}}30.77%)
115*9880d681SAndroid Build Coastguard Worker}
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3
118*9880d681SAndroid Build Coastguard Worker
119*9880d681SAndroid Build Coastguard Workerdefine void @test3(i32 %x) nounwind {
120*9880d681SAndroid Build Coastguard Workerentry:
121*9880d681SAndroid Build Coastguard Worker
122*9880d681SAndroid Build Coastguard Worker; In this switch statement, there is no edge from jump table to default
123*9880d681SAndroid Build Coastguard Worker; statement.
124*9880d681SAndroid Build Coastguard Worker
125*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %sw.default [
126*9880d681SAndroid Build Coastguard Worker    i32 10, label %sw.bb
127*9880d681SAndroid Build Coastguard Worker    i32 11, label %sw.bb2
128*9880d681SAndroid Build Coastguard Worker    i32 12, label %sw.bb3
129*9880d681SAndroid Build Coastguard Worker    i32 13, label %sw.bb4
130*9880d681SAndroid Build Coastguard Worker    i32 14, label %sw.bb5
131*9880d681SAndroid Build Coastguard Worker  ], !prof !2
132*9880d681SAndroid Build Coastguard Worker
133*9880d681SAndroid Build Coastguard Workersw.bb:
134*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 0)
135*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
136*9880d681SAndroid Build Coastguard Worker
137*9880d681SAndroid Build Coastguard Workersw.bb2:
138*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 2)
139*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
140*9880d681SAndroid Build Coastguard Worker
141*9880d681SAndroid Build Coastguard Workersw.bb3:
142*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 3)
143*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
144*9880d681SAndroid Build Coastguard Worker
145*9880d681SAndroid Build Coastguard Workersw.bb4:
146*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 4)
147*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
148*9880d681SAndroid Build Coastguard Worker
149*9880d681SAndroid Build Coastguard Workersw.bb5:
150*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 5)
151*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
152*9880d681SAndroid Build Coastguard Worker
153*9880d681SAndroid Build Coastguard Workersw.default:
154*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 1)
155*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
156*9880d681SAndroid Build Coastguard Worker
157*9880d681SAndroid Build Coastguard Workersw.epilog:
158*9880d681SAndroid Build Coastguard Worker  ret void
159*9880d681SAndroid Build Coastguard Worker
160*9880d681SAndroid Build Coastguard Worker; Check if weights are correctly assigned to edges generated from switch
161*9880d681SAndroid Build Coastguard Worker; statement.
162*9880d681SAndroid Build Coastguard Worker;
163*9880d681SAndroid Build Coastguard Worker; CHECK: BB#0:
164*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#6: [0, 9] + [15, UINT32_MAX] {10}
165*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#8: [10, 14] (jump table) (50)
166*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#6({{[0-9a-fx/= ]+}}16.67%) BB#8({{[0-9a-fx/= ]+}}83.33%)
167*9880d681SAndroid Build Coastguard Worker;
168*9880d681SAndroid Build Coastguard Worker; CHECK: BB#8:
169*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#1: {10} (10)
170*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#2: {11} (10)
171*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#3: {12} (10)
172*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#4: {13} (10)
173*9880d681SAndroid Build Coastguard Worker; BB#8 to BB#5: {14} (10)
174*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#1({{[0-9a-fx/= ]+}}20.00%) BB#2({{[0-9a-fx/= ]+}}20.00%) BB#3({{[0-9a-fx/= ]+}}20.00%) BB#4({{[0-9a-fx/= ]+}}20.00%) BB#5({{[0-9a-fx/= ]+}}20.00%)
175*9880d681SAndroid Build Coastguard Worker}
176*9880d681SAndroid Build Coastguard Worker
177*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test4
178*9880d681SAndroid Build Coastguard Worker
179*9880d681SAndroid Build Coastguard Workerdefine void @test4(i32 %x) nounwind {
180*9880d681SAndroid Build Coastguard Workerentry:
181*9880d681SAndroid Build Coastguard Worker
182*9880d681SAndroid Build Coastguard Worker; In this switch statement, there is no edge from bit test to default basic
183*9880d681SAndroid Build Coastguard Worker; block.
184*9880d681SAndroid Build Coastguard Worker
185*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %sw.default [
186*9880d681SAndroid Build Coastguard Worker    i32 1, label %sw.bb
187*9880d681SAndroid Build Coastguard Worker    i32 111, label %sw.bb2
188*9880d681SAndroid Build Coastguard Worker    i32 112, label %sw.bb3
189*9880d681SAndroid Build Coastguard Worker    i32 113, label %sw.bb3
190*9880d681SAndroid Build Coastguard Worker    i32 114, label %sw.bb2
191*9880d681SAndroid Build Coastguard Worker    i32 115, label %sw.bb2
192*9880d681SAndroid Build Coastguard Worker  ], !prof !3
193*9880d681SAndroid Build Coastguard Worker
194*9880d681SAndroid Build Coastguard Workersw.bb:
195*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 0)
196*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
197*9880d681SAndroid Build Coastguard Worker
198*9880d681SAndroid Build Coastguard Workersw.bb2:
199*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 2)
200*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
201*9880d681SAndroid Build Coastguard Worker
202*9880d681SAndroid Build Coastguard Workersw.bb3:
203*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 3)
204*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
205*9880d681SAndroid Build Coastguard Worker
206*9880d681SAndroid Build Coastguard Workersw.default:
207*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 1)
208*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
209*9880d681SAndroid Build Coastguard Worker
210*9880d681SAndroid Build Coastguard Workersw.epilog:
211*9880d681SAndroid Build Coastguard Worker  ret void
212*9880d681SAndroid Build Coastguard Worker
213*9880d681SAndroid Build Coastguard Worker; Check if weights are correctly assigned to edges generated from switch
214*9880d681SAndroid Build Coastguard Worker; statement.
215*9880d681SAndroid Build Coastguard Worker;
216*9880d681SAndroid Build Coastguard Worker; CHECK: BB#0:
217*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#6: [0, 110] + [116, UINT32_MAX] (20)
218*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#7: [111, 115] (bit test) (50)
219*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#6({{[0-9a-fx/= ]+}}28.57%) BB#7({{[0-9a-fx/= ]+}}71.43%)
220*9880d681SAndroid Build Coastguard Worker;
221*9880d681SAndroid Build Coastguard Worker; CHECK: BB#7:
222*9880d681SAndroid Build Coastguard Worker; BB#7 to BB#2: {111, 114, 115} (30)
223*9880d681SAndroid Build Coastguard Worker; BB#7 to BB#3: {112, 113} (20)
224*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#2({{[0-9a-fx/= ]+}}60.00%) BB#3({{[0-9a-fx/= ]+}}40.00%)
225*9880d681SAndroid Build Coastguard Worker}
226*9880d681SAndroid Build Coastguard Worker
227*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test5
228*9880d681SAndroid Build Coastguard Worker
229*9880d681SAndroid Build Coastguard Workerdefine void @test5(i32 %x) nounwind {
230*9880d681SAndroid Build Coastguard Workerentry:
231*9880d681SAndroid Build Coastguard Worker
232*9880d681SAndroid Build Coastguard Worker; In this switch statement, there is an edge from jump table to default basic
233*9880d681SAndroid Build Coastguard Worker; block.
234*9880d681SAndroid Build Coastguard Worker
235*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %sw.default [
236*9880d681SAndroid Build Coastguard Worker    i32 4, label %sw.bb
237*9880d681SAndroid Build Coastguard Worker    i32 20, label %sw.bb2
238*9880d681SAndroid Build Coastguard Worker    i32 28, label %sw.bb3
239*9880d681SAndroid Build Coastguard Worker    i32 36, label %sw.bb4
240*9880d681SAndroid Build Coastguard Worker    i32 124, label %sw.bb5
241*9880d681SAndroid Build Coastguard Worker  ], !prof !2
242*9880d681SAndroid Build Coastguard Worker
243*9880d681SAndroid Build Coastguard Workersw.bb:
244*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 0)
245*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
246*9880d681SAndroid Build Coastguard Worker
247*9880d681SAndroid Build Coastguard Workersw.bb2:
248*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 1)
249*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
250*9880d681SAndroid Build Coastguard Worker
251*9880d681SAndroid Build Coastguard Workersw.bb3:
252*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 2)
253*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
254*9880d681SAndroid Build Coastguard Worker
255*9880d681SAndroid Build Coastguard Workersw.bb4:
256*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 3)
257*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
258*9880d681SAndroid Build Coastguard Worker
259*9880d681SAndroid Build Coastguard Workersw.bb5:
260*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 4)
261*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
262*9880d681SAndroid Build Coastguard Worker
263*9880d681SAndroid Build Coastguard Workersw.default:
264*9880d681SAndroid Build Coastguard Worker  call void @foo(i32 5)
265*9880d681SAndroid Build Coastguard Worker  br label %sw.epilog
266*9880d681SAndroid Build Coastguard Worker
267*9880d681SAndroid Build Coastguard Workersw.epilog:
268*9880d681SAndroid Build Coastguard Worker  ret void
269*9880d681SAndroid Build Coastguard Worker
270*9880d681SAndroid Build Coastguard Worker; Check if weights are correctly assigned to edges generated from switch
271*9880d681SAndroid Build Coastguard Worker; statement.
272*9880d681SAndroid Build Coastguard Worker;
273*9880d681SAndroid Build Coastguard Worker; CHECK: BB#0:
274*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#6: [10, UINT32_MAX] (15)
275*9880d681SAndroid Build Coastguard Worker; BB#0 to BB#8: [4, 20, 28, 36] (jump table) (45)
276*9880d681SAndroid Build Coastguard Worker; CHECK: Successors according to CFG: BB#8({{[0-9a-fx/= ]+}}25.00%) BB#9({{[0-9a-fx/= ]+}}75.00%)
277*9880d681SAndroid Build Coastguard Worker}
278*9880d681SAndroid Build Coastguard Worker
279*9880d681SAndroid Build Coastguard Worker!1 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10}
280*9880d681SAndroid Build Coastguard Worker!2 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10}
281*9880d681SAndroid Build Coastguard Worker!3 = !{!"branch_weights", i32 10, i32 10, i32 10, i32 10, i32 10, i32 10, i32 10}
282