diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/vacuum-tnh.wast | 63 |
1 files changed, 50 insertions, 13 deletions
diff --git a/test/lit/passes/vacuum-tnh.wast b/test/lit/passes/vacuum-tnh.wast index eaa63a4ae..4820a55bc 100644 --- a/test/lit/passes/vacuum-tnh.wast +++ b/test/lit/passes/vacuum-tnh.wast @@ -4,10 +4,11 @@ (module (memory 1 1) + ;; CHECK: (type $struct (struct (field (mut i32)))) + (type $struct (struct (field (mut i32)))) + ;; CHECK: (func $drop (param $x i32) (param $y anyref) - ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (unreachable) - ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) (func $drop (param $x i32) (param $y anyref) ;; A load might trap, normally, but if traps never happen then we can @@ -36,15 +37,8 @@ ;; 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: (local.set $x + ;; CHECK-NEXT: (i32.const 2) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: ) @@ -55,7 +49,7 @@ ) ;; Add to the load an additional specific side effect, of writing to a - ;; local. + ;; local. We can remove the load, but not the write to a local. (drop (block (result i32) (local.set $x (i32.const 2)) @@ -71,4 +65,47 @@ ;; CHECK-NEXT: (nop) ;; CHECK-NEXT: ) (func $return-nothing) + + ;; CHECK: (func $partial (param $x (ref $struct)) + ;; CHECK-NEXT: (local $y (ref null $struct)) + ;; CHECK-NEXT: (local.set $y + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (local.set $y + ;; CHECK-NEXT: (local.get $x) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $partial (param $x (ref $struct)) + (local $y (ref null $struct)) + ;; The struct.get's side effect can be ignored due to tnh, and the value is + ;; dropped anyhow, so we can remove it. We cannot remove the local.tee + ;; inside it, however, so we must only vacuum out the struct.get and + ;; nothing more. (In addition, a drop of a tee will become a set.) + (drop + (struct.get $struct 0 + (local.tee $y + (local.get $x) + ) + ) + ) + ;; Similar, but with an eqz on the outside, which can also be removed. + (drop + (i32.eqz + (struct.get $struct 0 + (local.tee $y + (local.get $x) + ) + ) + ) + ) + ) + + ;; CHECK: (func $toplevel + ;; CHECK-NEXT: (nop) + ;; CHECK-NEXT: ) + (func $toplevel + ;; A removable side effect at the top level of a function. We can turn this + ;; into a nop. + (unreachable) + ) ) |