1; RUN: llc %s -O2 -print-machineinstrs -mtriple=aarch64-linux-gnu -jump-table-density=40                         -o /dev/null 2> %t; FileCheck %s --check-prefixes=CHECK,CHECK0  < %t
2; RUN: llc %s -O2 -print-machineinstrs -mtriple=aarch64-linux-gnu -jump-table-density=40 -max-jump-table-size=4  -o /dev/null 2> %t; FileCheck %s --check-prefixes=CHECK,CHECK4  < %t
3; RUN: llc %s -O2 -print-machineinstrs -mtriple=aarch64-linux-gnu -jump-table-density=40 -max-jump-table-size=8  -o /dev/null 2> %t; FileCheck %s --check-prefixes=CHECK,CHECK8  < %t
4; RUN: llc %s -O2 -print-machineinstrs -mtriple=aarch64-linux-gnu -jump-table-density=40 -max-jump-table-size=16 -o /dev/null 2> %t; FileCheck %s --check-prefixes=CHECK,CHECK16 < %t
5; RUN: llc %s -O2 -print-machineinstrs -mtriple=aarch64-linux-gnu -jump-table-density=40 -mcpu=exynos-m3         -o /dev/null 2> %t; FileCheck %s --check-prefixes=CHECK,CHECKM3 < %t
6
7declare void @ext(i32, i32)
8
9define i32 @jt1(i32 %a, i32 %b) {
10entry:
11  switch i32 %a, label %return [
12    i32 1,  label %bb1
13    i32 2,  label %bb2
14    i32 3,  label %bb3
15    i32 4,  label %bb4
16    i32 5,  label %bb5
17    i32 6,  label %bb6
18    i32 7,  label %bb7
19    i32 8,  label %bb8
20    i32 9,  label %bb9
21    i32 10, label %bb10
22    i32 11, label %bb11
23    i32 12, label %bb12
24    i32 13, label %bb13
25    i32 14, label %bb14
26    i32 15, label %bb15
27    i32 16, label %bb16
28    i32 17, label %bb17
29  ]
30; CHECK-LABEL: function jt1:
31; CHECK-NEXT: Jump Tables:
32; CHECK0-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
33; CHECK0-NOT:   %jump-table.1:
34; CHECK4-NEXT:  %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5
35; CHECK4-NEXT:  %jump-table.1: %bb.6 %bb.7 %bb.8 %bb.9
36; CHECK4-NEXT:  %jump-table.2: %bb.10 %bb.11 %bb.12 %bb.13
37; CHECK4-NEXT:  %jump-table.3: %bb.14 %bb.15 %bb.16 %bb.17
38; CHECK4-NOT:   %jump-table.4:
39; CHECK8-NEXT:  %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9
40; CHECK8-NEXT:  %jump-table.1: %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
41; CHECK8-NOT:   %jump-table.2:
42; CHECK16-NEXT: %jump-table.0: %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
43; CHECK16-NOT:  %jump-table.1:
44; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
45; CHECKM3-NOT:  %jump-table.1:
46
47bb1:  tail call void @ext(i32 1, i32 0)  br label %return
48bb2:  tail call void @ext(i32 2, i32 2)  br label %return
49bb3:  tail call void @ext(i32 3, i32 4)  br label %return
50bb4:  tail call void @ext(i32 4, i32 6)  br label %return
51bb5:  tail call void @ext(i32 5, i32 8)  br label %return
52bb6:  tail call void @ext(i32 6, i32 10) br label %return
53bb7:  tail call void @ext(i32 7, i32 12) br label %return
54bb8:  tail call void @ext(i32 8, i32 14) br label %return
55bb9:  tail call void @ext(i32 9, i32 16) br label %return
56bb10: tail call void @ext(i32 1, i32 18) br label %return
57bb11: tail call void @ext(i32 2, i32 20) br label %return
58bb12: tail call void @ext(i32 3, i32 22) br label %return
59bb13: tail call void @ext(i32 4, i32 24) br label %return
60bb14: tail call void @ext(i32 5, i32 26) br label %return
61bb15: tail call void @ext(i32 6, i32 28) br label %return
62bb16: tail call void @ext(i32 7, i32 30) br label %return
63bb17: tail call void @ext(i32 8, i32 32) br label %return
64
65return: ret i32 %b
66}
67
68define void @jt2(i32 %x) {
69entry:
70  switch i32 %x, label %return [
71    i32 1,  label %bb1
72    i32 2,  label %bb2
73    i32 3,  label %bb3
74    i32 4,  label %bb4
75
76    i32 14, label %bb5
77    i32 15, label %bb6
78  ]
79; CHECK-LABEL: function jt2:
80; CHECK-NEXT: Jump Tables:
81; CHECK0-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
82; CHECK0-NOT:   %jump-table.1:
83; CHECK4-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
84; CHECK4-NOT:   %jump-table.1:
85; CHECK8-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4{{$}}
86; CHECK8-NOT:   %jump-table.1:
87; CHECK16-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
88; CHECK16-NOT:  %jump-table.1:
89; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.7 %bb.5 %bb.6{{$}}
90; CHECKM3-NOT:  %jump-table.1:
91; CHECK-DAG: End machine code for function jt2.
92
93bb1: tail call void @ext(i32 6, i32 1) br label %return
94bb2: tail call void @ext(i32 5, i32 2) br label %return
95bb3: tail call void @ext(i32 4, i32 3) br label %return
96bb4: tail call void @ext(i32 3, i32 4) br label %return
97bb5: tail call void @ext(i32 2, i32 5) br label %return
98bb6: tail call void @ext(i32 1, i32 6) br label %return
99return: ret void
100}
101
102define void @jt3(i32 %x) {
103entry:
104  switch i32 %x, label %return [
105    i32 1,  label %bb1
106    i32 2,  label %bb2
107    i32 3,  label %bb3
108    i32 4,  label %bb4
109
110    i32 14, label %bb5
111    i32 15, label %bb6
112    i32 16, label %bb7
113    i32 17, label %bb8
114
115    i32 19, label %bb9
116    i32 20, label %bb10
117
118    i32 22, label %bb11
119    i32 23, label %bb12
120  ]
121; CHECK-LABEL: function jt3:
122; CHECK-NEXT: Jump Tables:
123; CHECK0-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.5 %bb.6 %bb.7 %bb.8 %bb.13 %bb.9 %bb.10 %bb.13 %bb.11 %bb.12
124; CHECK0-NOT:   %jump-table.1:
125; CHECK4-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4
126; CHECK4-NEXT:  %jump-table.1: %bb.5 %bb.6 %bb.7 %bb.8
127; CHECK4-NOT:   %jump-table.2:
128; CHECK8-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4
129; CHECK8-NEXT:  %jump-table.1: %bb.5 %bb.6 %bb.7 %bb.8 %bb.13 %bb.9 %bb.10
130; CHECK8-NOT:   %jump-table.2:
131; CHECK16-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.5 %bb.6 %bb.7
132; CHECK16-NEXT: %jump-table.1: %bb.8 %bb.13 %bb.9 %bb.10 %bb.13 %bb.11 %bb.12
133; CHECK16-NOT:  %jump-table.2:
134; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.5 %bb.6 %bb.7 %bb.8 %bb.13 %bb.9 %bb.10
135; CHECKM3-NOT:  %jump-table.1:
136; CHECK-DAG: End machine code for function jt3.
137
138bb1:  tail call void @ext(i32 1,  i32 12) br label %return
139bb2:  tail call void @ext(i32 2,  i32 11) br label %return
140bb3:  tail call void @ext(i32 3,  i32 10) br label %return
141bb4:  tail call void @ext(i32 4,  i32 9)  br label %return
142bb5:  tail call void @ext(i32 5,  i32 8)  br label %return
143bb6:  tail call void @ext(i32 6,  i32 7)  br label %return
144bb7:  tail call void @ext(i32 7,  i32 6)  br label %return
145bb8:  tail call void @ext(i32 8,  i32 5)  br label %return
146bb9:  tail call void @ext(i32 9,  i32 4)  br label %return
147bb10: tail call void @ext(i32 10, i32 3)  br label %return
148bb11: tail call void @ext(i32 11, i32 2)  br label %return
149bb12: tail call void @ext(i32 12, i32 1)  br label %return
150
151return: ret void
152}
153
154define void @jt4(i32 %x) {
155entry:
156  switch i32 %x, label %default [
157    i32 1,  label %bb1
158    i32 2,  label %bb2
159    i32 3,  label %bb3
160    i32 4,  label %bb4
161
162    i32 14, label %bb5
163    i32 15, label %bb6
164    i32 16, label %bb7
165    i32 17, label %bb8
166
167    i32 19, label %bb9
168    i32 20, label %bb10
169
170    i32 22, label %bb11
171    i32 23, label %bb12
172  ]
173; CHECK-LABEL: function jt4:
174; CHECK-NEXT: Jump Tables:
175; CHECK0-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.5 %bb.6 %bb.7 %bb.8 %bb.13 %bb.9 %bb.10 %bb.13 %bb.11 %bb.12
176; CHECK0-NOT:   %jump-table.1:
177; CHECK4-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4
178; CHECK4-NEXT:  %jump-table.1: %bb.5 %bb.6 %bb.7 %bb.8
179; CHECK4-NOT:   %jump-table.2:
180; CHECK8-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4
181; CHECK8-NEXT:  %jump-table.1: %bb.5 %bb.6 %bb.7 %bb.8 %bb.13 %bb.9 %bb.10
182; CHECK8-NOT:   %jump-table.2:
183; CHECK16-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.5 %bb.6 %bb.7
184; CHECK16-NEXT: %jump-table.1: %bb.8 %bb.13 %bb.9 %bb.10 %bb.13 %bb.11 %bb.12
185; CHECK16-NOT:  %jump-table.2:
186; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.13 %bb.5 %bb.6 %bb.7 %bb.8 %bb.13 %bb.9 %bb.10
187; CHECKM3-NOT:  %jump-table.1:
188; CHECK-DAG: End machine code for function jt4.
189
190bb1:  tail call void @ext(i32 1,  i32 12) br label %return
191bb2:  tail call void @ext(i32 2,  i32 11) br label %return
192bb3:  tail call void @ext(i32 3,  i32 10) br label %return
193bb4:  tail call void @ext(i32 4,  i32 9)  br label %return
194bb5:  tail call void @ext(i32 5,  i32 8)  br label %return
195bb6:  tail call void @ext(i32 6,  i32 7)  br label %return
196bb7:  tail call void @ext(i32 7,  i32 6)  br label %return
197bb8:  tail call void @ext(i32 8,  i32 5)  br label %return
198bb9:  tail call void @ext(i32 9,  i32 4)  br label %return
199bb10: tail call void @ext(i32 10, i32 3)  br label %return
200bb11: tail call void @ext(i32 11, i32 2)  br label %return
201bb12: tail call void @ext(i32 12, i32 1)  br label %return
202default: unreachable
203
204return: ret void
205}
206
207define i32 @jt1_optsize(i32 %a, i32 %b) optsize {
208entry:
209  switch i32 %a, label %return [
210    i32 1,  label %bb1
211    i32 2,  label %bb2
212    i32 3,  label %bb3
213    i32 4,  label %bb4
214    i32 5,  label %bb5
215    i32 6,  label %bb6
216    i32 7,  label %bb7
217    i32 8,  label %bb8
218    i32 9,  label %bb9
219    i32 10, label %bb10
220    i32 11, label %bb11
221    i32 12, label %bb12
222    i32 13, label %bb13
223    i32 14, label %bb14
224    i32 15, label %bb15
225    i32 16, label %bb16
226    i32 17, label %bb17
227  ]
228; CHECK-LABEL: function jt1_optsize:
229; CHECK-NEXT: Jump Tables:
230; CHECK0-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
231; CHECK0-NOT:   %jump-table.1:
232; CHECK4-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
233; CHECK4-NOT:   %jump-table.1:
234; CHECK8-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
235; CHECK8-NOT:   %jump-table.1:
236; CHECK16-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
237; CHECK16-NOT:  %jump-table.1:
238; CHECKM1-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
239; CHECKM1-NOT:  %jump-table.1:
240; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
241; CHECKM3-NOT:  %jump-table.1:
242; CHECK-DAG: End machine code for function jt1_optsize.
243
244bb1:  tail call void @ext(i32 1, i32 0)  br label %return
245bb2:  tail call void @ext(i32 2, i32 2)  br label %return
246bb3:  tail call void @ext(i32 3, i32 4)  br label %return
247bb4:  tail call void @ext(i32 4, i32 6)  br label %return
248bb5:  tail call void @ext(i32 5, i32 8)  br label %return
249bb6:  tail call void @ext(i32 6, i32 10) br label %return
250bb7:  tail call void @ext(i32 7, i32 12) br label %return
251bb8:  tail call void @ext(i32 8, i32 14) br label %return
252bb9:  tail call void @ext(i32 9, i32 16) br label %return
253bb10: tail call void @ext(i32 1, i32 18) br label %return
254bb11: tail call void @ext(i32 2, i32 20) br label %return
255bb12: tail call void @ext(i32 3, i32 22) br label %return
256bb13: tail call void @ext(i32 4, i32 24) br label %return
257bb14: tail call void @ext(i32 5, i32 26) br label %return
258bb15: tail call void @ext(i32 6, i32 28) br label %return
259bb16: tail call void @ext(i32 7, i32 30) br label %return
260bb17: tail call void @ext(i32 8, i32 32) br label %return
261
262return: ret i32 %b
263}
264
265define i32 @jt1_pgso(i32 %a, i32 %b) !prof !14 {
266entry:
267  switch i32 %a, label %return [
268    i32 1,  label %bb1
269    i32 2,  label %bb2
270    i32 3,  label %bb3
271    i32 4,  label %bb4
272    i32 5,  label %bb5
273    i32 6,  label %bb6
274    i32 7,  label %bb7
275    i32 8,  label %bb8
276    i32 9,  label %bb9
277    i32 10, label %bb10
278    i32 11, label %bb11
279    i32 12, label %bb12
280    i32 13, label %bb13
281    i32 14, label %bb14
282    i32 15, label %bb15
283    i32 16, label %bb16
284    i32 17, label %bb17
285  ]
286; CHECK-LABEL: function jt1_pgso:
287; CHECK-NEXT: Jump Tables:
288; CHECK0-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
289; CHECK0-NOT:   %jump-table.1:
290; CHECK4-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
291; CHECK4-NOT:   %jump-table.1:
292; CHECK8-NEXT:  %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
293; CHECK8-NOT:   %jump-table.1:
294; CHECK16-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
295; CHECK16-NOT:  %jump-table.1:
296; CHECKM1-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
297; CHECKM1-NOT:  %jump-table.1:
298; CHECKM3-NEXT: %jump-table.0: %bb.1 %bb.2 %bb.3 %bb.4 %bb.5 %bb.6 %bb.7 %bb.8 %bb.9 %bb.10 %bb.11 %bb.12 %bb.13 %bb.14 %bb.15 %bb.16 %bb.17
299; CHECKM3-NOT:  %jump-table.1:
300; CHECK-DAG: End machine code for function jt1_pgso.
301
302bb1:  tail call void @ext(i32 1, i32 0)  br label %return
303bb2:  tail call void @ext(i32 2, i32 2)  br label %return
304bb3:  tail call void @ext(i32 3, i32 4)  br label %return
305bb4:  tail call void @ext(i32 4, i32 6)  br label %return
306bb5:  tail call void @ext(i32 5, i32 8)  br label %return
307bb6:  tail call void @ext(i32 6, i32 10) br label %return
308bb7:  tail call void @ext(i32 7, i32 12) br label %return
309bb8:  tail call void @ext(i32 8, i32 14) br label %return
310bb9:  tail call void @ext(i32 9, i32 16) br label %return
311bb10: tail call void @ext(i32 1, i32 18) br label %return
312bb11: tail call void @ext(i32 2, i32 20) br label %return
313bb12: tail call void @ext(i32 3, i32 22) br label %return
314bb13: tail call void @ext(i32 4, i32 24) br label %return
315bb14: tail call void @ext(i32 5, i32 26) br label %return
316bb15: tail call void @ext(i32 6, i32 28) br label %return
317bb16: tail call void @ext(i32 7, i32 30) br label %return
318bb17: tail call void @ext(i32 8, i32 32) br label %return
319
320return: ret i32 %b
321}
322
323!llvm.module.flags = !{!0}
324!0 = !{i32 1, !"ProfileSummary", !1}
325!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
326!2 = !{!"ProfileFormat", !"InstrProf"}
327!3 = !{!"TotalCount", i64 10000}
328!4 = !{!"MaxCount", i64 10}
329!5 = !{!"MaxInternalCount", i64 1}
330!6 = !{!"MaxFunctionCount", i64 1000}
331!7 = !{!"NumCounts", i64 3}
332!8 = !{!"NumFunctions", i64 3}
333!9 = !{!"DetailedSummary", !10}
334!10 = !{!11, !12, !13}
335!11 = !{i32 10000, i64 100, i32 1}
336!12 = !{i32 999000, i64 100, i32 1}
337!13 = !{i32 999999, i64 1, i32 2}
338!14 = !{!"function_entry_count", i64 0}
339