xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/switch-density.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=x86_64-linux-gnu %s -o - -jump-table-density=25 | FileCheck %s --check-prefix=DENSE --check-prefix=CHECK
2*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=x86_64-linux-gnu %s -o - -jump-table-density=10 | FileCheck %s --check-prefix=SPARSE --check-prefix=CHECK
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workerdeclare void @g(i32)
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerdefine void @sparse(i32 %x) {
7*9880d681SAndroid Build Coastguard Workerentry:
8*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %return [
9*9880d681SAndroid Build Coastguard Worker    i32 300, label %bb0
10*9880d681SAndroid Build Coastguard Worker    i32 100, label %bb1
11*9880d681SAndroid Build Coastguard Worker    i32 400, label %bb1
12*9880d681SAndroid Build Coastguard Worker    i32 500, label %bb2
13*9880d681SAndroid Build Coastguard Worker  ]
14*9880d681SAndroid Build Coastguard Workerbb0: tail call void @g(i32 0) br label %return
15*9880d681SAndroid Build Coastguard Workerbb1: tail call void @g(i32 1) br label %return
16*9880d681SAndroid Build Coastguard Workerbb2: tail call void @g(i32 1) br label %return
17*9880d681SAndroid Build Coastguard Workerreturn: ret void
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker; Should pivot around 400 for two subtrees with two jump tables each.
20*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: sparse
21*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: cmpl
22*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $399
23*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $100
24*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $300
25*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $400
26*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $500
27*9880d681SAndroid Build Coastguard Worker}
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Workerdefine void @med(i32 %x) {
30*9880d681SAndroid Build Coastguard Workerentry:
31*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %return [
32*9880d681SAndroid Build Coastguard Worker    i32 30, label %bb0
33*9880d681SAndroid Build Coastguard Worker    i32 10, label %bb1
34*9880d681SAndroid Build Coastguard Worker    i32 40, label %bb1
35*9880d681SAndroid Build Coastguard Worker    i32 50, label %bb2
36*9880d681SAndroid Build Coastguard Worker    i32 20, label %bb3
37*9880d681SAndroid Build Coastguard Worker  ]
38*9880d681SAndroid Build Coastguard Workerbb0: tail call void @g(i32 0) br label %return
39*9880d681SAndroid Build Coastguard Workerbb1: tail call void @g(i32 1) br label %return
40*9880d681SAndroid Build Coastguard Workerbb2: tail call void @g(i32 1) br label %return
41*9880d681SAndroid Build Coastguard Workerbb3: tail call void @g(i32 2) br label %return
42*9880d681SAndroid Build Coastguard Workerreturn: ret void
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker; Lowered as a jump table when sparse, and branches when dense.
45*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: med
46*9880d681SAndroid Build Coastguard Worker; SPARSE: addl $-10
47*9880d681SAndroid Build Coastguard Worker; SPARSE: cmpl $40
48*9880d681SAndroid Build Coastguard Worker; SPARSE: ja
49*9880d681SAndroid Build Coastguard Worker; SPARSE: jmpq *.LJTI
50*9880d681SAndroid Build Coastguard Worker; DENSE-NOT: cmpl
51*9880d681SAndroid Build Coastguard Worker; DENSE: cmpl $29
52*9880d681SAndroid Build Coastguard Worker; DENSE-DAG: cmpl $10
53*9880d681SAndroid Build Coastguard Worker; DENSE-DAG: cmpl $20
54*9880d681SAndroid Build Coastguard Worker; DENSE-DAG: cmpl $30
55*9880d681SAndroid Build Coastguard Worker; DENSE-DAG: cmpl $40
56*9880d681SAndroid Build Coastguard Worker; DENSE-DAG: cmpl $50
57*9880d681SAndroid Build Coastguard Worker; DENSE: retq
58*9880d681SAndroid Build Coastguard Worker}
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Workerdefine void @dense(i32 %x) {
61*9880d681SAndroid Build Coastguard Workerentry:
62*9880d681SAndroid Build Coastguard Worker  switch i32 %x, label %return [
63*9880d681SAndroid Build Coastguard Worker    i32 12, label %bb0
64*9880d681SAndroid Build Coastguard Worker    i32 4,  label %bb1
65*9880d681SAndroid Build Coastguard Worker    i32 16, label %bb1
66*9880d681SAndroid Build Coastguard Worker    i32 20, label %bb2
67*9880d681SAndroid Build Coastguard Worker    i32 8,  label %bb3
68*9880d681SAndroid Build Coastguard Worker  ]
69*9880d681SAndroid Build Coastguard Workerbb0: tail call void @g(i32 0) br label %return
70*9880d681SAndroid Build Coastguard Workerbb1: tail call void @g(i32 1) br label %return
71*9880d681SAndroid Build Coastguard Workerbb2: tail call void @g(i32 1) br label %return
72*9880d681SAndroid Build Coastguard Workerbb3: tail call void @g(i32 2) br label %return
73*9880d681SAndroid Build Coastguard Workerreturn: ret void
74*9880d681SAndroid Build Coastguard Worker
75*9880d681SAndroid Build Coastguard Worker; Lowered as a jump table when sparse, and branches when dense.
76*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: dense
77*9880d681SAndroid Build Coastguard Worker; CHECK: addl $-4
78*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $16
79*9880d681SAndroid Build Coastguard Worker; CHECK: ja
80*9880d681SAndroid Build Coastguard Worker; CHECK: jmpq *.LJTI
81*9880d681SAndroid Build Coastguard Worker}
82