1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs | FileCheck %s 2 3 ; Test switch instructions. Block placement is disabled because it reorders 4 ; the blocks in a way that isn't interesting here. 5 6 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" 7 target triple = "wasm32-unknown-unknown" 8 9 declare void @foo0() 10 declare void @foo1() 11 declare void @foo2() 12 declare void @foo3() 13 declare void @foo4() 14 declare void @foo5() 15 16 ; CHECK-LABEL: bar32: 17 ; CHECK: block{{$}} 18 ; CHECK: block{{$}} 19 ; CHECK: block{{$}} 20 ; CHECK: block{{$}} 21 ; CHECK: block{{$}} 22 ; CHECK: block{{$}} 23 ; CHECK: block{{$}} 24 ; CHECK: br_table {{[^,]+}}, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 4, 5, 0{{$}} 25 ; CHECK: .LBB0_2: 26 ; CHECK: call foo0@FUNCTION{{$}} 27 ; CHECK: .LBB0_3: 28 ; CHECK: call foo1@FUNCTION{{$}} 29 ; CHECK: .LBB0_4: 30 ; CHECK: call foo2@FUNCTION{{$}} 31 ; CHECK: .LBB0_5: 32 ; CHECK: call foo3@FUNCTION{{$}} 33 ; CHECK: .LBB0_6: 34 ; CHECK: call foo4@FUNCTION{{$}} 35 ; CHECK: .LBB0_7: 36 ; CHECK: call foo5@FUNCTION{{$}} 37 ; CHECK: .LBB0_8: 38 ; CHECK: return{{$}} 39 define void @bar32(i32 %n) { 40 entry: 41 switch i32 %n, label %sw.epilog [ 42 i32 0, label %sw.bb 43 i32 1, label %sw.bb 44 i32 2, label %sw.bb 45 i32 3, label %sw.bb 46 i32 4, label %sw.bb 47 i32 5, label %sw.bb 48 i32 6, label %sw.bb 49 i32 7, label %sw.bb.1 50 i32 8, label %sw.bb.1 51 i32 9, label %sw.bb.1 52 i32 10, label %sw.bb.1 53 i32 11, label %sw.bb.1 54 i32 12, label %sw.bb.1 55 i32 13, label %sw.bb.1 56 i32 14, label %sw.bb.1 57 i32 15, label %sw.bb.2 58 i32 16, label %sw.bb.2 59 i32 17, label %sw.bb.2 60 i32 18, label %sw.bb.2 61 i32 19, label %sw.bb.2 62 i32 20, label %sw.bb.2 63 i32 21, label %sw.bb.3 64 i32 22, label %sw.bb.4 65 i32 23, label %sw.bb.5 66 ] 67 68 sw.bb: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry 69 tail call void @foo0() 70 br label %sw.epilog 71 72 sw.bb.1: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry 73 tail call void @foo1() 74 br label %sw.epilog 75 76 sw.bb.2: ; preds = %entry, %entry, %entry, %entry, %entry, %entry 77 tail call void @foo2() 78 br label %sw.epilog 79 80 sw.bb.3: ; preds = %entry 81 tail call void @foo3() 82 br label %sw.epilog 83 84 sw.bb.4: ; preds = %entry 85 tail call void @foo4() 86 br label %sw.epilog 87 88 sw.bb.5: ; preds = %entry 89 tail call void @foo5() 90 br label %sw.epilog 91 92 sw.epilog: ; preds = %entry, %sw.bb.5, %sw.bb.4, %sw.bb.3, %sw.bb.2, %sw.bb.1, %sw.bb 93 ret void 94 } 95 96 ; CHECK-LABEL: bar64: 97 ; CHECK: block{{$}} 98 ; CHECK: block{{$}} 99 ; CHECK: block{{$}} 100 ; CHECK: block{{$}} 101 ; CHECK: block{{$}} 102 ; CHECK: block{{$}} 103 ; CHECK: block{{$}} 104 ; CHECK: br_table {{[^,]+}}, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 4, 5, 0{{$}} 105 ; CHECK: .LBB1_2: 106 ; CHECK: call foo0@FUNCTION{{$}} 107 ; CHECK: .LBB1_3: 108 ; CHECK: call foo1@FUNCTION{{$}} 109 ; CHECK: .LBB1_4: 110 ; CHECK: call foo2@FUNCTION{{$}} 111 ; CHECK: .LBB1_5: 112 ; CHECK: call foo3@FUNCTION{{$}} 113 ; CHECK: .LBB1_6: 114 ; CHECK: call foo4@FUNCTION{{$}} 115 ; CHECK: .LBB1_7: 116 ; CHECK: call foo5@FUNCTION{{$}} 117 ; CHECK: .LBB1_8: 118 ; CHECK: return{{$}} 119 define void @bar64(i64 %n) { 120 entry: 121 switch i64 %n, label %sw.epilog [ 122 i64 0, label %sw.bb 123 i64 1, label %sw.bb 124 i64 2, label %sw.bb 125 i64 3, label %sw.bb 126 i64 4, label %sw.bb 127 i64 5, label %sw.bb 128 i64 6, label %sw.bb 129 i64 7, label %sw.bb.1 130 i64 8, label %sw.bb.1 131 i64 9, label %sw.bb.1 132 i64 10, label %sw.bb.1 133 i64 11, label %sw.bb.1 134 i64 12, label %sw.bb.1 135 i64 13, label %sw.bb.1 136 i64 14, label %sw.bb.1 137 i64 15, label %sw.bb.2 138 i64 16, label %sw.bb.2 139 i64 17, label %sw.bb.2 140 i64 18, label %sw.bb.2 141 i64 19, label %sw.bb.2 142 i64 20, label %sw.bb.2 143 i64 21, label %sw.bb.3 144 i64 22, label %sw.bb.4 145 i64 23, label %sw.bb.5 146 ] 147 148 sw.bb: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry 149 tail call void @foo0() 150 br label %sw.epilog 151 152 sw.bb.1: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry 153 tail call void @foo1() 154 br label %sw.epilog 155 156 sw.bb.2: ; preds = %entry, %entry, %entry, %entry, %entry, %entry 157 tail call void @foo2() 158 br label %sw.epilog 159 160 sw.bb.3: ; preds = %entry 161 tail call void @foo3() 162 br label %sw.epilog 163 164 sw.bb.4: ; preds = %entry 165 tail call void @foo4() 166 br label %sw.epilog 167 168 sw.bb.5: ; preds = %entry 169 tail call void @foo5() 170 br label %sw.epilog 171 172 sw.epilog: ; preds = %entry, %sw.bb.5, %sw.bb.4, %sw.bb.3, %sw.bb.2, %sw.bb.1, %sw.bb 173 ret void 174 } 175