18a9cb242SWouter van Oortmerssen; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -disable-block-placement -verify-machineinstrs | FileCheck %s 2950a13cfSDan Gohman 3f0b165a7SDan Gohman; Test switch instructions. Block placement is disabled because it reorders 4f0b165a7SDan Gohman; the blocks in a way that isn't interesting here. 5950a13cfSDan Gohman 60c6f5ac5SDan Gohmantarget datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" 7a5908009SSam Cleggtarget triple = "wasm32-unknown-unknown" 8950a13cfSDan Gohman 9950a13cfSDan Gohmandeclare void @foo0() 10950a13cfSDan Gohmandeclare void @foo1() 11950a13cfSDan Gohmandeclare void @foo2() 12950a13cfSDan Gohmandeclare void @foo3() 13950a13cfSDan Gohmandeclare void @foo4() 14950a13cfSDan Gohmandeclare void @foo5() 15950a13cfSDan Gohman 16e51c058eSDan Gohman; CHECK-LABEL: bar32: 171d68e80fSDan Gohman; CHECK: block {{$}} 181d68e80fSDan Gohman; CHECK: block {{$}} 191d68e80fSDan Gohman; CHECK: block {{$}} 201d68e80fSDan Gohman; CHECK: block {{$}} 211d68e80fSDan Gohman; CHECK: block {{$}} 221d68e80fSDan Gohman; CHECK: block {{$}} 231d68e80fSDan Gohman; CHECK: block {{$}} 247f50c15bSThomas Lively; 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, 6{{$}} 257f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_1: 26755a8959SThomas Lively; CHECK: call foo0{{$}} 277f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_2: 28755a8959SThomas Lively; CHECK: call foo1{{$}} 297f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_3: 30755a8959SThomas Lively; CHECK: call foo2{{$}} 317f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_4: 32755a8959SThomas Lively; CHECK: call foo3{{$}} 337f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_5: 34755a8959SThomas Lively; CHECK: call foo4{{$}} 357f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_6: 36755a8959SThomas Lively; CHECK: call foo5{{$}} 377f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_7: 38e51c058eSDan Gohman; CHECK: return{{$}} 39950a13cfSDan Gohmandefine void @bar32(i32 %n) { 40950a13cfSDan Gohmanentry: 41950a13cfSDan Gohman switch i32 %n, label %sw.epilog [ 42950a13cfSDan Gohman i32 0, label %sw.bb 43950a13cfSDan Gohman i32 1, label %sw.bb 44950a13cfSDan Gohman i32 2, label %sw.bb 45950a13cfSDan Gohman i32 3, label %sw.bb 46950a13cfSDan Gohman i32 4, label %sw.bb 47950a13cfSDan Gohman i32 5, label %sw.bb 48950a13cfSDan Gohman i32 6, label %sw.bb 49950a13cfSDan Gohman i32 7, label %sw.bb.1 50950a13cfSDan Gohman i32 8, label %sw.bb.1 51950a13cfSDan Gohman i32 9, label %sw.bb.1 52950a13cfSDan Gohman i32 10, label %sw.bb.1 53950a13cfSDan Gohman i32 11, label %sw.bb.1 54950a13cfSDan Gohman i32 12, label %sw.bb.1 55950a13cfSDan Gohman i32 13, label %sw.bb.1 56950a13cfSDan Gohman i32 14, label %sw.bb.1 57950a13cfSDan Gohman i32 15, label %sw.bb.2 58950a13cfSDan Gohman i32 16, label %sw.bb.2 59950a13cfSDan Gohman i32 17, label %sw.bb.2 60950a13cfSDan Gohman i32 18, label %sw.bb.2 61950a13cfSDan Gohman i32 19, label %sw.bb.2 62950a13cfSDan Gohman i32 20, label %sw.bb.2 63950a13cfSDan Gohman i32 21, label %sw.bb.3 64950a13cfSDan Gohman i32 22, label %sw.bb.4 65950a13cfSDan Gohman i32 23, label %sw.bb.5 66950a13cfSDan Gohman ] 67950a13cfSDan Gohman 68950a13cfSDan Gohmansw.bb: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry 69950a13cfSDan Gohman tail call void @foo0() 70950a13cfSDan Gohman br label %sw.epilog 71950a13cfSDan Gohman 72950a13cfSDan Gohmansw.bb.1: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry 73950a13cfSDan Gohman tail call void @foo1() 74950a13cfSDan Gohman br label %sw.epilog 75950a13cfSDan Gohman 76950a13cfSDan Gohmansw.bb.2: ; preds = %entry, %entry, %entry, %entry, %entry, %entry 77950a13cfSDan Gohman tail call void @foo2() 78950a13cfSDan Gohman br label %sw.epilog 79950a13cfSDan Gohman 80950a13cfSDan Gohmansw.bb.3: ; preds = %entry 81950a13cfSDan Gohman tail call void @foo3() 82950a13cfSDan Gohman br label %sw.epilog 83950a13cfSDan Gohman 84950a13cfSDan Gohmansw.bb.4: ; preds = %entry 85950a13cfSDan Gohman tail call void @foo4() 86950a13cfSDan Gohman br label %sw.epilog 87950a13cfSDan Gohman 88950a13cfSDan Gohmansw.bb.5: ; preds = %entry 89950a13cfSDan Gohman tail call void @foo5() 90950a13cfSDan Gohman br label %sw.epilog 91950a13cfSDan Gohman 92950a13cfSDan Gohmansw.epilog: ; preds = %entry, %sw.bb.5, %sw.bb.4, %sw.bb.3, %sw.bb.2, %sw.bb.1, %sw.bb 93950a13cfSDan Gohman ret void 94950a13cfSDan Gohman} 95950a13cfSDan Gohman 96e51c058eSDan Gohman; CHECK-LABEL: bar64: 971d68e80fSDan Gohman; CHECK: block {{$}} 98*8df30d98SThomas Lively; CHECK: i64.const 99*8df30d98SThomas Lively; CHECK: i64.gt_u 100*8df30d98SThomas Lively; CHECK: br_if 0 1011d68e80fSDan Gohman; CHECK: block {{$}} 1021d68e80fSDan Gohman; CHECK: block {{$}} 1031d68e80fSDan Gohman; CHECK: block {{$}} 1041d68e80fSDan Gohman; CHECK: block {{$}} 1051d68e80fSDan Gohman; CHECK: block {{$}} 1061d68e80fSDan Gohman; CHECK: block {{$}} 107*8df30d98SThomas Lively; CHECK: i32.wrap_i64 108*8df30d98SThomas Lively; 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{{$}} 1097f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_2: 110*8df30d98SThomas Lively; CHECK: call foo0{{$}} 1117f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_3: 112*8df30d98SThomas Lively; CHECK: call foo1{{$}} 1137f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_4: 114*8df30d98SThomas Lively; CHECK: call foo2{{$}} 1157f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_5: 116*8df30d98SThomas Lively; CHECK: call foo3{{$}} 1177f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_6: 118*8df30d98SThomas Lively; CHECK: call foo4{{$}} 1197f50c15bSThomas Lively; CHECK: .LBB{{[0-9]+}}_7: 120*8df30d98SThomas Lively; CHECK: call foo5{{$}} 121*8df30d98SThomas Lively; CHECK: .LBB{{[0-9]+}}_8: 122e51c058eSDan Gohman; CHECK: return{{$}} 123950a13cfSDan Gohmandefine void @bar64(i64 %n) { 124950a13cfSDan Gohmanentry: 125950a13cfSDan Gohman switch i64 %n, label %sw.epilog [ 126950a13cfSDan Gohman i64 0, label %sw.bb 127950a13cfSDan Gohman i64 1, label %sw.bb 128950a13cfSDan Gohman i64 2, label %sw.bb 129950a13cfSDan Gohman i64 3, label %sw.bb 130950a13cfSDan Gohman i64 4, label %sw.bb 131950a13cfSDan Gohman i64 5, label %sw.bb 132950a13cfSDan Gohman i64 6, label %sw.bb 133950a13cfSDan Gohman i64 7, label %sw.bb.1 134950a13cfSDan Gohman i64 8, label %sw.bb.1 135950a13cfSDan Gohman i64 9, label %sw.bb.1 136950a13cfSDan Gohman i64 10, label %sw.bb.1 137950a13cfSDan Gohman i64 11, label %sw.bb.1 138950a13cfSDan Gohman i64 12, label %sw.bb.1 139950a13cfSDan Gohman i64 13, label %sw.bb.1 140950a13cfSDan Gohman i64 14, label %sw.bb.1 141950a13cfSDan Gohman i64 15, label %sw.bb.2 142950a13cfSDan Gohman i64 16, label %sw.bb.2 143950a13cfSDan Gohman i64 17, label %sw.bb.2 144950a13cfSDan Gohman i64 18, label %sw.bb.2 145950a13cfSDan Gohman i64 19, label %sw.bb.2 146950a13cfSDan Gohman i64 20, label %sw.bb.2 147950a13cfSDan Gohman i64 21, label %sw.bb.3 148950a13cfSDan Gohman i64 22, label %sw.bb.4 149950a13cfSDan Gohman i64 23, label %sw.bb.5 150950a13cfSDan Gohman ] 151950a13cfSDan Gohman 152950a13cfSDan Gohmansw.bb: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry 153950a13cfSDan Gohman tail call void @foo0() 154950a13cfSDan Gohman br label %sw.epilog 155950a13cfSDan Gohman 156950a13cfSDan Gohmansw.bb.1: ; preds = %entry, %entry, %entry, %entry, %entry, %entry, %entry, %entry 157950a13cfSDan Gohman tail call void @foo1() 158950a13cfSDan Gohman br label %sw.epilog 159950a13cfSDan Gohman 160950a13cfSDan Gohmansw.bb.2: ; preds = %entry, %entry, %entry, %entry, %entry, %entry 161950a13cfSDan Gohman tail call void @foo2() 162950a13cfSDan Gohman br label %sw.epilog 163950a13cfSDan Gohman 164950a13cfSDan Gohmansw.bb.3: ; preds = %entry 165950a13cfSDan Gohman tail call void @foo3() 166950a13cfSDan Gohman br label %sw.epilog 167950a13cfSDan Gohman 168950a13cfSDan Gohmansw.bb.4: ; preds = %entry 169950a13cfSDan Gohman tail call void @foo4() 170950a13cfSDan Gohman br label %sw.epilog 171950a13cfSDan Gohman 172950a13cfSDan Gohmansw.bb.5: ; preds = %entry 173950a13cfSDan Gohman tail call void @foo5() 174950a13cfSDan Gohman br label %sw.epilog 175950a13cfSDan Gohman 176950a13cfSDan Gohmansw.epilog: ; preds = %entry, %sw.bb.5, %sw.bb.4, %sw.bb.3, %sw.bb.2, %sw.bb.1, %sw.bb 177950a13cfSDan Gohman ret void 178950a13cfSDan Gohman} 179*8df30d98SThomas Lively 180*8df30d98SThomas Lively; CHECK-LABEL: truncated: 181*8df30d98SThomas Lively; CHECK: block 182*8df30d98SThomas Lively; CHECK: block 183*8df30d98SThomas Lively; CHECK: block 184*8df30d98SThomas Lively; CHECK: i32.wrap_i64 185*8df30d98SThomas Lively; CHECK: br_table {{[^,]+}}, 0, 1, 2{{$}} 186*8df30d98SThomas Lively; CHECK: .LBB{{[0-9]+}}_1 187*8df30d98SThomas Lively; CHECK: end_block 188*8df30d98SThomas Lively; CHECK: call foo0{{$}} 189*8df30d98SThomas Lively; CHECK: return{{$}} 190*8df30d98SThomas Lively; CHECK: .LBB{{[0-9]+}}_2 191*8df30d98SThomas Lively; CHECK: end_block 192*8df30d98SThomas Lively; CHECK: call foo1{{$}} 193*8df30d98SThomas Lively; CHECK: return{{$}} 194*8df30d98SThomas Lively; CHECK: .LBB{{[0-9]+}}_3 195*8df30d98SThomas Lively; CHECK: end_block 196*8df30d98SThomas Lively; CHECK: call foo2{{$}} 197*8df30d98SThomas Lively; CHECK: return{{$}} 198*8df30d98SThomas Lively; CHECK: end_function 199*8df30d98SThomas Livelydefine void @truncated(i64 %n) { 200*8df30d98SThomas Livelyentry: 201*8df30d98SThomas Lively %m = trunc i64 %n to i32 202*8df30d98SThomas Lively switch i32 %m, label %default [ 203*8df30d98SThomas Lively i32 0, label %bb1 204*8df30d98SThomas Lively i32 1, label %bb2 205*8df30d98SThomas Lively ] 206*8df30d98SThomas Lively 207*8df30d98SThomas Livelybb1: 208*8df30d98SThomas Lively tail call void @foo0() 209*8df30d98SThomas Lively ret void 210*8df30d98SThomas Lively 211*8df30d98SThomas Livelybb2: 212*8df30d98SThomas Lively tail call void @foo1() 213*8df30d98SThomas Lively ret void 214*8df30d98SThomas Lively 215*8df30d98SThomas Livelydefault: 216*8df30d98SThomas Lively tail call void @foo2() 217*8df30d98SThomas Lively ret void 218*8df30d98SThomas Lively} 219