;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. ;; NOTE: This test was ported using port_passes_tests_to_lit.py and could be cleaned up. ;; RUN: foreach %s %t wasm-opt --flatten --rereloop -S -o - | filecheck %s (module (memory 1) ;; CHECK: (type $0 (func)) ;; CHECK: (type $1 (func (result i32))) ;; CHECK: (type $2 (func (result f64))) ;; CHECK: (type $3 (func (param i32))) ;; CHECK: (type $4 (func (param i32) (result f32))) ;; CHECK: (type $5 (func (result f32))) ;; CHECK: (global $global (mut i32) (i32.const 0)) (global $global (mut i32) (i32.const 0)) ;; CHECK: (memory $0 1) ;; CHECK: (func $0 (result f64) ;; CHECK-NEXT: (local $0 f64) ;; CHECK-NEXT: (local $1 f64) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $0 ;; CHECK-NEXT: (f64.const -nan:0xfffffd63e4e5a) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $0 (result f64) (if (i32.const 0) (then (loop $label$2 (unreachable) ) ) ) (f64.const -nan:0xfffffd63e4e5a) ) ;; CHECK: (func $1 (result i32) ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$6$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block $switch$1$leave ;; CHECK-NEXT: (block $switch$1$default ;; CHECK-NEXT: (block $switch$1$case$4 ;; CHECK-NEXT: (br_table $switch$1$case$4 $switch$1$case$4 $switch$1$default ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$6$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block $switch$6$leave ;; CHECK-NEXT: (block $switch$6$default ;; CHECK-NEXT: (block $switch$6$case$3 ;; CHECK-NEXT: (br_table $switch$6$case$3 $switch$6$default ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $0 ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) (func $1 (result i32) (block $label$8 (block $label$9 (block $label$16 (block $label$18 (block $label$19 (br_table $label$18 $label$16 $label$19 (i32.const 0) ) ) (br_table $label$9 $label$8 (i32.const 1) ) ) (unreachable) ) (unreachable) ) (unreachable) ) (i32.const 2) ) ;; CHECK: (func $skip-empty ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $skip-empty (block $a1 (block $a2 (block $a3 (block $a4 (br $a4) ) (br $a3) ) (br $a2) ) (br $a1) ) ) ;; CHECK: (func $skip-empty-2 ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block $block$5$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$5$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$4$break ;; CHECK-NEXT: (call $skip-empty) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$4$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (call $skip-empty) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $skip-empty-2 (block $a1 (block $a2 (block $a3 (block $a4 (br $a4) ) (call $skip-empty) (br $a3) ) (call $skip-empty) (br $a2) ) (br $a1) ) ) ;; CHECK: (func $skip-empty-3 ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block $block$5$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$5$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$4$break ;; CHECK-NEXT: (call $skip-empty) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$4$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (call $skip-empty) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $skip-empty-3 (block $a1 (block $a2 (block $a3 (block $a4 (nop) (br $a4) (nop) ) (nop) (call $skip-empty) (nop) (br $a3) ) (nop) (call $skip-empty) (nop) (br $a2) ) (br $a1) ) ) ;; CHECK: (func $skip-empty-4 (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $skip-empty-4 (param $x i32) (block $a1 (block $a2 (block $a3 (block $a4 (br_table $a1 $a2 $a3 $a4 $a1 $a2 $a3 $a4 (local.get $x)) ) (br $a3) ) (br $a2) ) (br $a1) ) ) ;; CHECK: (func $skipping (param $0 i32) (result f32) ;; CHECK-NEXT: (local $1 f32) ;; CHECK-NEXT: (local $2 f32) ;; CHECK-NEXT: (local $3 f32) ;; CHECK-NEXT: (local $4 f32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (f32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $4 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $skipping (param $0 i32) (result f32) (if (i32.const 0) (then (unreachable) ) ) ;; branches joining here lead to skip opportunities (loop $label$2 (result f32) (f32.const 1) ) ) ;; CHECK: (func $merging ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $merging (if (i32.const 0) (then (return) ) ;; no else, but the else ends up with a return too, and we can merge them ) ) ;; CHECK: (func $unswitch ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $unswitch (block $label$1 (br_table $label$1 $label$1 (i32.const 0) ) ) ) ;; CHECK: (func $skip-only-empty ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block $block$3$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (global.set $global ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$3$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$3$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $skip-only-empty (if (i32.const 1) (then (global.set $global (i32.const 0) ) ) ) ) ;; CHECK: (func $skip-only-one-branch-out (result i32) ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $0 ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $skip-only-one-branch-out (result i32) (block $label$1 (nop) ) (if (i32.const 1) (then (unreachable) ;; blocks a path through ) ) (i32.const 0) ) ;; CHECK: (func $multipass-for-skips (result f32) ;; CHECK-NEXT: (local $0 f32) ;; CHECK-NEXT: (local $1 f32) ;; CHECK-NEXT: (local $2 f32) ;; CHECK-NEXT: (local $3 f32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (block $block$6$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $0 ;; CHECK-NEXT: (f32.const 9223372036854775808) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$6$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (f32.const 65505) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$6$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $multipass-for-skips (result f32) (if (result f32) (i32.const 0) (then (block (result f32) (block $label$2 (br_if $label$2 (i32.const 536870912) ) ) (f32.const 9223372036854775808) ) ) (else (f32.const 65505) ) ) ) ;; CHECK: (func $branch-merge-vs-replace ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $branch-merge-vs-replace (if (i32.const 0) (then (unreachable) ) ) ) ;; CHECK: (func $unswitch-amount ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const -23) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$5$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block $switch$4$leave ;; CHECK-NEXT: (block $switch$4$default ;; CHECK-NEXT: (block $switch$4$case$2 ;; CHECK-NEXT: (br_table $switch$4$case$2 $switch$4$default ;; CHECK-NEXT: (i32.const 44064) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$5$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $unswitch-amount (block $label$1 (if (i32.const -23) (then (nop) ) (else (block (block $label$4 (br_table $label$1 $label$4 (i32.const 44064) ) ) (unreachable) ) ) ) ) ) ) ;; manual TODO: merge branches, all the parts (module ;; CHECK: (type $3 (func (param i32))) ;; CHECK: (type $0 (func)) (type $0 (func)) ;; CHECK: (type $2 (func (param i32) (result i32))) ;; CHECK: (type $1 (func (result i32))) (type $1 (func (result i32))) (type $2 (func (param i32) (result i32))) (type $3 (func (param i32))) ;; CHECK: (func $trivial ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) (func $trivial (; 0 ;) (type $0) (nop) ) ;; CHECK: (func $trivial2 ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $trivial) ;; CHECK-NEXT: (call $trivial) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $trivial2 (; 1 ;) (type $0) (block (call $trivial) (nop) (call $trivial) (nop) ) (nop) ) ;; CHECK: (func $return-void ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) (func $return-void (; 2 ;) (type $0) (return) (unreachable) ) ;; CHECK: (func $return-val (result i32) ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $return-val (; 3 ;) (type $1) (result i32) (return (i32.const 1) ) (unreachable) ) ;; CHECK: (func $ifs (param $x i32) (result i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (local $6 i32) ;; CHECK-NEXT: (local $7 i32) ;; CHECK-NEXT: (local $8 i32) ;; CHECK-NEXT: (local $9 i32) ;; CHECK-NEXT: (local $10 i32) ;; CHECK-NEXT: (local $11 i32) ;; CHECK-NEXT: (local $12 i32) ;; CHECK-NEXT: (local $13 i32) ;; CHECK-NEXT: (local $14 i32) ;; CHECK-NEXT: (local $15 i32) ;; CHECK-NEXT: (local $16 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $6 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $6) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $7 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $7) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $8 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $8) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $9 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $9) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $10 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $10) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $11 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $11) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $ifs (; 4 ;) (type $2) (param $x i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (block (block (local.set $1 (local.get $x) ) (if (local.get $1) (then (block (block (local.set $2 (local.get $x) ) (if (local.get $2) (then (block (return (i32.const 2) ) (unreachable) ) ) (else (block (return (i32.const 3) ) (unreachable) ) ) ) ) (unreachable) ) ) ) ) (nop) (block (local.set $3 (local.get $x) ) (if (local.get $3) (then (block (return (i32.const 4) ) (unreachable) ) ) ) ) (nop) (return (i32.const 5) ) (unreachable) ) (local.set $5 (local.get $4) ) (return (local.get $5) ) ) ;; CHECK: (func $loops (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (local $6 i32) ;; CHECK-NEXT: (local $7 i32) ;; CHECK-NEXT: (local $8 i32) ;; CHECK-NEXT: (local $9 i32) ;; CHECK-NEXT: (local $10 i32) ;; CHECK-NEXT: (block $block$17$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $4 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $5 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $5) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (loop $shape$2$continue ;; CHECK-NEXT: (call $trivial) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $shape$2$continue) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$17$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$19$break ;; CHECK-NEXT: (loop $shape$4$continue ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $trivial) ;; CHECK-NEXT: (local.set $6 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $6) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $7 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $7) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (br $shape$4$continue) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$19$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$26$break ;; CHECK-NEXT: (loop $shape$6$continue ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $trivial) ;; CHECK-NEXT: (local.set $8 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $8) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $9 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $9) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (br $shape$6$continue) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$26$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $loops (; 5 ;) (type $3) (param $x i32) (local $1 i32) (local $2 i32) (local $3 i32) (block (block (local.set $1 (local.get $x) ) (if (local.get $1) (then (block (loop $top (block (call $trivial) (nop) (br $top) (unreachable) ) (unreachable) ) (unreachable) ) ) ) ) (nop) (loop $top2 (block (call $trivial) (nop) (local.set $2 (local.get $x) ) (br_if $top2 (local.get $2) ) (nop) ) (nop) ) (nop) (loop $top3 (block (call $trivial) (nop) (block (local.set $3 (local.get $x) ) (if (local.get $3) (then (block (br $top3) (unreachable) ) ) ) ) (nop) ) (nop) ) (nop) ) (nop) ) ;; CHECK: (func $br-out (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (call $br-out ;; CHECK-NEXT: (i32.const 5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $br-out (; 6 ;) (type $3) (param $x i32) (block $out (call $br-out (i32.const 5) ) (nop) (br $out) (unreachable) ) (nop) ) ;; CHECK: (func $unreachable (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (local $6 i32) ;; CHECK-NEXT: (local $7 i32) ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $4 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $4) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$30$break ;; CHECK-NEXT: (call $unreachable ;; CHECK-NEXT: (i32.const 5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$30$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $5 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $6 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $6) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $unreachable ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $unreachable ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $unreachable (; 7 ;) (type $3) (param $x i32) (local $1 i32) (local $2 i32) (block (block (local.set $1 (local.get $x) ) (if (local.get $1) (then (block (block (local.set $2 (local.get $x) ) (if (local.get $2) (then (block (block $block (call $unreachable (i32.const 1) ) (nop) (unreachable) (unreachable) (call $unreachable (i32.const 2) ) (nop) ) (unreachable) ) ) (else (block (block $block4 (call $unreachable (i32.const 3) ) (nop) (return) (unreachable) (call $unreachable (i32.const 4) ) (nop) ) (unreachable) ) ) ) ) (unreachable) ) ) ) ) (nop) (block $out (call $unreachable (i32.const 5) ) (nop) (br $out) (unreachable) (call $unreachable (i32.const 6) ) (nop) ) (nop) ) (nop) ) ;; CHECK: (func $empty-blocks (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (block $block$3$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$3$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $empty-blocks (; 8 ;) (type $3) (param $x i32) (block (block $block ) (nop) (block $block5 ) (nop) ) (nop) ) ;; CHECK: (func $before-and-after (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (local $6 i32) ;; CHECK-NEXT: (local $7 i32) ;; CHECK-NEXT: (local $8 i32) ;; CHECK-NEXT: (local $9 i32) ;; CHECK-NEXT: (local $10 i32) ;; CHECK-NEXT: (local $11 i32) ;; CHECK-NEXT: (local $12 i32) ;; CHECK-NEXT: (local $13 i32) ;; CHECK-NEXT: (local $14 i32) ;; CHECK-NEXT: (local $15 i32) ;; CHECK-NEXT: (local $16 i32) ;; CHECK-NEXT: (block $block$3$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $6 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $6) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $7 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $7) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (br $block$3$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$3$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$7$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 6) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 7) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 8) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$7$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$8$break ;; CHECK-NEXT: (loop $shape$4$continue ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 9) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $8 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $8) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $9 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $9) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (br $shape$4$continue) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$8$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$10$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 10) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 11) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $10 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $10) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $11 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $11) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 12) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$10$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$10$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$13$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 13) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $12 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $4 ;; CHECK-NEXT: (local.get $12) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $13 ;; CHECK-NEXT: (local.get $4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $13) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 14) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$13$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 15) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$13$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$16$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $14 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $5 ;; CHECK-NEXT: (local.get $14) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $15 ;; CHECK-NEXT: (local.get $5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $15) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 16) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$16$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$16$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$19$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 17) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 18) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 19) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 20) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 21) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 22) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$19$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$21$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 23) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 24) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$21$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $before-and-after ;; CHECK-NEXT: (i32.const 25) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $before-and-after (; 9 ;) (type $3) (param $x i32) (local $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) (block (call $before-and-after (i32.const 1) ) (nop) (block $block (call $before-and-after (i32.const 2) ) (nop) ) (nop) (call $before-and-after (i32.const 3) ) (nop) (block $out (call $before-and-after (i32.const 4) ) (nop) (local.set $1 (local.get $x) ) (br_if $out (local.get $1) ) (nop) (call $before-and-after (i32.const 5) ) (nop) ) (nop) (call $before-and-after (i32.const 6) ) (nop) (loop $loop-in (nop) ) (nop) (call $before-and-after (i32.const 7) ) (nop) (loop $top (nop) ) (nop) (call $before-and-after (i32.const 8) ) (nop) (loop $top2 (block (call $before-and-after (i32.const 9) ) (nop) (local.set $2 (local.get $x) ) (br_if $top2 (local.get $2) ) (nop) (call $before-and-after (i32.const 10) ) (nop) ) (nop) ) (nop) (call $before-and-after (i32.const 11) ) (nop) (block (local.set $3 (local.get $x) ) (if (local.get $3) (then (block (call $before-and-after (i32.const 12) ) (nop) ) ) ) ) (nop) (call $before-and-after (i32.const 13) ) (nop) (block (local.set $4 (local.get $x) ) (if (local.get $4) (then (block (call $before-and-after (i32.const 14) ) (nop) ) ) (else (block (call $before-and-after (i32.const 15) ) (nop) ) ) ) ) (nop) (block (local.set $5 (local.get $x) ) (if (local.get $5) (then (block (block $block8 (call $before-and-after (i32.const 16) ) (nop) ) (nop) ) ) ) ) (nop) (call $before-and-after (i32.const 17) ) (nop) (block $block9 (call $before-and-after (i32.const 18) ) (nop) (block $block10 (call $before-and-after (i32.const 19) ) (nop) ) (nop) (call $before-and-after (i32.const 20) ) (nop) ) (nop) (call $before-and-after (i32.const 21) ) (nop) (block $block11 (block $block12 (call $before-and-after (i32.const 22) ) (nop) ) (nop) ) (nop) (call $before-and-after (i32.const 23) ) (nop) (block $no1 (block $no2 (call $before-and-after (i32.const 24) ) (nop) ) (nop) ) (nop) (call $before-and-after (i32.const 25) ) (nop) ) (nop) ) ;; CHECK: (func $switch (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (local $6 i32) ;; CHECK-NEXT: (local $7 i32) ;; CHECK-NEXT: (block $block$3$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $4 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$3$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block $block$9$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $switch ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $5 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $6 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block $switch$3$leave ;; CHECK-NEXT: (block $switch$3$default ;; CHECK-NEXT: (block $switch$3$case$9 ;; CHECK-NEXT: (br_table $switch$3$case$9 $switch$3$case$9 $switch$3$case$9 $switch$3$default ;; CHECK-NEXT: (local.get $6) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$9$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $switch ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$9$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $switch ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $switch (; 10 ;) (type $3) (param $x i32) (local $1 i32) (local $2 i32) (block $out (block $a (local.set $1 (local.get $x) ) (br_table $a $a (local.get $1) ) (unreachable) ) (nop) (call $switch (i32.const 1) ) (nop) (block $b (block $c (local.set $2 (local.get $x) ) (br_table $b $b $b $c (local.get $2) ) (unreachable) ) (nop) (call $switch (i32.const 2) ) (nop) ) (nop) (call $switch (i32.const 3) ) (nop) ) (nop) ) ;; CHECK: (func $no-return ;; CHECK-NEXT: (local $0 i32) ;; CHECK-NEXT: (block $block$4$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$4$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$4$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $no-return (; 11 ;) (type $0) (if (i32.const 1) (then (block (drop (i32.const 2) ) (nop) ) ) (else (block (drop (i32.const 3) ) (nop) ) ) ) (nop) ) ;; CHECK: (func $if-br-wat (param $x i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (local $6 i32) ;; CHECK-NEXT: (local $7 i32) ;; CHECK-NEXT: (block $block$2$break ;; CHECK-NEXT: (block $block$12$break ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $if-br-wat ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $3 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $4 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $4) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $if-br-wat ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$12$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $5 ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $2 ;; CHECK-NEXT: (local.get $5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $6 ;; CHECK-NEXT: (local.get $2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $6) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (else ;; CHECK-NEXT: (br $block$12$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $if-br-wat ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (br $block$2$break) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (call $if-br-wat ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (return) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $if-br-wat (; 12 ;) (type $3) (param $x i32) (local $1 i32) (local $2 i32) (block (call $if-br-wat (i32.const 0) ) (nop) (block $label$2 (block (local.set $1 (local.get $x) ) (if (local.get $1) (then (block (call $if-br-wat (i32.const 1) ) (nop) ) ) (else (block (block (local.set $2 (local.get $x) ) (if (local.get $2) (then (block (br $label$2) (unreachable) ) ) ) ) (nop) ) ) ) ) (nop) (call $if-br-wat (i32.const 2) ) (nop) ) (nop) (call $if-br-wat (i32.const 3) ) (nop) ) (nop) ) ;; CHECK: (func $switcher-to-nowhere (param $0 i32) (result i32) ;; CHECK-NEXT: (local $1 i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) ;; CHECK-NEXT: (local $4 i32) ;; CHECK-NEXT: (local $5 i32) ;; CHECK-NEXT: (local $6 i32) ;; CHECK-NEXT: (local $7 i32) ;; CHECK-NEXT: (local $8 i32) ;; CHECK-NEXT: (local $9 i32) ;; CHECK-NEXT: (local $10 i32) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (local.set $4 ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $1 ;; CHECK-NEXT: (local.get $4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.set $5 ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block $switch$1$leave ;; CHECK-NEXT: (block $switch$1$default ;; CHECK-NEXT: (block $switch$1$case$3 ;; CHECK-NEXT: (block $switch$1$case$4 ;; CHECK-NEXT: (br_table $switch$1$case$4 $switch$1$case$3 $switch$1$default ;; CHECK-NEXT: (local.get $5) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (block ;; CHECK-NEXT: (block ;; CHECK-NEXT: (return ;; CHECK-NEXT: (i32.const 3) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) (func $switcher-to-nowhere (; 13 ;) (type $2) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) (block (block $switch (block $switch-case0 (block $switch-case (local.set $1 (local.get $0) ) (br_table $switch-case $switch-case0 $switch (local.get $1) ) (unreachable) ) (nop) (return (i32.const 1) ) (unreachable) ) (nop) (return (i32.const 2) ) (unreachable) ) (nop) (return (i32.const 3) ) (unreachable) ) (local.set $3 (local.get $2) ) (return (local.get $3) ) ) )