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