1 ; RUN: llc -mtriple=i686-pc-gnu-linux < %s | FileCheck %s -check-prefix=CHECK 2 ; RUN: llc -mtriple=i686-pc-gnu-linux -print-machineinstrs=expand-isel-pseudos %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=CHECK-JT-PROB 3 4 5 ; An unreachable default destination is replaced with the most popular case label. 6 7 define void @foo(i32 %x, i32* %to) { 8 ; CHECK-LABEL: foo: 9 ; CHECK: movl 4(%esp), [[REG:%e[a-z]{2}]] 10 ; CHECK: cmpl $3, [[REG]] 11 ; CHECK: ja .LBB0_6 12 ; CHECK-NEXT: # BB#1: 13 ; CHECK-NEXT: jmpl *.LJTI0_0(,[[REG]],4) 14 ; CHECK: movl $4 15 ; CHECK: retl 16 17 entry: 18 switch i32 %x, label %default [ 19 i32 0, label %bb0 20 i32 1, label %bb1 21 i32 2, label %bb2 22 i32 3, label %bb3 23 i32 4, label %bb4 24 i32 5, label %bb4 25 ] 26 bb0: 27 store i32 0, i32* %to 28 br label %exit 29 bb1: 30 store i32 1, i32* %to 31 br label %exit 32 bb2: 33 store i32 2, i32* %to 34 br label %exit 35 bb3: 36 store i32 3, i32* %to 37 br label %exit 38 bb4: 39 store i32 4, i32* %to 40 br label %exit 41 exit: 42 ret void 43 default: 44 unreachable 45 46 ; The jump table has four entries. 47 ; CHECK-LABEL: .LJTI0_0: 48 ; CHECK-NEXT: .long .LBB0_2 49 ; CHECK-NEXT: .long .LBB0_3 50 ; CHECK-NEXT: .long .LBB0_4 51 ; CHECK-NEXT: .long .LBB0_5 52 } 53 54 ; Check if branch probabilities are correctly assigned to the jump table. 55 56 define void @bar(i32 %x, i32* %to) { 57 ; CHECK-JT-PROB-LABEL: bar: 58 ; CHECK-JT-PROB: Successors according to CFG: BB#6({{[0-9a-fx/= ]+}}14.29%) BB#8({{[0-9a-fx/= ]+}}85.71%) 59 ; CHECK-JT-PROB: Successors according to CFG: BB#1({{[0-9a-fx/= ]+}}16.67%) BB#2({{[0-9a-fx/= ]+}}16.67%) BB#3({{[0-9a-fx/= ]+}}16.67%) BB#4({{[0-9a-fx/= ]+}}16.67%) BB#5({{[0-9a-fx/= ]+}}33.33%) 60 61 entry: 62 switch i32 %x, label %default [ 63 i32 0, label %bb0 64 i32 1, label %bb1 65 i32 2, label %bb2 66 i32 3, label %bb3 67 i32 4, label %bb4 68 i32 5, label %bb4 69 ], !prof !1 70 bb0: 71 store i32 0, i32* %to 72 br label %exit 73 bb1: 74 store i32 1, i32* %to 75 br label %exit 76 bb2: 77 store i32 2, i32* %to 78 br label %exit 79 bb3: 80 store i32 3, i32* %to 81 br label %exit 82 bb4: 83 store i32 4, i32* %to 84 br label %exit 85 default: 86 store i32 5, i32* %to 87 br label %exit 88 exit: 89 ret void 90 } 91 92 !1 = !{!"branch_weights", i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16} 93