1# RUN: llc -mtriple=wasm32-unknown-unknown -run-pass wasm-fix-irreducible-control-flow %s -o - | FileCheck %s 2 3# This tests if we correctly create at most 2 routing blocks per entry block, 4# and also whether those routing blocks are generated in the correct place. If 5# one of the predecessor is the layout predecessor of an entry, a routing block 6# for the entry should be generated right after the layout predecessor. 7 8--- | 9 target triple = "wasm32-unknown-unknown" 10 11 define void @test0() { 12 pred0: 13 ret void 14 pred1: 15 ret void 16 entry0: 17 ret void 18 entry1: 19 ret void 20 } 21... 22 23--- 24# CHECK-LABEL: test0 25name: test0 26liveins: 27 - { reg: '$arguments' } 28body: | 29 bb.0.pred0: 30 successors: %bb.1, %bb.2 31 liveins: $arguments 32 %0:i32 = CONST_I32 100, implicit-def $arguments 33 BR_IF %bb.2, %0:i32, implicit-def $arguments 34 ; CHECK: bb.0.pred0: 35 ; CHECK: BR_IF %bb.2, %0, implicit-def $arguments 36 37 bb.1.pred1: 38 ; predecessors: %bb.1 39 successors: %bb.2, %bb.3 40 BR_IF %bb.3, %0:i32, implicit-def $arguments 41 ; CHECK: bb.1.pred1: 42 ; CHECK: BR_IF %bb.7, %0, implicit-def $arguments 43 ; This falls through to bb.2, so we don't need an additional BR here 44 ; CHECK-NOT: BR 45 46 ; Routing block for entry0, when predecessor is outside the loop 47 ; This routing block is shared between the two predecessors: pred0 and pred1. 48 ; CHECK: bb.2: 49 ; CHECK: %1:i32 = CONST_I32 0, implicit-def $arguments 50 ; CHECK: BR %bb.6, implicit-def $arguments 51 52 bb.2.entry0: 53 ; predecessors: %bb.0, %bb.1, %bb.1 54 successors: %bb.3 55 BR %bb.3, implicit-def $arguments 56 ; CHECK: bb.3.entry0: 57 ; CHECK: BR %bb.4, implicit-def $arguments 58 59 ; Routing block for entry1, when predecessor is inside the loop 60 ; CHECK: bb.4: 61 ; CHECK: %1:i32 = CONST_I32 1, implicit-def $arguments 62 ; CHECK: BR %bb.6, implicit-def $arguments 63 64 bb.3.entry1: 65 ; predecessors: %bb.1, %bb.2 66 successors: %bb.2 67 BR %bb.2, implicit-def $arguments 68 ; CHECK: bb.5.entry1: 69 ; CHECK: BR %bb.8, implicit-def $arguments 70 71 ; Dispatch block 72 ; CHECK: bb.6: 73 ; CHECK: BR_TABLE_I32 %1, %bb.3, %bb.5, %bb.5, implicit-def $arguments 74 75 ; Routing block for entry1, when predecessor is outside the loop 76 ; CHECK: bb.7: 77 ; CHECK: %1:i32 = CONST_I32 1, implicit-def $arguments 78 ; CHECK: BR %bb.6, implicit-def $arguments 79 80 ; Routing block for entry0, when predecessor is inside the loop 81 ; CHECK: bb.8: 82 ; CHECK: %1:i32 = CONST_I32 0, implicit-def $arguments 83 ; CHECK: BR %bb.6, implicit-def $arguments 84