diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/help/optimization-opts.test | 5 | ||||
-rw-r--r-- | test/lit/passes/optimize-instructions-gc-iit.wast | 70 | ||||
-rw-r--r-- | test/lit/passes/vacuum-tnh.wast | 74 |
3 files changed, 149 insertions, 0 deletions
diff --git a/test/lit/help/optimization-opts.test b/test/lit/help/optimization-opts.test index d189c6398..52695077a 100644 --- a/test/lit/help/optimization-opts.test +++ b/test/lit/help/optimization-opts.test @@ -161,6 +161,11 @@ ;; CHECK-NEXT: traps occur (from load, div/mod, ;; CHECK-NEXT: etc.) ;; CHECK-NEXT: +;; CHECK-NEXT: --traps-never-happen,-tnh Optimize under the helpful +;; CHECK-NEXT: assumption that no trap is +;; CHECK-NEXT: reached at runtime (from load, +;; CHECK-NEXT: div/mod, etc.) +;; CHECK-NEXT: ;; CHECK-NEXT: --low-memory-unused,-lmu Optimize under the helpful ;; CHECK-NEXT: assumption that the low 1K of ;; CHECK-NEXT: memory is not used by the diff --git a/test/lit/passes/optimize-instructions-gc-iit.wast b/test/lit/passes/optimize-instructions-gc-iit.wast index e30fac8a8..cc1bb3b85 100644 --- a/test/lit/passes/optimize-instructions-gc-iit.wast +++ b/test/lit/passes/optimize-instructions-gc-iit.wast @@ -3,16 +3,22 @@ ;; RUN: | filecheck %s ;; RUN: wasm-opt %s --optimize-instructions --ignore-implicit-traps --enable-reference-types --enable-gc --nominal -S -o - \ ;; RUN: | filecheck %s --check-prefix NOMNL +;; Also test trapsNeverHappen (with nominal; no need for both type system modes). +;; RUN: wasm-opt %s --optimize-instructions --traps-never-happen --enable-reference-types --enable-gc --nominal -S -o - \ +;; RUN: | filecheck %s --check-prefix NOMNL-TNH (module ;; CHECK: (type $parent (struct (field i32))) ;; NOMNL: (type $parent (struct (field i32))) + ;; NOMNL-TNH: (type $parent (struct (field i32))) (type $parent (struct (field i32))) ;; CHECK: (type $child (struct (field i32) (field f64))) ;; NOMNL: (type $child (struct (field i32) (field f64)) (extends $parent)) + ;; NOMNL-TNH: (type $child (struct (field i32) (field f64)) (extends $parent)) (type $child (struct (field i32) (field f64)) (extends $parent)) ;; CHECK: (type $other (struct (field i64) (field f32))) ;; NOMNL: (type $other (struct (field i64) (field f32))) + ;; NOMNL-TNH: (type $other (struct (field i64) (field f32))) (type $other (struct (field i64) (field f32))) ;; CHECK: (func $foo @@ -21,6 +27,9 @@ ;; NOMNL: (func $foo ;; NOMNL-NEXT: (nop) ;; NOMNL-NEXT: ) + ;; NOMNL-TNH: (func $foo + ;; NOMNL-TNH-NEXT: (nop) + ;; NOMNL-TNH-NEXT: ) (func $foo) @@ -84,6 +93,36 @@ ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) + ;; NOMNL-TNH: (func $ref-cast-iit (param $parent (ref $parent)) (param $child (ref $child)) (param $other (ref $other)) (param $parent-rtt (rtt $parent)) (param $child-rtt (rtt $child)) (param $other-rtt (rtt $other)) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (block (result (ref $parent)) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (local.get $parent-rtt) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (local.get $parent) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (block (result (ref $child)) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (local.get $parent-rtt) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (local.get $child) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (ref.cast + ;; NOMNL-TNH-NEXT: (local.get $parent) + ;; NOMNL-TNH-NEXT: (local.get $child-rtt) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (ref.cast + ;; NOMNL-TNH-NEXT: (local.get $child) + ;; NOMNL-TNH-NEXT: (local.get $other-rtt) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) (func $ref-cast-iit (param $parent (ref $parent)) (param $child (ref $child)) @@ -175,6 +214,32 @@ ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) + ;; NOMNL-TNH: (func $ref-cast-iit-bad (param $parent (ref $parent)) (param $parent-rtt (rtt $parent)) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (ref.cast + ;; NOMNL-TNH-NEXT: (block $block (result (ref $parent)) + ;; NOMNL-TNH-NEXT: (call $foo) + ;; NOMNL-TNH-NEXT: (local.get $parent) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (block $block0 (result (rtt $parent)) + ;; NOMNL-TNH-NEXT: (call $foo) + ;; NOMNL-TNH-NEXT: (local.get $parent-rtt) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (ref.cast + ;; NOMNL-TNH-NEXT: (local.get $parent) + ;; NOMNL-TNH-NEXT: (unreachable) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (ref.cast + ;; NOMNL-TNH-NEXT: (unreachable) + ;; NOMNL-TNH-NEXT: (local.get $parent-rtt) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) (func $ref-cast-iit-bad (param $parent (ref $parent)) (param $parent-rtt (rtt $parent)) @@ -218,6 +283,11 @@ ;; NOMNL-NEXT: (i32.const 1) ;; NOMNL-NEXT: ) ;; NOMNL-NEXT: ) + ;; NOMNL-TNH: (func $ref-eq-ref-cast (param $x eqref) + ;; NOMNL-TNH-NEXT: (drop + ;; NOMNL-TNH-NEXT: (i32.const 1) + ;; NOMNL-TNH-NEXT: ) + ;; NOMNL-TNH-NEXT: ) (func $ref-eq-ref-cast (param $x eqref) ;; we can look through a ref.cast if we ignore traps (drop diff --git a/test/lit/passes/vacuum-tnh.wast b/test/lit/passes/vacuum-tnh.wast new file mode 100644 index 000000000..eaa63a4ae --- /dev/null +++ b/test/lit/passes/vacuum-tnh.wast @@ -0,0 +1,74 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. +;; RUN: wasm-opt %s --vacuum --traps-never-happen -all -S -o - | filecheck %s + +(module + (memory 1 1) + + ;; CHECK: (func $drop (param $x i32) (param $y anyref) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $drop (param $x i32) (param $y anyref) + ;; A load might trap, normally, but if traps never happen then we can + ;; remove it. + (drop + (i32.load (local.get $x)) + ) + + ;; A trap on a null value can also be ignored. + (drop + (ref.as_non_null + (local.get $y) + ) + ) + + ;; Ignore unreachable code. + (drop + (unreachable) + ) + ) + + ;; Other side effects prevent us making any changes. + ;; CHECK: (func $other-side-effects (param $x i32) (result i32) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (call $other-side-effects + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (block $block (result i32) + ;; CHECK-NEXT: (local.set $x + ;; CHECK-NEXT: (i32.const 2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.load + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + (func $other-side-effects (param $x i32) (result i32) + ;; A call has all manner of other side effects. + (drop + (call $other-side-effects (i32.const 1)) + ) + + ;; Add to the load an additional specific side effect, of writing to a + ;; local. + (drop + (block (result i32) + (local.set $x (i32.const 2)) + (i32.load (local.get $x)) + ) + ) + + (i32.const 1) + ) + + ;; A helper function for the above, that returns nothing. + ;; CHECK: (func $return-nothing + ;; CHECK-NEXT: (nop) + ;; CHECK-NEXT: ) + (func $return-nothing) +) |