;; 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 -Oz --all-features -S -o - | filecheck %s (module (memory 100 100) ;; CHECK: (type $0 (func (param i32 i32) (result i32))) ;; CHECK: (type $1 (func (param i32) (result i32))) ;; CHECK: (type $2 (func (param i32 i32 i32 i32) (result i32))) ;; CHECK: (type $3 (func (result v128))) ;; CHECK: (memory $0 100 100) ;; CHECK: (export "localcse" (func $basics)) ;; CHECK: (export "localcse-2" (func $8)) ;; CHECK: (export "propagate-sign-for-mul-i32-lhs-const-pot" (func $9)) ;; CHECK: (export "propagate-sign-for-mul-i32-smin" (func $10)) ;; CHECK: (export "eliminate-redundant-checks-1" (func $11)) ;; CHECK: (export "eliminate-redundant-checks-1a" (func $11)) ;; CHECK: (export "eliminate-redundant-checks-2" (func $12)) ;; CHECK: (export "eliminate-redundant-checks-2a" (func $12)) ;; CHECK: (export "eliminate-redundant-checks-skip-1" (func $13)) ;; CHECK: (export "eliminate-redundant-checks-skip-2" (func $14)) ;; CHECK: (export "precompute-simd" (func $precompute-simd)) ;; CHECK: (func $basics (type $0) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) ;; CHECK-NEXT: (i32.add ;; CHECK-NEXT: (local.tee $0 ;; CHECK-NEXT: (i32.add ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $basics (export "localcse") (param $x i32) (param $y i32) (result i32) ;; -O3 does localcse (local $x2 i32) (local $y2 i32) (local.set $x2 (i32.add (local.get $x) (local.get $y)) ) (local.set $y2 (i32.add (local.get $x) (local.get $y)) ) (i32.add (local.get $x2) (local.get $y2)) ) ;; CHECK: (func $8 (type $2) (; has Stack IR ;) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) ;; CHECK-NEXT: (i32.store ;; CHECK-NEXT: (local.tee $0 ;; CHECK-NEXT: (i32.add ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: (i32.const 4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.and ;; CHECK-NEXT: (i32.load ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const -75) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.store ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (i32.or ;; CHECK-NEXT: (i32.load ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const 8) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) (func $8 (export "localcse-2") (param $var$0 i32) (param $var$1 i32) (param $var$2 i32) (param $var$3 i32) (result i32) (block $label$0 (result i32) (i32.store (local.tee $var$2 (i32.add (local.get $var$1) (i32.const 4) ) ) (i32.and (i32.load (local.get $var$2) ) (i32.xor (local.tee $var$2 (i32.const 74) ) (i32.const -1) ) ) ) (i32.store (local.tee $var$1 (i32.add (local.get $var$1) (i32.const 4) ) ) (i32.or (i32.load (local.get $var$1) ) (i32.and (local.get $var$2) (i32.const 8) ) ) ) (i32.const 0) ) ) ;; CHECK: (func $9 (type $1) (; has Stack IR ;) (param $0 i32) (result i32) ;; CHECK-NEXT: (i32.mul ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (i32.const -4) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $9 (export "propagate-sign-for-mul-i32-lhs-const-pot") (param $0 i32) (result i32) (i32.mul (i32.const 4) (i32.sub (i32.const 0) (local.get $0) ) ) ) ;; CHECK: (func $10 (type $1) (; has Stack IR ;) (param $0 i32) (result i32) ;; CHECK-NEXT: (i32.shl ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (i32.const 31) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $10 (export "propagate-sign-for-mul-i32-smin") (param $0 i32) (result i32) (i32.mul (i32.sub (i32.const 0) (local.get $0) ) (i32.const 0x80000000) ) ) ;; CHECK: (func $11 (type $1) (; has Stack IR ;) (param $0 i32) (result i32) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) (func $11 (export "eliminate-redundant-checks-1") (param $0 i32) (result i32) (if (local.get $0) (then (if (local.get $0) (then (return (local.get $0)) ) ) ) ) (i32.const 0) ) (func $11a (export "eliminate-redundant-checks-1a") (param $0 i32) (result i32) (if (select (local.get $0) (i32.const 0) (local.get $0) ) (then (return (local.get $0)) ) ) (i32.const 0) ) ;; CHECK: (func $12 (type $0) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) (func $12 (export "eliminate-redundant-checks-2") (param $0 i32) (param $1 i32) (result i32) (if (local.tee $1 (local.get $0)) (then (if (local.get $1) (then (return (local.get $1)) ) ) ) ) (i32.const 0) ) (func $12a (export "eliminate-redundant-checks-2a") (param $0 i32) (param $1 i32) (result i32) (if (select (local.tee $1 (local.get $0)) (i32.const 0) (local.get $1) ) (then (return (local.get $1)) ) ) (i32.const 0) ) ;; CHECK: (func $13 (type $0) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (select ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) (func $13 (export "eliminate-redundant-checks-skip-1") (param $0 i32) (param $1 i32) (result i32) (if (select (local.get $1) (i32.const 0) (local.tee $1 (local.get $0)) ) (then (return (local.get $1)) ) ) (i32.const 0) ) ;; CHECK: (func $14 (type $0) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) ;; CHECK-NEXT: (if ;; CHECK-NEXT: (select ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (local.get $1) ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (then ;; CHECK-NEXT: (return ;; CHECK-NEXT: (local.get $0) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) (func $14 (export "eliminate-redundant-checks-skip-2") (param $0 i32) (param $1 i32) (result i32) (if (select (i32.const 0) (local.get $1) (local.tee $1 (local.get $0)) ) (then (return (local.get $1)) ) ) (i32.const 0) ) ;; CHECK: (func $precompute-simd (type $3) (; has Stack IR ;) (result v128) ;; CHECK-NEXT: (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) ;; CHECK-NEXT: ) (func $precompute-simd (export "precompute-simd") (result v128) (i32x4.splat (i32.const 0) ) ) )