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 83define void @dense_optsize(i32 %x) optsize { 84entry: 85 switch i32 %x, label %return [ 86 i32 12, label %bb0 87 i32 4, label %bb1 88 i32 16, label %bb1 89 i32 20, label %bb2 90 i32 8, label %bb3 91 ] 92bb0: tail call void @g(i32 0) br label %return 93bb1: tail call void @g(i32 1) br label %return 94bb2: tail call void @g(i32 1) br label %return 95bb3: tail call void @g(i32 2) br label %return 96return: ret void 97 98; Lowered as branches. 99; CHECK-LABEL: dense_optsize 100; CHECK: cmpl $11 101; CHECK: cmpl $20 102; CHECK: cmpl $16 103; CHECK: cmpl $12 104; CHECK: cmpl $4 105; CHECK: cmpl $8 106; CHECK: retq 107} 108 109define void @dense_pgso(i32 %x) !prof !14 { 110entry: 111 switch i32 %x, label %return [ 112 i32 12, label %bb0 113 i32 4, label %bb1 114 i32 16, label %bb1 115 i32 20, label %bb2 116 i32 8, label %bb3 117 ] 118bb0: tail call void @g(i32 0) br label %return 119bb1: tail call void @g(i32 1) br label %return 120bb2: tail call void @g(i32 1) br label %return 121bb3: tail call void @g(i32 2) br label %return 122return: ret void 123 124; Lowered as branches. 125; CHECK-LABEL: dense_pgso 126; CHECK: cmpl $11 127; CHECK: cmpl $20 128; CHECK: cmpl $16 129; CHECK: cmpl $12 130; CHECK: cmpl $4 131; CHECK: cmpl $8 132; CHECK: retq 133} 134 135!llvm.module.flags = !{!0} 136!0 = !{i32 1, !"ProfileSummary", !1} 137!1 = !{!2, !3, !4, !5, !6, !7, !8, !9} 138!2 = !{!"ProfileFormat", !"InstrProf"} 139!3 = !{!"TotalCount", i64 10000} 140!4 = !{!"MaxCount", i64 10} 141!5 = !{!"MaxInternalCount", i64 1} 142!6 = !{!"MaxFunctionCount", i64 1000} 143!7 = !{!"NumCounts", i64 3} 144!8 = !{!"NumFunctions", i64 3} 145!9 = !{!"DetailedSummary", !10} 146!10 = !{!11, !12, !13} 147!11 = !{i32 10000, i64 100, i32 1} 148!12 = !{i32 999000, i64 100, i32 1} 149!13 = !{i32 999999, i64 1, i32 2} 150!14 = !{!"function_entry_count", i64 0} 151