diff options
Diffstat (limited to 'test/passes')
39 files changed, 6569 insertions, 3073 deletions
diff --git a/test/passes/coalesce-locals-learning.txt b/test/passes/coalesce-locals-learning.txt index 44ad12f53..f5622d097 100644 --- a/test/passes/coalesce-locals-learning.txt +++ b/test/passes/coalesce-locals-learning.txt @@ -5,7 +5,7 @@ (type $2 (func)) (type $3 (func (param i32 f32))) (type $4 (func (param i32))) - (import $_emscripten_autodebug_i32 "env" "_emscripten_autodebug_i32" (param i32 i32) (result i32)) + (import "env" "_emscripten_autodebug_i32" (func $_emscripten_autodebug_i32 (param i32 i32) (result i32))) (func $nothing-to-do (type $2) (local $0 i32) (nop) @@ -28,35 +28,49 @@ (set_local $1 (i32.const 0) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $almost-interfere (type $2) (local $0 i32) (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $redundant-copy (type $2) (local $0 i32) (set_local $0 (i32.const 0) ) - (get_local $0) - (get_local $0) + (nop) + (drop + (get_local $0) + ) ) (func $ineffective-store (type $2) (local $0 i32) - (i32.const 0) + (drop + (i32.const 0) + ) (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $block (type $2) (local $0 i32) @@ -65,7 +79,9 @@ (i32.const 0) ) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $see-both-sides (type $2) (local $0 i32) @@ -78,8 +94,12 @@ (i32.const 0) ) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $see-br-and-ignore-dead (type $2) (local $0 i32) @@ -88,11 +108,19 @@ ) (block $block (br $block) - (i32.const 0) + (drop + (i32.const 0) + ) + (drop + (get_local $0) + ) + (drop + (i32.const -1) + ) + ) + (drop (get_local $0) - (i32.const -1) ) - (get_local $0) ) (func $see-block-body (type $2) (local $0 i32) @@ -104,30 +132,46 @@ (set_local $1 (i32.const 0) ) - (get_local $1) + (drop + (get_local $1) + ) (br $block) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $zero-init (type $2) (local $0 i32) (local $1 i32) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $multi (type $2) (local $0 i32) (local $1 i32) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $if-else (type $2) (local $0 i32) (local $1 i32) (if (i32.const 0) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) (func $if-else-parallel (type $2) @@ -138,13 +182,17 @@ (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) (block $block3 (set_local $0 (i32.const 1) ) - (get_local $0) + (drop + (get_local $0) + ) ) ) ) @@ -160,8 +208,12 @@ (i32.const 1) ) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $if-else-through (type $2) (local $0 i32) @@ -174,11 +226,19 @@ ) (if (i32.const 0) - (i32.const 1) - (i32.const 2) + (drop + (i32.const 1) + ) + (drop + (i32.const 2) + ) + ) + (drop + (get_local $0) + ) + (drop + (get_local $1) ) - (get_local $0) - (get_local $1) ) (func $if-through (type $2) (local $0 i32) @@ -191,10 +251,16 @@ ) (if (i32.const 0) - (i32.const 1) + (drop + (i32.const 1) + ) + ) + (drop + (get_local $0) + ) + (drop + (get_local $1) ) - (get_local $0) - (get_local $1) ) (func $if-through2 (type $2) (local $0 i32) @@ -208,8 +274,12 @@ (i32.const 1) ) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $if-through2 (type $2) (local $0 i32) @@ -220,8 +290,12 @@ (if (i32.const 0) (block $block1 - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -229,12 +303,16 @@ (local $0 i32) (local $1 i32) (if - (set_local $0 + (tee_local $0 (i32.const 0) ) (block $block1 - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -247,10 +325,14 @@ (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) ) - (get_local $1) + (drop + (get_local $1) + ) ) (func $if4 (type $2) (local $0 i32) @@ -260,13 +342,17 @@ (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) (set_local $0 (i32.const 1) ) ) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $if5 (type $2) (local $0 i32) @@ -274,57 +360,85 @@ (if (i32.const 0) (block $block1 - (get_local $0) + (drop + (get_local $0) + ) (set_local $1 (i32.const 1) ) ) ) - (get_local $1) + (drop + (get_local $1) + ) ) (func $loop (type $2) (local $0 i32) (local $1 i32) - (loop $out $in - (get_local $0) - (set_local $0 - (i32.const 0) + (block $out + (loop $in + (drop + (get_local $0) + ) + (set_local $0 + (i32.const 0) + ) + (drop + (get_local $1) + ) + (br $in) ) - (get_local $1) - (br $in) ) ) (func $interfere-in-dead (type $2) (local $0 i32) (block $block (br $block) - (get_local $0) - (get_local $0) + (drop + (get_local $0) + ) + (drop + (get_local $0) + ) ) ) (func $interfere-in-dead2 (type $2) (local $0 i32) (block $block (unreachable) - (get_local $0) - (get_local $0) + (drop + (get_local $0) + ) + (drop + (get_local $0) + ) ) ) (func $interfere-in-dead3 (type $2) (local $0 i32) (block $block (return) - (get_local $0) - (get_local $0) + (drop + (get_local $0) + ) + (drop + (get_local $0) + ) ) ) (func $params (type $3) (param $0 i32) (param $1 f32) (local $2 i32) (local $3 i32) (local $4 i32) - (get_local $2) - (get_local $3) - (get_local $4) + (drop + (get_local $2) + ) + (drop + (get_local $3) + ) + (drop + (get_local $4) + ) ) (func $interfere-in-dead (type $2) (local $0 i32) @@ -333,8 +447,12 @@ (br_if $block (i32.const 0) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) (func $switch (type $2) @@ -347,13 +465,21 @@ (br_table $switch-case$1 $switch-case$2 $switch-case$1 $switch-case$1 $switch$def (i32.const 100) ) + (drop + (get_local $0) + ) + ) + (drop (get_local $0) ) - (get_local $0) ) - (get_local $1) + (drop + (get_local $1) + ) + ) + (drop + (get_local $2) ) - (get_local $2) ) (func $greedy-can-be-happy (type $2) (local $0 i32) @@ -371,8 +497,12 @@ (set_local $1 (i32.const 101) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block5 (set_local $0 @@ -381,8 +511,12 @@ (set_local $1 (i32.const 103) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) (if @@ -394,8 +528,12 @@ (set_local $1 (i32.const 105) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block10 (set_local $0 @@ -404,8 +542,12 @@ (set_local $1 (i32.const 107) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -418,8 +560,12 @@ (set_local $1 (i32.const 109) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block15 (set_local $0 @@ -428,8 +574,12 @@ (set_local $1 (i32.const 111) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -450,8 +600,12 @@ (set_local $1 (i32.const 101) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block5 (set_local $0 @@ -460,8 +614,12 @@ (set_local $1 (i32.const 103) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) (if @@ -473,8 +631,12 @@ (set_local $1 (i32.const 105) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block10 (set_local $0 @@ -483,8 +645,12 @@ (set_local $1 (i32.const 107) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -497,8 +663,12 @@ (set_local $1 (i32.const 109) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block15 (set_local $0 @@ -507,8 +677,12 @@ (set_local $1 (i32.const 111) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -520,7 +694,9 @@ (get_local $2) (i32.const 4096) ) - (get_local $0) + (drop + (get_local $0) + ) ) (set_local $3 (get_local $0) @@ -537,129 +713,135 @@ ) ) (block $block2 - (loop $while-out$0 $while-in$1 - (if - (i32.eqz - (i32.and - (get_local $0) - (i32.const 3) - ) - ) - (br $while-out$0) - ) - (block $block4 + (block $while-out$0 + (loop $while-in$1 (if (i32.eqz - (get_local $2) - ) - (return - (get_local $3) + (i32.and + (get_local $0) + (i32.const 3) + ) ) + (br $while-out$0) ) - (i32.store8 - (get_local $0) - (i32.load8_s - (get_local $1) + (block $block4 + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $3) + ) ) - ) - (set_local $0 - (i32.add + (i32.store8 (get_local $0) - (i32.const 1) + (i32.load8_s + (get_local $1) + ) ) - ) - (set_local $1 - (i32.add - (get_local $1) - (i32.const 1) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 1) + ) ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 1) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 1) + ) ) - ) - ) - (br $while-in$1) - ) - (loop $while-out$2 $while-in$3 - (if - (i32.eqz - (i32.ge_s - (get_local $2) - (i32.const 4) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) ) ) - (br $while-out$2) + (br $while-in$1) ) - (block $block7 - (i32.store - (get_local $0) - (i32.load - (get_local $1) + ) + (block $while-out$2 + (loop $while-in$3 + (if + (i32.eqz + (i32.ge_s + (get_local $2) + (i32.const 4) + ) ) + (br $while-out$2) ) - (set_local $0 - (i32.add + (block $block7 + (i32.store (get_local $0) - (i32.const 4) + (i32.load + (get_local $1) + ) ) - ) - (set_local $1 - (i32.add - (get_local $1) - (i32.const 4) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 4) + ) ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 4) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 4) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 4) + ) ) ) + (br $while-in$3) ) - (br $while-in$3) ) ) ) - (loop $while-out$4 $while-in$5 - (if - (i32.eqz - (i32.gt_s - (get_local $2) - (i32.const 0) - ) - ) - (br $while-out$4) - ) - (block $block9 - (i32.store8 - (get_local $0) - (i32.load8_s - (get_local $1) + (block $while-out$4 + (loop $while-in$5 + (if + (i32.eqz + (i32.gt_s + (get_local $2) + (i32.const 0) + ) ) + (br $while-out$4) ) - (set_local $0 - (i32.add + (block $block9 + (i32.store8 (get_local $0) - (i32.const 1) + (i32.load8_s + (get_local $1) + ) ) - ) - (set_local $1 - (i32.add - (get_local $1) - (i32.const 1) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 1) + ) ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 1) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) ) ) + (br $while-in$5) ) - (br $while-in$5) ) (return (get_local $3) @@ -679,6 +861,8 @@ ) (nop) ) - (get_local $0) + (drop + (get_local $0) + ) ) ) diff --git a/test/passes/coalesce-locals-learning.wast b/test/passes/coalesce-locals-learning.wast index a7152d16a..469a034ba 100644 --- a/test/passes/coalesce-locals-learning.wast +++ b/test/passes/coalesce-locals-learning.wast @@ -1,288 +1,474 @@ (module (memory 10) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $2 (func)) + (type $3 (func (param i32 f32))) + (type $4 (func (param i32))) (import $_emscripten_autodebug_i32 "env" "_emscripten_autodebug_i32" (param i32 i32) (result i32)) - (table) - (func $nothing-to-do + (func $nothing-to-do (type $2) (local $x i32) + (nop) ) - (func $merge + (func $merge (type $2) (local $x i32) (local $y i32) + (nop) ) - (func $leave-type + (func $leave-type (type $2) (local $x i32) (local $y f32) + (nop) ) - (func $leave-interfere + (func $leave-interfere (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 0)) - (get_local $x) - (get_local $y) + (set_local $x + (i32.const 0) + ) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $almost-interfere + (func $almost-interfere (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (get_local $x) - (set_local $y (i32.const 0)) - (get_local $y) + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $y) + ) ) - (func $redundant-copy + (func $redundant-copy (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (get_local $x)) - (get_local $y) + (set_local $x + (i32.const 0) + ) + (set_local $y + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $ineffective-store + (func $ineffective-store (type $2) (local $x i32) - (set_local $x (i32.const 0)) - (set_local $x (i32.const 0)) - (get_local $x) + (set_local $x + (i32.const 0) + ) + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) ) - (func $block + (func $block (type $2) (local $x i32) - (block - (set_local $x (i32.const 0)) + (block $block0 + (set_local $x + (i32.const 0) + ) + ) + (drop + (get_local $x) ) - (get_local $x) ) - (func $see-both-sides + (func $see-both-sides (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (block - (set_local $y (i32.const 0)) + (set_local $x + (i32.const 0) + ) + (block $block0 + (set_local $y + (i32.const 0) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) ) - (get_local $x) - (get_local $y) ) - (func $see-br-and-ignore-dead + (func $see-br-and-ignore-dead (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (block $block (br $block) - (set_local $y (i32.const 0)) - (get_local $y) - (set_local $x (i32.const -1)) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $y) + ) + (set_local $x + (i32.const -1) + ) + ) + (drop + (get_local $x) ) - (get_local $x) ) - (func $see-block-body + (func $see-block-body (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (block $block - (set_local $y (i32.const 0)) - (get_local $y) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $y) + ) (br $block) ) - (get_local $x) + (drop + (get_local $x) + ) ) - (func $zero-init + (func $zero-init (type $2) (local $x i32) (local $y i32) - (get_local $x) - (get_local $y) - ) - (func $multi - (local $x i32) ;; x is free, but y and z conflict - (local $y i32) - (local $z i32) - (get_local $y) - (get_local $z) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $if-else + (func $multi (type $2) (local $x i32) (local $y i32) - (if ;; x and y conflict when they are merged into their shared predecessor - (i32.const 0) - (get_local $x) + (local $z i32) + (drop (get_local $y) ) + (drop + (get_local $z) + ) ) - (func $if-else-parallel + (func $if-else (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (set_local $x (i32.const 0)) + (drop (get_local $x) ) - (block - (set_local $y (i32.const 1)) + (drop (get_local $y) ) ) ) - (func $if-else-after + (func $if-else-parallel (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 1)) + (block $block1 + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) + ) + (block $block3 + (set_local $y + (i32.const 1) + ) + (drop + (get_local $y) + ) + ) ) - (get_local $x) - (get_local $y) ) - (func $if-else-through + (func $if-else-after (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 1)) (if (i32.const 0) - (i32.const 1) - (i32.const 2) + (set_local $x + (i32.const 0) + ) + (set_local $y + (i32.const 1) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) ) - (get_local $x) - (get_local $y) ) - (func $if-through + (func $if-else-through (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 1)) + (set_local $x + (i32.const 0) + ) + (set_local $y + (i32.const 1) + ) (if (i32.const 0) + (drop + (i32.const 1) + ) + (drop + (i32.const 2) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) + ) + (func $if-through (type $2) + (local $x i32) + (local $y i32) + (set_local $x + (i32.const 0) + ) + (set_local $y (i32.const 1) ) - (get_local $x) - (get_local $y) + (if + (i32.const 0) + (drop + (i32.const 1) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $if-through2 + (func $if-through2 (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (if (i32.const 0) - (set_local $y (i32.const 1)) + (set_local $y + (i32.const 1) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) ) - (get_local $x) - (get_local $y) ) - (func $if-through2 + (func $if-through2 (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (if (i32.const 0) - (block - (get_local $x) - (get_local $y) + (block $block1 + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) ) - (func $if2 + (func $if2 (type $2) (local $x i32) (local $y i32) (if - (set_local $x (i32.const 0)) - (block - (get_local $x) - (get_local $y) + (tee_local $x + (i32.const 0) + ) + (block $block1 + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) ) - (func $if3 + (func $if3 (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (set_local $x (i32.const 0)) - (get_local $x) + (block $block1 + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) ) ) - (get_local $y) + (drop + (get_local $y) + ) ) - (func $if4 + (func $if4 (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (set_local $x (i32.const 0)) - (get_local $x) - (set_local $y (i32.const 1)) ;; we might not go through here, but it's ok + (block $block1 + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) + (set_local $y + (i32.const 1) + ) ) ) - (get_local $y) + (drop + (get_local $y) + ) ) - (func $if5 + (func $if5 (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (get_local $x) ;; we might go through here, and it causes interference - (set_local $y (i32.const 1)) + (block $block1 + (drop + (get_local $x) + ) + (set_local $y + (i32.const 1) + ) ) ) - (get_local $y) + (drop + (get_local $y) + ) ) - (func $loop + (func $loop (type $2) (local $x i32) (local $y i32) - (loop $out $in - (get_local $x) - (set_local $x (i32.const 0)) ;; effective, due to looping - (get_local $y) - (br $in) + (block $out + (loop $in + (drop + (get_local $x) + ) + (set_local $x + (i32.const 0) + ) + (drop + (get_local $y) + ) + (br $in) + ) ) ) - (func $interfere-in-dead + (func $interfere-in-dead (type $2) (local $x i32) (local $y i32) (block $block (br $block) - (get_local $x) - (get_local $y) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $interfere-in-dead2 + (func $interfere-in-dead2 (type $2) (local $x i32) (local $y i32) (block $block (unreachable) - (get_local $x) - (get_local $y) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $interfere-in-dead3 + (func $interfere-in-dead3 (type $2) (local $x i32) (local $y i32) (block $block (return) - (get_local $x) - (get_local $y) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $params (param $p i32) (param $q f32) - (local $x i32) ;; x is free, but others conflict + (func $params (type $3) (param $p i32) (param $q f32) + (local $x i32) (local $y i32) (local $z i32) (local $w i32) - (get_local $y) - (get_local $z) - (get_local $w) + (drop + (get_local $y) + ) + (drop + (get_local $z) + ) + (drop + (get_local $w) + ) ) - (func $interfere-in-dead + (func $interfere-in-dead (type $2) (local $x i32) (local $y i32) (block $block - (br_if $block (i32.const 0)) - (get_local $x) - (get_local $y) + (br_if $block + (i32.const 0) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $switch + (func $switch (type $2) (local $x i32) (local $y i32) (local $z i32) @@ -293,15 +479,23 @@ (br_table $switch-case$1 $switch-case$2 $switch-case$1 $switch-case$1 $switch$def (i32.const 100) ) - (get_local $x) ;; unreachable + (drop + (get_local $x) + ) + ) + (drop + (get_local $y) ) - (get_local $y) ) - (get_local $z) + (drop + (get_local $z) + ) + ) + (drop + (get_local $w) ) - (get_local $w) ) - (func $greedy-can-be-happy + (func $greedy-can-be-happy (type $2) (local $x1 i32) (local $x2 i32) (local $x3 i32) @@ -314,53 +508,101 @@ (i32.const 1) (if (i32.const 2) - (block - (set_local $x1 (i32.const 100)) - (set_local $y2 (i32.const 101)) - (get_local $x1) - (get_local $y2) + (block $block3 + (set_local $x1 + (i32.const 100) + ) + (set_local $y2 + (i32.const 101) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y2) + ) ) - (block - (set_local $x1 (i32.const 102)) - (set_local $y3 (i32.const 103)) - (get_local $x1) - (get_local $y3) + (block $block5 + (set_local $x1 + (i32.const 102) + ) + (set_local $y3 + (i32.const 103) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y3) + ) ) ) (if (i32.const 3) - (block - (set_local $x2 (i32.const 104)) - (set_local $y1 (i32.const 105)) - (get_local $x2) - (get_local $y1) + (block $block8 + (set_local $x2 + (i32.const 104) + ) + (set_local $y1 + (i32.const 105) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x2 (i32.const 106)) - (set_local $y3 (i32.const 107)) - (get_local $x2) - (get_local $y3) + (block $block10 + (set_local $x2 + (i32.const 106) + ) + (set_local $y3 + (i32.const 107) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y3) + ) ) ) ) (if (i32.const 4) - (block - (set_local $x3 (i32.const 108)) - (set_local $y1 (i32.const 109)) - (get_local $x3) - (get_local $y1) + (block $block13 + (set_local $x3 + (i32.const 108) + ) + (set_local $y1 + (i32.const 109) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x3 (i32.const 110)) - (set_local $y2 (i32.const 111)) - (get_local $x3) - (get_local $y2) + (block $block15 + (set_local $x3 + (i32.const 110) + ) + (set_local $y2 + (i32.const 111) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y2) + ) ) ) ) ) - (func $greedy-can-be-sad + (func $greedy-can-be-sad (type $2) (local $x1 i32) (local $y1 i32) (local $x2 i32) @@ -373,63 +615,110 @@ (i32.const 1) (if (i32.const 2) - (block - (set_local $x1 (i32.const 100)) - (set_local $y2 (i32.const 101)) - (get_local $x1) - (get_local $y2) + (block $block3 + (set_local $x1 + (i32.const 100) + ) + (set_local $y2 + (i32.const 101) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y2) + ) ) - (block - (set_local $x1 (i32.const 102)) - (set_local $y3 (i32.const 103)) - (get_local $x1) - (get_local $y3) + (block $block5 + (set_local $x1 + (i32.const 102) + ) + (set_local $y3 + (i32.const 103) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y3) + ) ) ) (if (i32.const 3) - (block - (set_local $x2 (i32.const 104)) - (set_local $y1 (i32.const 105)) - (get_local $x2) - (get_local $y1) + (block $block8 + (set_local $x2 + (i32.const 104) + ) + (set_local $y1 + (i32.const 105) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x2 (i32.const 106)) - (set_local $y3 (i32.const 107)) - (get_local $x2) - (get_local $y3) + (block $block10 + (set_local $x2 + (i32.const 106) + ) + (set_local $y3 + (i32.const 107) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y3) + ) ) ) ) (if (i32.const 4) - (block - (set_local $x3 (i32.const 108)) - (set_local $y1 (i32.const 109)) - (get_local $x3) - (get_local $y1) + (block $block13 + (set_local $x3 + (i32.const 108) + ) + (set_local $y1 + (i32.const 109) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x3 (i32.const 110)) - (set_local $y2 (i32.const 111)) - (get_local $x3) - (get_local $y2) + (block $block15 + (set_local $x3 + (i32.const 110) + ) + (set_local $y2 + (i32.const 111) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y2) + ) ) ) ) ) - (func $_memcpy (param $i1 i32) (param $i2 i32) (param $i3 i32) (result i32) + (func $_memcpy (type $FUNCSIG$iiii) (param $i1 i32) (param $i2 i32) (param $i3 i32) (result i32) (local $i4 i32) (if (i32.ge_s (get_local $i3) (i32.const 4096) ) - (get_local $i1) - (get_local $i2) - (get_local $i3) - (return) + (drop + (get_local $i1) + ) ) (set_local $i4 (get_local $i1) @@ -445,150 +734,157 @@ (i32.const 3) ) ) - (block - (loop $while-out$0 $while-in$1 - (if - (i32.eqz - (i32.and - (get_local $i1) - (i32.const 3) - ) - ) - (br $while-out$0) - ) - (block + (block $block2 + (block $while-out$0 + (loop $while-in$1 (if (i32.eqz - (get_local $i3) - ) - (return - (get_local $i4) + (i32.and + (get_local $i1) + (i32.const 3) + ) ) + (br $while-out$0) ) - (i32.store8 - (get_local $i1) - (i32.load8_s - (get_local $i2) + (block $block4 + (if + (i32.eqz + (get_local $i3) + ) + (return + (get_local $i4) + ) ) - ) - (set_local $i1 - (i32.add + (i32.store8 (get_local $i1) - (i32.const 1) + (i32.load8_s + (get_local $i2) + ) ) - ) - (set_local $i2 - (i32.add - (get_local $i2) - (i32.const 1) + (set_local $i1 + (i32.add + (get_local $i1) + (i32.const 1) + ) ) - ) - (set_local $i3 - (i32.sub - (get_local $i3) - (i32.const 1) + (set_local $i2 + (i32.add + (get_local $i2) + (i32.const 1) + ) ) - ) - ) - (br $while-in$1) - ) - (loop $while-out$2 $while-in$3 - (if - (i32.eqz - (i32.ge_s - (get_local $i3) - (i32.const 4) + (set_local $i3 + (i32.sub + (get_local $i3) + (i32.const 1) + ) ) ) - (br $while-out$2) + (br $while-in$1) ) - (block - (i32.store - (get_local $i1) - (i32.load - (get_local $i2) + ) + (block $while-out$2 + (loop $while-in$3 + (if + (i32.eqz + (i32.ge_s + (get_local $i3) + (i32.const 4) + ) ) + (br $while-out$2) ) - (set_local $i1 - (i32.add + (block $block7 + (i32.store (get_local $i1) - (i32.const 4) + (i32.load + (get_local $i2) + ) ) - ) - (set_local $i2 - (i32.add - (get_local $i2) - (i32.const 4) + (set_local $i1 + (i32.add + (get_local $i1) + (i32.const 4) + ) ) - ) - (set_local $i3 - (i32.sub - (get_local $i3) - (i32.const 4) + (set_local $i2 + (i32.add + (get_local $i2) + (i32.const 4) + ) + ) + (set_local $i3 + (i32.sub + (get_local $i3) + (i32.const 4) + ) ) ) + (br $while-in$3) ) - (br $while-in$3) ) ) ) - (loop $while-out$4 $while-in$5 - (if - (i32.eqz - (i32.gt_s - (get_local $i3) - (i32.const 0) - ) - ) - (br $while-out$4) - ) - (block - (i32.store8 - (get_local $i1) - (i32.load8_s - (get_local $i2) + (block $while-out$4 + (loop $while-in$5 + (if + (i32.eqz + (i32.gt_s + (get_local $i3) + (i32.const 0) + ) ) + (br $while-out$4) ) - (set_local $i1 - (i32.add + (block $block9 + (i32.store8 (get_local $i1) - (i32.const 1) + (i32.load8_s + (get_local $i2) + ) ) - ) - (set_local $i2 - (i32.add - (get_local $i2) - (i32.const 1) + (set_local $i1 + (i32.add + (get_local $i1) + (i32.const 1) + ) ) - ) - (set_local $i3 - (i32.sub - (get_local $i3) - (i32.const 1) + (set_local $i2 + (i32.add + (get_local $i2) + (i32.const 1) + ) + ) + (set_local $i3 + (i32.sub + (get_local $i3) + (i32.const 1) + ) ) ) + (br $while-in$5) ) - (br $while-in$5) ) (return (get_local $i4) ) ) - (func $this-is-effective-i-tell-you (param $x i32) + (func $this-is-effective-i-tell-you (type $4) (param $x i32) (if (i32.const -1) - (block - (if ;; this is important for the bug + (block $block1 + (if (i32.const 0) (nop) ) - (set_local $x ;; this set is effective! + (set_local $x (i32.const 1) ) ) - (nop) ;; this is enough for the bug + (nop) + ) + (drop + (get_local $x) ) - (get_local $x) ;; this ends up with the wrong value in the test ) ) - diff --git a/test/passes/coalesce-locals.txt b/test/passes/coalesce-locals.txt index c24cf34e9..3836cfadb 100644 --- a/test/passes/coalesce-locals.txt +++ b/test/passes/coalesce-locals.txt @@ -5,7 +5,7 @@ (type $2 (func)) (type $3 (func (param i32 f32))) (type $4 (func (param i32))) - (import $_emscripten_autodebug_i32 "env" "_emscripten_autodebug_i32" (param i32 i32) (result i32)) + (import "env" "_emscripten_autodebug_i32" (func $_emscripten_autodebug_i32 (param i32 i32) (result i32))) (func $nothing-to-do (type $2) (local $0 i32) (nop) @@ -28,35 +28,49 @@ (set_local $1 (i32.const 0) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $almost-interfere (type $2) (local $0 i32) (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $redundant-copy (type $2) (local $0 i32) (set_local $0 (i32.const 0) ) - (get_local $0) - (get_local $0) + (nop) + (drop + (get_local $0) + ) ) (func $ineffective-store (type $2) (local $0 i32) - (i32.const 0) + (drop + (i32.const 0) + ) (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $block (type $2) (local $0 i32) @@ -65,7 +79,9 @@ (i32.const 0) ) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $see-both-sides (type $2) (local $0 i32) @@ -78,8 +94,12 @@ (i32.const 0) ) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $see-br-and-ignore-dead (type $2) (local $0 i32) @@ -88,11 +108,19 @@ ) (block $block (br $block) - (i32.const 0) + (drop + (i32.const 0) + ) + (drop + (get_local $0) + ) + (drop + (i32.const -1) + ) + ) + (drop (get_local $0) - (i32.const -1) ) - (get_local $0) ) (func $see-block-body (type $2) (local $0 i32) @@ -104,30 +132,46 @@ (set_local $1 (i32.const 0) ) - (get_local $1) + (drop + (get_local $1) + ) (br $block) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $zero-init (type $2) (local $0 i32) (local $1 i32) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $multi (type $2) (local $0 i32) (local $1 i32) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $if-else (type $2) (local $0 i32) (local $1 i32) (if (i32.const 0) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) (func $if-else-parallel (type $2) @@ -138,13 +182,17 @@ (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) (block $block3 (set_local $0 (i32.const 1) ) - (get_local $0) + (drop + (get_local $0) + ) ) ) ) @@ -160,8 +208,12 @@ (i32.const 1) ) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $if-else-through (type $2) (local $0 i32) @@ -174,11 +226,19 @@ ) (if (i32.const 0) - (i32.const 1) - (i32.const 2) + (drop + (i32.const 1) + ) + (drop + (i32.const 2) + ) + ) + (drop + (get_local $0) + ) + (drop + (get_local $1) ) - (get_local $0) - (get_local $1) ) (func $if-through (type $2) (local $0 i32) @@ -191,10 +251,16 @@ ) (if (i32.const 0) - (i32.const 1) + (drop + (i32.const 1) + ) + ) + (drop + (get_local $0) + ) + (drop + (get_local $1) ) - (get_local $0) - (get_local $1) ) (func $if-through2 (type $2) (local $0 i32) @@ -208,8 +274,12 @@ (i32.const 1) ) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $if-through2 (type $2) (local $0 i32) @@ -220,8 +290,12 @@ (if (i32.const 0) (block $block1 - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -229,12 +303,16 @@ (local $0 i32) (local $1 i32) (if - (set_local $0 + (tee_local $0 (i32.const 0) ) (block $block1 - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -247,10 +325,14 @@ (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) ) ) - (get_local $1) + (drop + (get_local $1) + ) ) (func $if4 (type $2) (local $0 i32) @@ -260,13 +342,17 @@ (set_local $0 (i32.const 0) ) - (get_local $0) + (drop + (get_local $0) + ) (set_local $0 (i32.const 1) ) ) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $if5 (type $2) (local $0 i32) @@ -274,23 +360,31 @@ (if (i32.const 0) (block $block1 - (get_local $0) + (drop + (get_local $0) + ) (set_local $1 (i32.const 1) ) ) ) - (get_local $1) + (drop + (get_local $1) + ) ) (func $loop (type $2) (local $0 i32) (local $1 i32) - (loop $out $in - (get_local $0) + (loop $in + (drop + (get_local $0) + ) (set_local $0 (i32.const 0) ) - (get_local $1) + (drop + (get_local $1) + ) (br $in) ) ) @@ -298,33 +392,51 @@ (local $0 i32) (block $block (br $block) - (get_local $0) - (get_local $0) + (drop + (get_local $0) + ) + (drop + (get_local $0) + ) ) ) (func $interfere-in-dead2 (type $2) (local $0 i32) (block $block (unreachable) - (get_local $0) - (get_local $0) + (drop + (get_local $0) + ) + (drop + (get_local $0) + ) ) ) (func $interfere-in-dead3 (type $2) (local $0 i32) (block $block (return) - (get_local $0) - (get_local $0) + (drop + (get_local $0) + ) + (drop + (get_local $0) + ) ) ) (func $params (type $3) (param $0 i32) (param $1 f32) (local $2 i32) (local $3 i32) (local $4 i32) - (get_local $2) - (get_local $3) - (get_local $4) + (drop + (get_local $2) + ) + (drop + (get_local $3) + ) + (drop + (get_local $4) + ) ) (func $interfere-in-dead (type $2) (local $0 i32) @@ -333,8 +445,12 @@ (br_if $block (i32.const 0) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) (func $switch (type $2) @@ -347,13 +463,21 @@ (br_table $switch-case$1 $switch-case$2 $switch-case$1 $switch-case$1 $switch$def (i32.const 100) ) + (drop + (get_local $0) + ) + ) + (drop (get_local $0) ) - (get_local $0) ) - (get_local $1) + (drop + (get_local $1) + ) + ) + (drop + (get_local $2) ) - (get_local $2) ) (func $greedy-can-be-happy (type $2) (local $0 i32) @@ -371,8 +495,12 @@ (set_local $1 (i32.const 101) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block5 (set_local $0 @@ -381,8 +509,12 @@ (set_local $1 (i32.const 103) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) (if @@ -394,8 +526,12 @@ (set_local $1 (i32.const 105) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block10 (set_local $0 @@ -404,8 +540,12 @@ (set_local $1 (i32.const 107) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -418,8 +558,12 @@ (set_local $1 (i32.const 109) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block15 (set_local $0 @@ -428,8 +572,12 @@ (set_local $1 (i32.const 111) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) ) @@ -451,8 +599,12 @@ (set_local $1 (i32.const 101) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (block $block5 (set_local $0 @@ -461,8 +613,12 @@ (set_local $2 (i32.const 103) ) - (get_local $0) - (get_local $2) + (drop + (get_local $0) + ) + (drop + (get_local $2) + ) ) ) (if @@ -474,8 +630,12 @@ (set_local $0 (i32.const 105) ) - (get_local $1) - (get_local $0) + (drop + (get_local $1) + ) + (drop + (get_local $0) + ) ) (block $block10 (set_local $1 @@ -484,8 +644,12 @@ (set_local $2 (i32.const 107) ) - (get_local $1) - (get_local $2) + (drop + (get_local $1) + ) + (drop + (get_local $2) + ) ) ) ) @@ -498,8 +662,12 @@ (set_local $0 (i32.const 109) ) - (get_local $2) - (get_local $0) + (drop + (get_local $2) + ) + (drop + (get_local $0) + ) ) (block $block15 (set_local $2 @@ -508,8 +676,12 @@ (set_local $1 (i32.const 111) ) - (get_local $2) - (get_local $1) + (drop + (get_local $2) + ) + (drop + (get_local $1) + ) ) ) ) @@ -521,7 +693,9 @@ (get_local $2) (i32.const 4096) ) - (get_local $0) + (drop + (get_local $0) + ) ) (set_local $3 (get_local $0) @@ -538,129 +712,135 @@ ) ) (block $block2 - (loop $while-out$0 $while-in$1 - (if - (i32.eqz - (i32.and - (get_local $0) - (i32.const 3) - ) - ) - (br $while-out$0) - ) - (block $block4 + (block $while-out$0 + (loop $while-in$1 (if (i32.eqz - (get_local $2) - ) - (return - (get_local $3) + (i32.and + (get_local $0) + (i32.const 3) + ) ) + (br $while-out$0) ) - (i32.store8 - (get_local $0) - (i32.load8_s - (get_local $1) + (block $block4 + (if + (i32.eqz + (get_local $2) + ) + (return + (get_local $3) + ) ) - ) - (set_local $0 - (i32.add + (i32.store8 (get_local $0) - (i32.const 1) + (i32.load8_s + (get_local $1) + ) ) - ) - (set_local $1 - (i32.add - (get_local $1) - (i32.const 1) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 1) + ) ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 1) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 1) + ) ) - ) - ) - (br $while-in$1) - ) - (loop $while-out$2 $while-in$3 - (if - (i32.eqz - (i32.ge_s - (get_local $2) - (i32.const 4) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) ) ) - (br $while-out$2) + (br $while-in$1) ) - (block $block7 - (i32.store - (get_local $0) - (i32.load - (get_local $1) + ) + (block $while-out$2 + (loop $while-in$3 + (if + (i32.eqz + (i32.ge_s + (get_local $2) + (i32.const 4) + ) ) + (br $while-out$2) ) - (set_local $0 - (i32.add + (block $block7 + (i32.store (get_local $0) - (i32.const 4) + (i32.load + (get_local $1) + ) ) - ) - (set_local $1 - (i32.add - (get_local $1) - (i32.const 4) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 4) + ) ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 4) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 4) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 4) + ) ) ) + (br $while-in$3) ) - (br $while-in$3) ) ) ) - (loop $while-out$4 $while-in$5 - (if - (i32.eqz - (i32.gt_s - (get_local $2) - (i32.const 0) - ) - ) - (br $while-out$4) - ) - (block $block9 - (i32.store8 - (get_local $0) - (i32.load8_s - (get_local $1) + (block $while-out$4 + (loop $while-in$5 + (if + (i32.eqz + (i32.gt_s + (get_local $2) + (i32.const 0) + ) ) + (br $while-out$4) ) - (set_local $0 - (i32.add + (block $block9 + (i32.store8 (get_local $0) - (i32.const 1) + (i32.load8_s + (get_local $1) + ) ) - ) - (set_local $1 - (i32.add - (get_local $1) - (i32.const 1) + (set_local $0 + (i32.add + (get_local $0) + (i32.const 1) + ) ) - ) - (set_local $2 - (i32.sub - (get_local $2) - (i32.const 1) + (set_local $1 + (i32.add + (get_local $1) + (i32.const 1) + ) + ) + (set_local $2 + (i32.sub + (get_local $2) + (i32.const 1) + ) ) ) + (br $while-in$5) ) - (br $while-in$5) ) (return (get_local $3) @@ -680,7 +860,9 @@ ) (nop) ) - (get_local $0) + (drop + (get_local $0) + ) ) (func $prefer-remove-copies1 (type $2) (local $0 i32) @@ -688,12 +870,16 @@ (set_local $0 (i32.const 0) ) - (get_local $0) + (nop) (set_local $1 (i32.const 1) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) (func $prefer-remove-copies1 (type $2) (local $0 i32) @@ -701,11 +887,15 @@ (set_local $1 (i32.const 0) ) - (get_local $1) + (nop) (set_local $0 (i32.const 1) ) - (get_local $0) - (get_local $1) + (drop + (get_local $0) + ) + (drop + (get_local $1) + ) ) ) diff --git a/test/passes/coalesce-locals.wast b/test/passes/coalesce-locals.wast index a7cd6adc1..713fd7dd9 100644 --- a/test/passes/coalesce-locals.wast +++ b/test/passes/coalesce-locals.wast @@ -1,288 +1,472 @@ (module (memory 10) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) + (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $2 (func)) + (type $3 (func (param i32 f32))) + (type $4 (func (param i32))) (import $_emscripten_autodebug_i32 "env" "_emscripten_autodebug_i32" (param i32 i32) (result i32)) - (table) - (func $nothing-to-do + (func $nothing-to-do (type $2) (local $x i32) + (nop) ) - (func $merge + (func $merge (type $2) (local $x i32) (local $y i32) + (nop) ) - (func $leave-type + (func $leave-type (type $2) (local $x i32) (local $y f32) + (nop) ) - (func $leave-interfere + (func $leave-interfere (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 0)) - (get_local $x) - (get_local $y) + (set_local $x + (i32.const 0) + ) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $almost-interfere + (func $almost-interfere (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (get_local $x) - (set_local $y (i32.const 0)) - (get_local $y) + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $y) + ) ) - (func $redundant-copy + (func $redundant-copy (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (get_local $x)) - (get_local $y) + (set_local $x + (i32.const 0) + ) + (set_local $y + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $ineffective-store + (func $ineffective-store (type $2) (local $x i32) - (set_local $x (i32.const 0)) - (set_local $x (i32.const 0)) - (get_local $x) + (set_local $x + (i32.const 0) + ) + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) ) - (func $block + (func $block (type $2) (local $x i32) - (block - (set_local $x (i32.const 0)) + (block $block0 + (set_local $x + (i32.const 0) + ) + ) + (drop + (get_local $x) ) - (get_local $x) ) - (func $see-both-sides + (func $see-both-sides (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (block - (set_local $y (i32.const 0)) + (set_local $x + (i32.const 0) + ) + (block $block0 + (set_local $y + (i32.const 0) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) ) - (get_local $x) - (get_local $y) ) - (func $see-br-and-ignore-dead + (func $see-br-and-ignore-dead (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (block $block (br $block) - (set_local $y (i32.const 0)) - (get_local $y) - (set_local $x (i32.const -1)) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $y) + ) + (set_local $x + (i32.const -1) + ) + ) + (drop + (get_local $x) ) - (get_local $x) ) - (func $see-block-body + (func $see-block-body (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (block $block - (set_local $y (i32.const 0)) - (get_local $y) + (set_local $y + (i32.const 0) + ) + (drop + (get_local $y) + ) (br $block) ) - (get_local $x) + (drop + (get_local $x) + ) ) - (func $zero-init + (func $zero-init (type $2) (local $x i32) (local $y i32) - (get_local $x) - (get_local $y) - ) - (func $multi - (local $x i32) ;; x is free, but y and z conflict - (local $y i32) - (local $z i32) - (get_local $y) - (get_local $z) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $if-else + (func $multi (type $2) (local $x i32) (local $y i32) - (if ;; x and y conflict when they are merged into their shared predecessor - (i32.const 0) - (get_local $x) + (local $z i32) + (drop (get_local $y) ) + (drop + (get_local $z) + ) ) - (func $if-else-parallel + (func $if-else (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (set_local $x (i32.const 0)) + (drop (get_local $x) ) - (block - (set_local $y (i32.const 1)) + (drop (get_local $y) ) ) ) - (func $if-else-after + (func $if-else-parallel (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 1)) + (block $block1 + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) + ) + (block $block3 + (set_local $y + (i32.const 1) + ) + (drop + (get_local $y) + ) + ) ) - (get_local $x) - (get_local $y) ) - (func $if-else-through + (func $if-else-after (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 1)) (if (i32.const 0) - (i32.const 1) - (i32.const 2) + (set_local $x + (i32.const 0) + ) + (set_local $y + (i32.const 1) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) ) - (get_local $x) - (get_local $y) ) - (func $if-through + (func $if-else-through (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) - (set_local $y (i32.const 1)) + (set_local $x + (i32.const 0) + ) + (set_local $y + (i32.const 1) + ) (if (i32.const 0) + (drop + (i32.const 1) + ) + (drop + (i32.const 2) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) + ) + (func $if-through (type $2) + (local $x i32) + (local $y i32) + (set_local $x + (i32.const 0) + ) + (set_local $y (i32.const 1) ) - (get_local $x) - (get_local $y) + (if + (i32.const 0) + (drop + (i32.const 1) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) - (func $if-through2 + (func $if-through2 (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (if (i32.const 0) - (set_local $y (i32.const 1)) + (set_local $y + (i32.const 1) + ) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) ) - (get_local $x) - (get_local $y) ) - (func $if-through2 + (func $if-through2 (type $2) (local $x i32) (local $y i32) - (set_local $x (i32.const 0)) + (set_local $x + (i32.const 0) + ) (if (i32.const 0) - (block - (get_local $x) - (get_local $y) + (block $block1 + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) ) - (func $if2 + (func $if2 (type $2) (local $x i32) (local $y i32) (if - (set_local $x (i32.const 0)) - (block - (get_local $x) - (get_local $y) + (tee_local $x + (i32.const 0) + ) + (block $block1 + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) ) - (func $if3 + (func $if3 (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (set_local $x (i32.const 0)) - (get_local $x) + (block $block1 + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) ) ) - (get_local $y) + (drop + (get_local $y) + ) ) - (func $if4 + (func $if4 (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (set_local $x (i32.const 0)) - (get_local $x) - (set_local $y (i32.const 1)) ;; we might not go through here, but it's ok + (block $block1 + (set_local $x + (i32.const 0) + ) + (drop + (get_local $x) + ) + (set_local $y + (i32.const 1) + ) ) ) - (get_local $y) + (drop + (get_local $y) + ) ) - (func $if5 + (func $if5 (type $2) (local $x i32) (local $y i32) (if (i32.const 0) - (block - (get_local $x) ;; we might go through here, and it causes interference - (set_local $y (i32.const 1)) + (block $block1 + (drop + (get_local $x) + ) + (set_local $y + (i32.const 1) + ) ) ) - (get_local $y) + (drop + (get_local $y) + ) ) - (func $loop + (func $loop (type $2) (local $x i32) (local $y i32) - (loop $out $in - (get_local $x) - (set_local $x (i32.const 0)) ;; effective, due to looping - (get_local $y) + (loop $in + (drop + (get_local $x) + ) + (set_local $x + (i32.const 0) + ) + (drop + (get_local $y) + ) (br $in) ) ) - (func $interfere-in-dead + (func $interfere-in-dead (type $2) (local $x i32) (local $y i32) (block $block (br $block) - (get_local $x) - (get_local $y) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $interfere-in-dead2 + (func $interfere-in-dead2 (type $2) (local $x i32) (local $y i32) (block $block (unreachable) - (get_local $x) - (get_local $y) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $interfere-in-dead3 + (func $interfere-in-dead3 (type $2) (local $x i32) (local $y i32) (block $block (return) - (get_local $x) - (get_local $y) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $params (param $p i32) (param $q f32) - (local $x i32) ;; x is free, but others conflict + (func $params (type $3) (param $p i32) (param $q f32) + (local $x i32) (local $y i32) (local $z i32) (local $w i32) - (get_local $y) - (get_local $z) - (get_local $w) + (drop + (get_local $y) + ) + (drop + (get_local $z) + ) + (drop + (get_local $w) + ) ) - (func $interfere-in-dead + (func $interfere-in-dead (type $2) (local $x i32) (local $y i32) (block $block - (br_if $block (i32.const 0)) - (get_local $x) - (get_local $y) + (br_if $block + (i32.const 0) + ) + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) ) - (func $switch + (func $switch (type $2) (local $x i32) (local $y i32) (local $z i32) @@ -293,15 +477,23 @@ (br_table $switch-case$1 $switch-case$2 $switch-case$1 $switch-case$1 $switch$def (i32.const 100) ) - (get_local $x) ;; unreachable + (drop + (get_local $x) + ) + ) + (drop + (get_local $y) ) - (get_local $y) ) - (get_local $z) + (drop + (get_local $z) + ) + ) + (drop + (get_local $w) ) - (get_local $w) ) - (func $greedy-can-be-happy + (func $greedy-can-be-happy (type $2) (local $x1 i32) (local $x2 i32) (local $x3 i32) @@ -314,53 +506,101 @@ (i32.const 1) (if (i32.const 2) - (block - (set_local $x1 (i32.const 100)) - (set_local $y2 (i32.const 101)) - (get_local $x1) - (get_local $y2) + (block $block3 + (set_local $x1 + (i32.const 100) + ) + (set_local $y2 + (i32.const 101) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y2) + ) ) - (block - (set_local $x1 (i32.const 102)) - (set_local $y3 (i32.const 103)) - (get_local $x1) - (get_local $y3) + (block $block5 + (set_local $x1 + (i32.const 102) + ) + (set_local $y3 + (i32.const 103) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y3) + ) ) ) (if (i32.const 3) - (block - (set_local $x2 (i32.const 104)) - (set_local $y1 (i32.const 105)) - (get_local $x2) - (get_local $y1) + (block $block8 + (set_local $x2 + (i32.const 104) + ) + (set_local $y1 + (i32.const 105) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x2 (i32.const 106)) - (set_local $y3 (i32.const 107)) - (get_local $x2) - (get_local $y3) + (block $block10 + (set_local $x2 + (i32.const 106) + ) + (set_local $y3 + (i32.const 107) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y3) + ) ) ) ) (if (i32.const 4) - (block - (set_local $x3 (i32.const 108)) - (set_local $y1 (i32.const 109)) - (get_local $x3) - (get_local $y1) + (block $block13 + (set_local $x3 + (i32.const 108) + ) + (set_local $y1 + (i32.const 109) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x3 (i32.const 110)) - (set_local $y2 (i32.const 111)) - (get_local $x3) - (get_local $y2) + (block $block15 + (set_local $x3 + (i32.const 110) + ) + (set_local $y2 + (i32.const 111) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y2) + ) ) ) ) ) - (func $greedy-can-be-sad + (func $greedy-can-be-sad (type $2) (local $x1 i32) (local $y1 i32) (local $x2 i32) @@ -373,63 +613,110 @@ (i32.const 1) (if (i32.const 2) - (block - (set_local $x1 (i32.const 100)) - (set_local $y2 (i32.const 101)) - (get_local $x1) - (get_local $y2) + (block $block3 + (set_local $x1 + (i32.const 100) + ) + (set_local $y2 + (i32.const 101) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y2) + ) ) - (block - (set_local $x1 (i32.const 102)) - (set_local $y3 (i32.const 103)) - (get_local $x1) - (get_local $y3) + (block $block5 + (set_local $x1 + (i32.const 102) + ) + (set_local $y3 + (i32.const 103) + ) + (drop + (get_local $x1) + ) + (drop + (get_local $y3) + ) ) ) (if (i32.const 3) - (block - (set_local $x2 (i32.const 104)) - (set_local $y1 (i32.const 105)) - (get_local $x2) - (get_local $y1) + (block $block8 + (set_local $x2 + (i32.const 104) + ) + (set_local $y1 + (i32.const 105) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x2 (i32.const 106)) - (set_local $y3 (i32.const 107)) - (get_local $x2) - (get_local $y3) + (block $block10 + (set_local $x2 + (i32.const 106) + ) + (set_local $y3 + (i32.const 107) + ) + (drop + (get_local $x2) + ) + (drop + (get_local $y3) + ) ) ) ) (if (i32.const 4) - (block - (set_local $x3 (i32.const 108)) - (set_local $y1 (i32.const 109)) - (get_local $x3) - (get_local $y1) + (block $block13 + (set_local $x3 + (i32.const 108) + ) + (set_local $y1 + (i32.const 109) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y1) + ) ) - (block - (set_local $x3 (i32.const 110)) - (set_local $y2 (i32.const 111)) - (get_local $x3) - (get_local $y2) + (block $block15 + (set_local $x3 + (i32.const 110) + ) + (set_local $y2 + (i32.const 111) + ) + (drop + (get_local $x3) + ) + (drop + (get_local $y2) + ) ) ) ) ) - (func $_memcpy (param $i1 i32) (param $i2 i32) (param $i3 i32) (result i32) + (func $_memcpy (type $FUNCSIG$iiii) (param $i1 i32) (param $i2 i32) (param $i3 i32) (result i32) (local $i4 i32) (if (i32.ge_s (get_local $i3) (i32.const 4096) ) - (get_local $i1) - (get_local $i2) - (get_local $i3) - (return) + (drop + (get_local $i1) + ) ) (set_local $i4 (get_local $i1) @@ -445,170 +732,197 @@ (i32.const 3) ) ) - (block - (loop $while-out$0 $while-in$1 - (if - (i32.eqz - (i32.and - (get_local $i1) - (i32.const 3) - ) - ) - (br $while-out$0) - ) - (block + (block $block2 + (block $while-out$0 + (loop $while-in$1 (if (i32.eqz - (get_local $i3) - ) - (return - (get_local $i4) + (i32.and + (get_local $i1) + (i32.const 3) + ) ) + (br $while-out$0) ) - (i32.store8 - (get_local $i1) - (i32.load8_s - (get_local $i2) + (block $block4 + (if + (i32.eqz + (get_local $i3) + ) + (return + (get_local $i4) + ) ) - ) - (set_local $i1 - (i32.add + (i32.store8 (get_local $i1) - (i32.const 1) + (i32.load8_s + (get_local $i2) + ) ) - ) - (set_local $i2 - (i32.add - (get_local $i2) - (i32.const 1) + (set_local $i1 + (i32.add + (get_local $i1) + (i32.const 1) + ) ) - ) - (set_local $i3 - (i32.sub - (get_local $i3) - (i32.const 1) + (set_local $i2 + (i32.add + (get_local $i2) + (i32.const 1) + ) ) - ) - ) - (br $while-in$1) - ) - (loop $while-out$2 $while-in$3 - (if - (i32.eqz - (i32.ge_s - (get_local $i3) - (i32.const 4) + (set_local $i3 + (i32.sub + (get_local $i3) + (i32.const 1) + ) ) ) - (br $while-out$2) + (br $while-in$1) ) - (block - (i32.store - (get_local $i1) - (i32.load - (get_local $i2) + ) + (block $while-out$2 + (loop $while-in$3 + (if + (i32.eqz + (i32.ge_s + (get_local $i3) + (i32.const 4) + ) ) + (br $while-out$2) ) - (set_local $i1 - (i32.add + (block $block7 + (i32.store (get_local $i1) - (i32.const 4) + (i32.load + (get_local $i2) + ) ) - ) - (set_local $i2 - (i32.add - (get_local $i2) - (i32.const 4) + (set_local $i1 + (i32.add + (get_local $i1) + (i32.const 4) + ) ) - ) - (set_local $i3 - (i32.sub - (get_local $i3) - (i32.const 4) + (set_local $i2 + (i32.add + (get_local $i2) + (i32.const 4) + ) + ) + (set_local $i3 + (i32.sub + (get_local $i3) + (i32.const 4) + ) ) ) + (br $while-in$3) ) - (br $while-in$3) ) ) ) - (loop $while-out$4 $while-in$5 - (if - (i32.eqz - (i32.gt_s - (get_local $i3) - (i32.const 0) - ) - ) - (br $while-out$4) - ) - (block - (i32.store8 - (get_local $i1) - (i32.load8_s - (get_local $i2) + (block $while-out$4 + (loop $while-in$5 + (if + (i32.eqz + (i32.gt_s + (get_local $i3) + (i32.const 0) + ) ) + (br $while-out$4) ) - (set_local $i1 - (i32.add + (block $block9 + (i32.store8 (get_local $i1) - (i32.const 1) + (i32.load8_s + (get_local $i2) + ) ) - ) - (set_local $i2 - (i32.add - (get_local $i2) - (i32.const 1) + (set_local $i1 + (i32.add + (get_local $i1) + (i32.const 1) + ) ) - ) - (set_local $i3 - (i32.sub - (get_local $i3) - (i32.const 1) + (set_local $i2 + (i32.add + (get_local $i2) + (i32.const 1) + ) + ) + (set_local $i3 + (i32.sub + (get_local $i3) + (i32.const 1) + ) ) ) + (br $while-in$5) ) - (br $while-in$5) ) (return (get_local $i4) ) ) - (func $this-is-effective-i-tell-you (param $x i32) + (func $this-is-effective-i-tell-you (type $4) (param $x i32) (if (i32.const -1) - (block - (if ;; this is important for the bug + (block $block1 + (if (i32.const 0) (nop) ) - (set_local $x ;; this set is effective! + (set_local $x (i32.const 1) ) ) - (nop) ;; this is enough for the bug + (nop) + ) + (drop + (get_local $x) ) - (get_local $x) ;; this ends up with the wrong value in the test ) - (func $prefer-remove-copies1 + (func $prefer-remove-copies1 (type $2) (local $y i32) (local $z i32) - (local $x i32) ;; y and z interfere, x can be with either, but has a copy which should be prefered - (set_local $x (i32.const 0)) - (set_local $y (get_local $x)) - (set_local $z (i32.const 1)) - (get_local $y) - (get_local $z) - ) - (func $prefer-remove-copies1 + (local $x i32) + (set_local $x + (i32.const 0) + ) + (set_local $y + (get_local $x) + ) + (set_local $z + (i32.const 1) + ) + (drop + (get_local $y) + ) + (drop + (get_local $z) + ) + ) + (func $prefer-remove-copies1 (type $2) (local $y i32) (local $z i32) - (local $x i32) ;; y and z interfere, x can be with either, but has a copy which should be prefered - (set_local $x (i32.const 0)) - (set_local $z (get_local $x)) - (set_local $y (i32.const 1)) - (get_local $y) - (get_local $z) + (local $x i32) + (set_local $x + (i32.const 0) + ) + (set_local $z + (get_local $x) + ) + (set_local $y + (i32.const 1) + ) + (drop + (get_local $y) + ) + (drop + (get_local $z) + ) ) ) - diff --git a/test/passes/dce.txt b/test/passes/dce.txt index 9ae5977b6..6e70cd8de 100644 --- a/test/passes/dce.txt +++ b/test/passes/dce.txt @@ -31,7 +31,9 @@ (br_if $out (i32.const 3) ) - (i32.const 0) + (drop + (i32.const 0) + ) ) (if (i32.const 0) @@ -108,8 +110,12 @@ (if (i32.const 0) (block $block15 - (i32.const 10) - (i32.const 42) + (drop + (i32.const 10) + ) + (drop + (i32.const 42) + ) (unreachable) ) ) @@ -117,16 +123,18 @@ (i32.const 0) (unreachable) ) - (loop $out $in - (br_if $out - (i32.const 1) + (block $out + (loop $in + (br_if $out + (i32.const 1) + ) + (unreachable) ) - (unreachable) ) (if (i32.const 0) (block $block20 - (loop $out $in + (loop $in (br_if $in (i32.const 1) ) @@ -137,7 +145,9 @@ (if (i32.const 1) (block - (i32.const 123) + (drop + (i32.const 123) + ) (unreachable) ) ) @@ -152,22 +162,30 @@ (if (i32.const -1) (block - (i32.const 123) - (i32.const 456) + (drop + (i32.const 123) + ) + (drop + (i32.const 456) + ) (unreachable) ) ) (if (i32.const -2) (block - (i32.const 139) + (drop + (i32.const 139) + ) (unreachable) ) ) (if (i32.const -3) (block - (i32.const 246) + (drop + (i32.const 246) + ) (unreachable) ) ) @@ -181,12 +199,16 @@ ) (if (i32.const 22) - (unreachable) + (drop + (unreachable) + ) ) (if (i32.const 33) (block - (i32.const 0) + (drop + (i32.const 0) + ) (unreachable) ) ) @@ -200,17 +222,25 @@ ) (if (i32.const 66) - (unreachable) + (drop + (unreachable) + ) ) (if (i32.const 77) - (unreachable) + (drop + (unreachable) + ) ) (if (i32.const 88) - (block - (i32.const 0) - (unreachable) + (drop + (block + (drop + (i32.const 0) + ) + (unreachable) + ) ) ) (if @@ -219,29 +249,45 @@ ) (if (i32.const 100) - (block - (i32.const 123) - (i32.const 456) - (unreachable) + (drop + (block + (drop + (i32.const 123) + ) + (drop + (i32.const 456) + ) + (unreachable) + ) ) ) (if (i32.const 101) - (block - (i32.const 123) - (unreachable) + (drop + (block + (drop + (i32.const 123) + ) + (unreachable) + ) ) ) (if (i32.const 102) - (unreachable) + (drop + (unreachable) + ) + ) + (drop + (i32.const 1337) ) - (i32.const 1337) ) (func $killer (type $1) (unreachable) ) (func $target (type $1) - (i32.const 2000) + (drop + (i32.const 2000) + ) ) ) diff --git a/test/passes/dce.wast b/test/passes/dce.wast index dcec20cc1..61b3138e5 100644 --- a/test/passes/dce.wast +++ b/test/passes/dce.wast @@ -1,204 +1,389 @@ (module (memory 10) - (type $ii (func (param i32) (param i32))) + (type $ii (func (param i32 i32))) + (type $1 (func)) (table $call-me) - (func $call-me (param i32) (param i32) + (func $call-me (type $ii) (param $0 i32) (param $1 i32) + (nop) ) - (func $code-to-kill + (func $code-to-kill (type $1) (local $x i32) (block $out - (br $out) ;; kill everything after this - (i32.const 0) - (if (i32.const 1) - (i32.const 2) + (br $out) + (drop + (i32.const 0) + ) + (if + (i32.const 1) + (drop + (i32.const 2) + ) + ) + (br_table $out $out $out $out + (i32.const 3) ) - (br_table $out $out $out $out (i32.const 3)) (call $code-to-kill) ) - (if (i32.const 0) + (if + (i32.const 0) (block $out (unreachable) - (i32.const 0) + (drop + (i32.const 0) + ) ) ) - (if (i32.const 0) + (if + (i32.const 0) (block $out (return) - (i32.const 0) + (drop + (i32.const 0) + ) ) ) (block $out - (br_table $out $out $out $out (i32.const 4)) - (i32.const 0) + (br_table $out $out $out $out + (i32.const 4) + ) + (drop + (i32.const 0) + ) ) (block $out - (br_if $out (i32.const 3)) ;; but not after this - (i32.const 0) + (br_if $out + (i32.const 3) + ) + (drop + (i32.const 0) + ) ) - (if (i32.const 0) - (block - (if (i32.const 0) ;; if that is unreachable both ways + (if + (i32.const 0) + (block $block4 + (if + (i32.const 0) (block $out (unreachable) - (i32.const 0) + (drop + (i32.const 0) + ) ) (block $out (unreachable) - (i32.const 0) + (drop + (i32.const 0) + ) ) ) - (i32.const 0) + (drop + (i32.const 0) + ) ) ) - (if (i32.const 0) + (if + (i32.const 0) (block $out - (br $out (unreachable)) - (i32.const 0) + (br $out + (unreachable) + ) + (drop + (i32.const 0) + ) + (unreachable) ) ) - (if (i32.const 0) + (if + (i32.const 0) (block $out - (br_if $out (unreachable) (i32.const 0)) - (i32.const 0) + (br_if $out + (unreachable) + (i32.const 0) + ) + (drop + (i32.const 0) + ) + (unreachable) ) ) - (if (i32.const 0) + (if + (i32.const 0) (block $out - (br_if $out (unreachable) (unreachable)) - (i32.const 0) + (br_if $out + (unreachable) + (unreachable) + ) + (drop + (i32.const 0) + ) + (unreachable) ) ) (block $out (block $in - (br_if $out (i32.const 1)) + (br_if $out + (i32.const 1) + ) ) (unreachable) ) - (if (i32.const 0) - (block + (if + (i32.const 0) + (block $block11 (block $out (block $in - (br_if $in (i32.const 1)) + (br_if $in + (i32.const 1) + ) ) (unreachable) ) - (i32.const 10) + (drop + (i32.const 10) + ) ) ) (block $out (block $in - (br_table $out $in (i32.const 1)) + (br_table $out $in + (i32.const 1) + ) ) (unreachable) ) (block $out (block $in - (br_table $in $out (i32.const 1)) + (br_table $in $out + (i32.const 1) + ) ) (unreachable) ) - (if (i32.const 0) - (block + (if + (i32.const 0) + (block $block13 (block $out (block $in - (br_table $in $in (i32.const 1)) + (br_table $in $in + (i32.const 1) + ) ) (unreachable) ) - (i32.const 10) + (drop + (i32.const 10) + ) ) ) - (if (i32.const 0) - (block - (i32.const 10) - (i32.const 42) + (if + (i32.const 0) + (block $block15 + (drop + (i32.const 10) + ) + (drop + (i32.const 42) + ) (unreachable) - (return (unreachable)) + (return + (unreachable) + ) (unreachable) (return) ) ) - (if (i32.const 0) - (loop (unreachable)) + (if + (i32.const 0) + (loop $loop-in18 + (unreachable) + ) ) - (loop $out $in - (br_if $out (i32.const 1)) + (block $out + (loop $in + (br_if $out + (i32.const 1) + ) (unreachable) ) - (if (i32.const 0) - (block - (loop $out $in - (br_if $in (i32.const 1)) + ) + (if + (i32.const 0) + (block $block20 + (loop $in + (br_if $in + (i32.const 1) + ) (unreachable) ) - (i32.const 10) + (drop + (i32.const 10) + ) ) ) - (if (i32.const 1) - (call $call-me (i32.const 123) (unreachable)) + (if + (i32.const 1) + (call $call-me + (i32.const 123) + (unreachable) + ) ) - (if (i32.const 2) - (call $call-me (unreachable) (i32.const 0)) + (if + (i32.const 2) + (call $call-me + (unreachable) + (i32.const 0) + ) ) - (if (i32.const 3) - (call $call-me (unreachable) (unreachable)) + (if + (i32.const 3) + (call $call-me + (unreachable) + (unreachable) + ) ) - (if (i32.const -1) - (call_indirect $ii (i32.const 123) (i32.const 456) (unreachable)) + (if + (i32.const -1) + (call_indirect $ii + (i32.const 123) + (i32.const 456) + (unreachable) + ) + ) + (if + (i32.const -2) + (call_indirect $ii + (i32.const 139) + (unreachable) + (i32.const 0) + ) ) - (if (i32.const -2) - (call_indirect $ii (i32.const 139) (unreachable) (i32.const 0)) + (if + (i32.const -3) + (call_indirect $ii + (i32.const 246) + (unreachable) + (unreachable) + ) ) - (if (i32.const -3) - (call_indirect $ii (i32.const 246) (unreachable) (unreachable)) + (if + (i32.const -4) + (call_indirect $ii + (unreachable) + (unreachable) + (unreachable) + ) ) - (if (i32.const -4) - (call_indirect $ii (unreachable) (unreachable) (unreachable)) + (if + (i32.const 11) + (set_local $x + (unreachable) + ) ) - (if (i32.const 11) - (set_local $x (unreachable)) + (if + (i32.const 22) + (drop + (i32.load + (unreachable) + ) + ) ) - (if (i32.const 22) - (i32.load (unreachable)) + (if + (i32.const 33) + (i32.store + (i32.const 0) + (unreachable) + ) ) - (if (i32.const 33) - (i32.store (i32.const 0) (unreachable)) + (if + (i32.const 44) + (i32.store + (unreachable) + (i32.const 0) + ) ) - (if (i32.const 44) - (i32.store (unreachable) (i32.const 0)) + (if + (i32.const 55) + (i32.store + (unreachable) + (unreachable) + ) ) - (if (i32.const 55) - (i32.store (unreachable) (unreachable)) + (if + (i32.const 66) + (drop + (i32.eqz + (unreachable) + ) + ) ) - (if (i32.const 66) - (i32.eqz (unreachable)) + (if + (i32.const 77) + (drop + (i32.add + (unreachable) + (i32.const 0) + ) + ) ) - (if (i32.const 77) - (i32.add (unreachable) (i32.const 0)) + (if + (i32.const 88) + (drop + (i32.add + (i32.const 0) + (unreachable) + ) + ) ) - (if (i32.const 88) - (i32.add (i32.const 0) (unreachable)) + (if + (i32.const 99) + (i32.add + (unreachable) + (unreachable) + ) ) - (if (i32.const 99) - (i32.add (unreachable) (unreachable)) + (if + (i32.const 100) + (drop + (select + (i32.const 123) + (i32.const 456) + (unreachable) + ) + ) ) - (if (i32.const 100) - (select (i32.const 123) (i32.const 456) (unreachable)) + (if + (i32.const 101) + (drop + (select + (i32.const 123) + (unreachable) + (i32.const 456) + ) + ) ) - (if (i32.const 101) - (select (i32.const 123) (unreachable) (i32.const 456)) + (if + (i32.const 102) + (drop + (select + (unreachable) + (i32.const 123) + (i32.const 456) + ) + ) ) - (if (i32.const 102) - (select (unreachable) (i32.const 123) (i32.const 456)) + (drop + (i32.const 1337) ) - (i32.const 1337) ) - (func $killer + (func $killer (type $1) (unreachable) - (i32.const 1000) + (drop + (i32.const 1000) + ) ) - (func $target - (i32.const 2000) + (func $target (type $1) + (drop + (i32.const 2000) + ) ) ) - diff --git a/test/passes/drop-return-values.txt b/test/passes/drop-return-values.txt deleted file mode 100644 index 81ca99327..000000000 --- a/test/passes/drop-return-values.txt +++ /dev/null @@ -1,32 +0,0 @@ -(module - (memory 10) - (type $0 (func)) - (func $0 (type $0) - (local $x i32) - (local $1 i32) - (i32.add - (block - (set_local $x - (i32.const 10) - ) - (get_local $x) - ) - (i32.const 20) - ) - (i32.add - (block - (block - (set_local $1 - (i32.const 40) - ) - (i32.store - (i32.const 30) - (get_local $1) - ) - ) - (get_local $1) - ) - (i32.const 50) - ) - ) -) diff --git a/test/passes/drop-return-values.wast b/test/passes/drop-return-values.wast deleted file mode 100644 index 76463cc8e..000000000 --- a/test/passes/drop-return-values.wast +++ /dev/null @@ -1,9 +0,0 @@ -(module - (memory 10) - (func - (local $x i32) - (i32.add (set_local $x (i32.const 10)) (i32.const 20)) - (i32.add (i32.store (i32.const 30) (i32.const 40)) (i32.const 50)) - ) -) - diff --git a/test/passes/duplicate-function-elimination.txt b/test/passes/duplicate-function-elimination.txt index a7511fc5c..c49f7fd6f 100644 --- a/test/passes/duplicate-function-elimination.txt +++ b/test/passes/duplicate-function-elimination.txt @@ -9,7 +9,9 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other (type $0) (nop) @@ -19,25 +21,31 @@ (memory 0) (type $0 (func)) (func $erase (type $0) - (i32.const 0) + (drop + (i32.const 0) + ) ) ) (module (memory 0) (type $0 (func)) (func $keep2 (type $0) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other (type $0) - (i32.const 1) + (drop + (i32.const 1) + ) ) ) (module (memory 0) (start $keep2) (type $0 (func)) - (export "keep2" $keep2) - (export "other" $keep2) + (export "keep2" (func $keep2)) + (export "other" (func $keep2)) (table 3 3 anyfunc) (elem (i32.const 0) $keep2 $keep2 $caller) (func $keep2 (type $0) @@ -81,10 +89,14 @@ (type $2 (func)) (type $3 (func (param i32))) (func $keep4-similar-but-func-sig-differs (type $2) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other1 (type $3) (param $i i32) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other2 (type $T) (result i32) (i32.const 0) @@ -98,7 +110,9 @@ (type $S (func (result i32))) (type $1 (func (param i32))) (func $keep2-similar-but-func-sig-differs (type $1) (param $i i32) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other2 (type $S) (result i32) (i32.const 0) @@ -199,15 +213,21 @@ (type $0 (func)) (func $keep2 (type $0) (block $foo - (br $foo - (i32.const 0) + (block $block0 + (drop + (i32.const 0) + ) + (br $foo) ) ) ) (func $other (type $0) (block $bar - (br $bar - (i32.const 1) + (block $block0 + (drop + (i32.const 1) + ) + (br $bar) ) ) ) @@ -263,7 +283,7 @@ (memory 0) (type $0 (func)) (func $erase (type $0) - (loop $foo $bar + (loop $bar (nop) ) ) @@ -272,18 +292,22 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (block $foo - (br_table $foo $foo - (i32.const 0) - (i32.const 0) + (drop + (block $foo + (br_table $foo $foo + (i32.const 0) + (i32.const 0) + ) ) ) ) (func $other (type $0) - (block $bar - (br_table $bar $bar - (i32.const 0) - (i32.const 1) + (drop + (block $bar + (br_table $bar $bar + (i32.const 0) + (i32.const 1) + ) ) ) ) @@ -343,8 +367,8 @@ (module (memory 0) (type $FUNCSIG$v (func)) - (import $i "env" "i") - (import $i "env" "j") + (import "env" "i" (func $i)) + (import "env" "j" (func $i)) (func $erase (type $FUNCSIG$v) (call_import $i) ) @@ -352,8 +376,8 @@ (module (memory 0) (type $FUNCSIG$v (func)) - (import $i "env" "i") - (import $j "env" "j") + (import "env" "i" (func $i)) + (import "env" "j" (func $j)) (func $keep2 (type $FUNCSIG$v) (call_import $i) ) @@ -410,7 +434,9 @@ (type $0 (func)) (func $erase-even-locals-with-different-names (type $0) (local $i i32) - (get_local $i) + (drop + (get_local $i) + ) ) ) (module @@ -418,11 +444,15 @@ (type $0 (func)) (func $keep2 (type $0) (local $i i32) - (get_local $i) + (drop + (get_local $i) + ) ) (func $other (type $0) (local $j i64) - (get_local $j) + (drop + (get_local $j) + ) ) ) (module @@ -471,11 +501,15 @@ (memory 10) (type $0 (func)) (func $erase (type $0) - (i32.load - (i32.const 0) + (drop + (i32.load + (i32.const 0) + ) ) - (i32.load8_s offset=3 align=2 - (i32.const 0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) ) ) ) @@ -483,13 +517,17 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.load16_s offset=3 - (i32.const 0) + (drop + (i32.load offset=3 + (i32.const 0) + ) ) ) (func $other (type $0) - (i32.load8_s offset=3 align=2 - (i32.const 0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) ) ) ) @@ -497,13 +535,17 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.load8_s offset=3 - (i32.const 0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) ) ) (func $other (type $0) - (i32.load8_s offset=3 align=2 - (i32.const 0) + (drop + (i32.load16_s offset=3 align=1 + (i32.const 0) + ) ) ) ) @@ -511,13 +553,17 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.load8_s align=2 - (i32.const 0) + (drop + (i32.load16_s + (i32.const 0) + ) ) ) (func $other (type $0) - (i32.load8_s offset=3 align=2 - (i32.const 0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) ) ) ) @@ -525,13 +571,17 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.load8_s offset=3 align=2 - (i32.const 0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) ) ) (func $other (type $0) - (i32.load8_s offset=3 align=2 - (i32.const 1) + (drop + (i32.load16_s offset=3 + (i32.const 1) + ) ) ) ) @@ -539,13 +589,17 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.load8_u offset=3 align=2 - (i32.const 0) + (drop + (i32.load16_u offset=3 + (i32.const 0) + ) ) ) (func $other (type $0) - (i32.load8_s offset=3 align=2 - (i32.const 0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) ) ) ) @@ -557,7 +611,7 @@ (i32.const 0) (i32.const 100) ) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 (i32.const 0) (i32.const 100) ) @@ -567,13 +621,13 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.store16 offset=3 + (i32.store offset=3 (i32.const 0) (i32.const 100) ) ) (func $other (type $0) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 (i32.const 0) (i32.const 100) ) @@ -583,13 +637,13 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.store8 offset=3 + (i32.store16 offset=3 (i32.const 0) (i32.const 100) ) ) (func $other (type $0) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 align=1 (i32.const 0) (i32.const 100) ) @@ -599,13 +653,13 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.store8 align=2 + (i32.store16 (i32.const 0) (i32.const 100) ) ) (func $other (type $0) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 (i32.const 0) (i32.const 100) ) @@ -615,13 +669,13 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 (i32.const 0) (i32.const 100) ) ) (func $other (type $0) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 (i32.const 1) (i32.const 100) ) @@ -631,13 +685,13 @@ (memory 10) (type $0 (func)) (func $keep2 (type $0) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 (i32.const 0) (i32.const 100) ) ) (func $other (type $0) - (i32.store8 offset=3 align=2 + (i32.store16 offset=3 (i32.const 0) (i32.const 101) ) @@ -647,68 +701,94 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other (type $0) - (i64.const 0) + (drop + (i64.const 0) + ) ) ) (module (memory 0) (type $0 (func)) (func $keep2 (type $0) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other (type $0) - (f32.const 0) + (drop + (f32.const 0) + ) ) ) (module (memory 0) (type $0 (func)) (func $keep2 (type $0) - (i32.const 0) + (drop + (i32.const 0) + ) ) (func $other (type $0) - (f64.const 0) + (drop + (f64.const 0) + ) ) ) (module (memory 0) (type $0 (func)) (func $keep2 (type $0) - (i64.const 0) + (drop + (i64.const 0) + ) ) (func $other (type $0) - (i64.const 1) + (drop + (i64.const 1) + ) ) ) (module (memory 0) (type $0 (func)) (func $keep2 (type $0) - (f32.const 0.10000000149011612) + (drop + (f32.const 0.10000000149011612) + ) ) (func $other (type $0) - (f32.const -0.10000000149011612) + (drop + (f32.const -0.10000000149011612) + ) ) ) (module (memory 0) (type $0 (func)) (func $keep2 (type $0) - (f64.const 0.1) + (drop + (f64.const 0.1) + ) ) (func $other (type $0) - (f64.const 0.2) + (drop + (f64.const 0.2) + ) ) ) (module (memory 0) (type $0 (func)) (func $erase (type $0) - (f32.abs - (f32.const 0) + (drop + (f32.abs + (f32.const 0) + ) ) ) ) @@ -716,13 +796,17 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (f32.abs - (f32.const 0) + (drop + (f32.abs + (f32.const 0) + ) ) ) (func $other (type $0) - (f32.abs - (f32.const 1) + (drop + (f32.abs + (f32.const 1) + ) ) ) ) @@ -730,13 +814,17 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (f32.abs - (f32.const 0) + (drop + (f32.abs + (f32.const 0) + ) ) ) (func $other (type $0) - (f32.neg - (f32.const 0) + (drop + (f32.neg + (f32.const 0) + ) ) ) ) @@ -744,9 +832,11 @@ (memory 0) (type $0 (func)) (func $erase (type $0) - (f32.add - (f32.const 0) - (f32.const 0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) ) ) ) @@ -754,15 +844,19 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (f32.add - (f32.const 0) - (f32.const 0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) ) ) (func $other (type $0) - (f32.add - (f32.const 0) - (f32.const 1) + (drop + (f32.add + (f32.const 0) + (f32.const 1) + ) ) ) ) @@ -770,15 +864,19 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (f32.add - (f32.const 0) - (f32.const 0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) ) ) (func $other (type $0) - (f32.add - (f32.const 1) - (f32.const 0) + (drop + (f32.add + (f32.const 1) + (f32.const 0) + ) ) ) ) @@ -786,15 +884,19 @@ (memory 0) (type $0 (func)) (func $keep2 (type $0) - (f32.add - (f32.const 0) - (f32.const 0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) ) ) (func $other (type $0) - (f32.sub - (f32.const 0) - (f32.const 0) + (drop + (f32.sub + (f32.const 0) + (f32.const 0) + ) ) ) ) @@ -802,10 +904,12 @@ (memory 0) (type $0 (func)) (func $erase (type $0) - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) ) ) ) @@ -813,17 +917,21 @@ (memory 0) (type $0 (func)) (func $keep (type $0) - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) ) ) (func $other (type $0) - (select - (i32.const 1) - (i32.const 0) - (i32.const 0) + (drop + (select + (i32.const 1) + (i32.const 0) + (i32.const 0) + ) ) ) ) @@ -831,17 +939,21 @@ (memory 0) (type $0 (func)) (func $keep (type $0) - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) ) ) (func $other (type $0) - (select - (i32.const 0) - (i32.const 2) - (i32.const 0) + (drop + (select + (i32.const 0) + (i32.const 2) + (i32.const 0) + ) ) ) ) @@ -849,17 +961,21 @@ (memory 0) (type $0 (func)) (func $keep (type $0) - (select - (i32.const 0) - (i32.const 0) - (i32.const 0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) ) ) (func $other (type $0) - (select - (i32.const 0) - (i32.const 0) - (i32.const 3) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 3) + ) ) ) ) @@ -897,15 +1013,19 @@ (memory 0) (type $0 (func)) (func $erase (type $0) - (current_memory) + (drop + (current_memory) + ) ) ) (module (memory 0) (type $0 (func)) (func $erase (type $0) - (grow_memory - (i32.const 10) + (drop + (grow_memory + (i32.const 10) + ) ) ) ) @@ -913,13 +1033,17 @@ (memory 0) (type $0 (func)) (func $keep (type $0) - (grow_memory - (i32.const 10) + (drop + (grow_memory + (i32.const 10) + ) ) ) (func $other (type $0) - (grow_memory - (i32.const 11) + (drop + (grow_memory + (i32.const 11) + ) ) ) ) @@ -927,11 +1051,15 @@ (memory 0) (type $0 (func)) (func $keep (type $0) - (current_memory) + (drop + (current_memory) + ) ) (func $other (type $0) - (grow_memory - (i32.const 10) + (drop + (grow_memory + (i32.const 10) + ) ) ) ) diff --git a/test/passes/duplicate-function-elimination.wast b/test/passes/duplicate-function-elimination.wast index 8d1a85cd5..f72ef542e 100644 --- a/test/passes/duplicate-function-elimination.wast +++ b/test/passes/duplicate-function-elimination.wast @@ -1,87 +1,118 @@ (module - (func $erase + (memory 0) + (type $0 (func)) + (func $erase (type $0) (nop) ) - (func $other + (func $other (type $0) (nop) ) ) (module - (func $keep2 - (i32.const 0) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) ) - (func $other + (func $other (type $0) (nop) ) ) (module - (func $erase - (i32.const 0) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (i32.const 0) + ) ) - (func $other - (i32.const 0) + (func $other (type $0) + (drop + (i32.const 0) + ) ) ) (module - (func $keep2 - (i32.const 0) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) ) - (func $other - (i32.const 1) + (func $other (type $0) + (drop + (i32.const 1) + ) ) ) (module + (memory 0) + (start $other) + (type $0 (func)) (export "keep2" $keep2) (export "other" $other) - (start $other) (table $keep2 $other $caller) - (func $keep2 + (func $keep2 (type $0) (nop) ) - (func $other + (func $other (type $0) (nop) ) - (func $caller + (func $caller (type $0) (call $keep2) (call $other) ) ) (module - (func $keep2-after-two-passes + (memory 0) + (type $0 (func)) + (func $keep2-after-two-passes (type $0) (nop) ) - (func $other + (func $other (type $0) (nop) ) - (func $keep-caller + (func $keep-caller (type $0) (call $keep2-after-two-passes) ) - (func $other-caller + (func $other-caller (type $0) (call $other) ) ) (module - (func $keep-4 + (memory 0) + (type $0 (func)) + (func $keep-4 (type $0) (nop) ) - (func $other + (func $other (type $0) (unreachable) ) - (func $keep-caller + (func $keep-caller (type $0) (call $keep-4) ) - (func $other-caller + (func $other-caller (type $0) (call $other) ) ) (module - (type T (func (result i32))) - (type S (func (result i32))) - (func $keep4-similar-but-func-sig-differs - (i32.const 0) + (memory 0) + (type $T (func (result i32))) + (type $S (func (result i32))) + (type $2 (func)) + (type $3 (func (param i32))) + (func $keep4-similar-but-func-sig-differs (type $2) + (drop + (i32.const 0) + ) ) - (func $other1 (param $i i32) - (i32.const 0) + (func $other1 (type $3) (param $i i32) + (drop + (i32.const 0) + ) ) (func $other2 (type $T) (result i32) (i32.const 0) @@ -91,12 +122,18 @@ ) ) (module - (type S (func (result i32))) - (func $keep2-similar-but-func-sig-differs (param $i i32) - (i32.const 0) + (memory 0) + (type $S (func (result i32))) + (type $1 (func (param i32))) + (func $keep2-similar-but-func-sig-differs (type $1) (param $i i32) + (drop + (i32.const 0) + ) ) - (func $other1 (param $i i32) - (i32.const 0) + (func $other1 (type $1) (param $i i32) + (drop + (i32.const 0) + ) ) (func $other2 (type $S) (result i32) (i32.const 0) @@ -105,598 +142,1076 @@ (i32.const 0) ) ) -;; hashing tests for expressions (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (nop) ) - (func $other + (func $other (type $0) (nop) (nop) ) ) (module - (func $erase - (block) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $block0 + ) ) - (func $other - (block) + (func $other (type $0) + (block $block0 + ) ) ) (module - (func $keep2 - (block) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + ) ) - (func $other - (block (nop)) + (func $other (type $0) + (block $block0 + (nop) + ) ) ) (module - (func $erase - (block (nop)) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (block $block0 + (nop) + ) ) - (func $other - (block (nop)) + (func $other (type $0) + (block $block0 + (nop) + ) ) ) (module - (func $keep2 - (block (nop)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + (nop) + ) ) - (func $other - (block (nop) (unreachable)) + (func $other (type $0) + (block $block0 + (nop) + (unreachable) + ) ) ) (module - (func $keep2 - (block (nop)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (block $block0 + (nop) + ) ) - (func $other - (block (unreachable)) + (func $other (type $0) + (block $block0 + (unreachable) + ) ) ) (module - (func $erase-since-block-names-do-not-matter - (block $foo) + (memory 0) + (type $0 (func)) + (func $erase-since-block-names-do-not-matter (type $0) + (block $foo + ) ) - (func $other - (block $bar) + (func $other (type $0) + (block $bar + ) ) ) (module - (func $erase-since-block-names-do-not-matter + (memory 0) + (type $0 (func)) + (func $erase-since-block-names-do-not-matter (type $0) (block $foo (br $foo) - (br_table $foo $foo (i32.const 0)) + (br_table $foo $foo + (i32.const 0) + ) ) ) - (func $other + (func $other (type $0) (block $bar (br $bar) - (br_table $bar $bar (i32.const 0)) + (br_table $bar $bar + (i32.const 0) + ) ) ) ) (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (block $foo - (br $foo (i32.const 0)) + (block + (drop + (i32.const 0) + ) + (br $foo) + ) ) ) - (func $other + (func $other (type $0) (block $bar - (br $bar (i32.const 1)) + (block + (drop + (i32.const 1) + ) + (br $bar) + ) ) ) ) (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (block $foo - (br_if $foo (i32.const 0)) + (br_if $foo + (i32.const 0) + ) ) ) - (func $other + (func $other (type $0) (block $bar - (br_if $bar (i32.const 1)) + (br_if $bar + (i32.const 1) + ) ) ) ) (module - (func $erase + (memory 0) + (type $0 (func)) + (func $erase (type $0) (block $foo - (br_if $foo (i32.const 0)) + (br_if $foo + (i32.const 0) + ) ) ) - (func $other + (func $other (type $0) (block $bar - (br_if $bar (i32.const 0)) + (br_if $bar + (i32.const 0) + ) ) ) ) (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (block $foo - (br_table $foo $foo (i32.const 0)) + (br_table $foo $foo + (i32.const 0) + ) ) ) - (func $other + (func $other (type $0) (block $bar - (br_table $bar $bar (i32.const 1)) + (br_table $bar $bar + (i32.const 1) + ) ) ) ) (module - (func $erase - (loop $foo $bar) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (loop $bar + (nop) + ) ) - (func $other - (loop $sfo $sjc) + (func $other (type $0) + (loop $sjc + (nop) + ) ) ) (module - (func $keep2 - (block $foo - (br_table $foo $foo (i32.const 0) (i32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (block $foo + (br_table $foo $foo + (i32.const 0) + (i32.const 0) + ) + ) ) ) - (func $other - (block $bar - (br_table $bar $bar (i32.const 0) (i32.const 1)) + (func $other (type $0) + (drop + (block $bar + (br_table $bar $bar + (i32.const 0) + (i32.const 1) + ) + ) ) ) ) (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (block $foo (block $bar - (br_table $foo $bar (i32.const 0)) + (br_table $foo $bar + (i32.const 0) + ) ) ) ) - (func $other + (func $other (type $0) (block $bar (block $foo - (br_table $bar $foo (i32.const 0)) + (br_table $bar $foo + (i32.const 0) + ) ) ) ) ) (module - (func $erase + (memory 0) + (type $0 (func)) + (func $erase (type $0) (block $foo (block $bar - (br_table $foo $bar (i32.const 0)) + (br_table $foo $bar + (i32.const 0) + ) ) ) ) - (func $other + (func $other (type $0) (block $bar (block $foo - (br_table $foo $bar (i32.const 0)) + (br_table $foo $bar + (i32.const 0) + ) ) ) ) ) (module - (func $erase + (memory 0) + (type $0 (func)) + (func $erase (type $0) (call $erase) ) - (func $other + (func $other (type $0) (call $erase) ) ) (module - (func $keep2-but-in-theory-we-could-erase ;; TODO FIXME + (memory 0) + (type $0 (func)) + (func $keep2-but-in-theory-we-could-erase (type $0) (call $keep2-but-in-theory-we-could-erase) ) - (func $other + (func $other (type $0) (call $other) ) ) (module + (memory 0) + (type $FUNCSIG$v (func)) (import $i "env" "i") (import $i "env" "j") - (func $erase + (func $erase (type $FUNCSIG$v) (call_import $i) ) - (func $other + (func $other (type $FUNCSIG$v) (call_import $i) ) ) (module + (memory 0) + (type $FUNCSIG$v (func)) (import $i "env" "i") (import $j "env" "j") - (func $keep2 + (func $keep2 (type $FUNCSIG$v) (call_import $i) ) - (func $other + (func $other (type $FUNCSIG$v) (call_import $j) ) ) (module - (type T (func)) + (memory 0) + (type $T (func)) (table $erase $other) - (func $erase - (call_indirect $T (i32.const 0)) + (func $erase (type $T) + (call_indirect $T + (i32.const 0) + ) ) - (func $other - (call_indirect $T (i32.const 0)) + (func $other (type $T) + (call_indirect $T + (i32.const 0) + ) ) ) (module - (type T (func)) + (memory 0) + (type $T (func)) (table $keep2 $other) - (func $keep2 - (call_indirect $T (i32.const 0)) + (func $keep2 (type $T) + (call_indirect $T + (i32.const 0) + ) ) - (func $other - (call_indirect $T (i32.const 1)) + (func $other (type $T) + (call_indirect $T + (i32.const 1) + ) ) ) (module - (type T (func)) - (type S (func)) + (memory 0) + (type $T (func)) + (type $S (func)) (table $keep2 $other) - (func $keep2 - (call_indirect $T (i32.const 0)) + (func $keep2 (type $T) + (call_indirect $T + (i32.const 0) + ) ) - (func $other - (call_indirect $S (i32.const 0)) + (func $other (type $T) + (call_indirect $S + (i32.const 0) + ) ) ) (module - (func $erase-even-locals-with-different-names + (memory 0) + (type $0 (func)) + (func $erase-even-locals-with-different-names (type $0) (local $i i32) - (get_local $i) + (drop + (get_local $i) + ) ) - (func $other + (func $other (type $0) (local $j i32) - (get_local $j) + (drop + (get_local $j) + ) ) ) (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (local $i i32) - (get_local $i) + (drop + (get_local $i) + ) ) - (func $other + (func $other (type $0) (local $j i64) - (get_local $j) + (drop + (get_local $j) + ) ) ) (module - (func $erase-even-locals-with-different-names + (memory 0) + (type $0 (func)) + (func $erase-even-locals-with-different-names (type $0) (local $i i32) - (set_local $i (i32.const 0)) + (set_local $i + (i32.const 0) + ) ) - (func $other + (func $other (type $0) (local $j i32) - (set_local $j (i32.const 0)) + (set_local $j + (i32.const 0) + ) ) ) (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (local $i i32) - (set_local $i (i32.const 0)) + (set_local $i + (i32.const 0) + ) ) - (func $other + (func $other (type $0) (local $j i64) - (set_local $j (i64.const 0)) + (set_local $j + (i64.const 0) + ) ) ) (module - (func $keep2 + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) (local $i i32) - (set_local $i (i32.const 0)) + (set_local $i + (i32.const 0) + ) ) - (func $other + (func $other (type $0) (local $j i32) - (set_local $j (i32.const 1)) + (set_local $j + (i32.const 1) + ) ) ) (module (memory 10) - (func $erase - (i32.load (i32.const 0)) - (i32.load8_s align=2 offset=3 (i32.const 0)) + (type $0 (func)) + (func $erase (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) ) - (func $other - (i32.load (i32.const 0)) - (i32.load8_s align=2 offset=3 (i32.const 0)) + (func $other (type $0) + (drop + (i32.load + (i32.const 0) + ) + ) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) ) ) (module (memory 10) - (func $keep2 - (i32.load16_s align=2 offset=3 (i32.const 0)) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load offset=3 + (i32.const 0) + ) + ) ) - (func $other - (i32.load8_s align=2 offset=3 (i32.const 0)) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) ) ) (module (memory 10) - (func $keep2 - (i32.load8_s offset=3 (i32.const 0)) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s offset=3 + (i32.const 0) + ) + ) ) - (func $other - (i32.load8_s align=2 offset=3 (i32.const 0)) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=1 + (i32.const 0) + ) + ) ) ) (module (memory 10) - (func $keep2 - (i32.load8_s align=2 (i32.const 0)) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s align=2 + (i32.const 0) + ) + ) ) - (func $other - (i32.load8_s align=2 offset=3 (i32.const 0)) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) ) ) (module (memory 10) - (func $keep2 - (i32.load8_s align=2 offset=3 (i32.const 0)) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) ) - (func $other - (i32.load8_s align=2 offset=3 (i32.const 1)) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 1) + ) + ) ) ) (module (memory 10) - (func $keep2 - (i32.load8_u align=2 offset=3 (i32.const 0)) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.load16_u offset=3 align=2 + (i32.const 0) + ) + ) ) - (func $other - (i32.load8_s align=2 offset=3 (i32.const 0)) + (func $other (type $0) + (drop + (i32.load16_s offset=3 align=2 + (i32.const 0) + ) + ) ) ) - (module (memory 10) - (func $erase - (i32.store (i32.const 0) (i32.const 100)) - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 100)) + (type $0 (func)) + (func $erase (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) ) - (func $other - (i32.store (i32.const 0) (i32.const 100)) - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 100)) + (func $other (type $0) + (i32.store + (i32.const 0) + (i32.const 100) + ) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) ) ) (module (memory 10) - (func $keep2 - (i32.store16 align=2 offset=3 (i32.const 0) (i32.const 100)) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store32 offset=3 + (i32.const 0) + (i32.const 100) + ) ) - (func $other - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 100)) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) ) ) (module (memory 10) - (func $keep2 - (i32.store8 offset=3 (i32.const 0) (i32.const 100)) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 + (i32.const 0) + (i32.const 100) + ) ) - (func $other - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 100)) + (func $other (type $0) + (i32.store16 offset=3 align=1 + (i32.const 0) + (i32.const 100) + ) ) ) (module (memory 10) - (func $keep2 - (i32.store8 align=2 (i32.const 0) (i32.const 100)) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 align=2 + (i32.const 0) + (i32.const 100) + ) ) - (func $other - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 100)) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) ) ) (module (memory 10) - (func $keep2 - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 100)) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) ) - (func $other - (i32.store8 align=2 offset=3 (i32.const 1) (i32.const 100)) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 1) + (i32.const 100) + ) ) ) (module (memory 10) - (func $keep2 - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 100)) + (type $0 (func)) + (func $keep2 (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 100) + ) ) - (func $other - (i32.store8 align=2 offset=3 (i32.const 0) (i32.const 101)) + (func $other (type $0) + (i32.store16 offset=3 align=2 + (i32.const 0) + (i32.const 101) + ) ) ) (module - (func $keep2 - (i32.const 0) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) ) - (func $other - (i64.const 0) + (func $other (type $0) + (drop + (i64.const 0) + ) ) ) (module - (func $keep2 - (i32.const 0) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) ) - (func $other - (f32.const 0) + (func $other (type $0) + (drop + (f32.const 0) + ) ) ) (module - (func $keep2 - (i32.const 0) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i32.const 0) + ) ) - (func $other - (f64.const 0) + (func $other (type $0) + (drop + (f64.const 0) + ) ) ) (module - (func $keep2 - (i64.const 0) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (i64.const 0) + ) ) - (func $other - (i64.const 1) + (func $other (type $0) + (drop + (i64.const 1) + ) ) ) (module - (func $keep2 - (f32.const 0.1) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.const 0.10000000149011612) + ) ) - (func $other - (f32.const -0.1) + (func $other (type $0) + (drop + (f32.const -0.10000000149011612) + ) ) ) (module - (func $keep2 - (f64.const 0.1) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f64.const 0.1) + ) ) - (func $other - (f64.const 0.2) + (func $other (type $0) + (drop + (f64.const 0.2) + ) ) ) (module - (func $erase - (f32.abs (f32.const 0)) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) ) - (func $other - (f32.abs (f32.const 0)) + (func $other (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) ) ) (module - (func $keep2 - (f32.abs (f32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) ) - (func $other - (f32.abs (f32.const 1)) + (func $other (type $0) + (drop + (f32.abs + (f32.const 1) + ) + ) ) ) (module - (func $keep2 - (f32.abs (f32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.abs + (f32.const 0) + ) + ) ) - (func $other - (f32.neg (f32.const 0)) + (func $other (type $0) + (drop + (f32.neg + (f32.const 0) + ) + ) ) ) (module - (func $erase - (f32.add (f32.const 0) (f32.const 0)) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) ) - (func $other - (f32.add (f32.const 0) (f32.const 0)) + (func $other (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) ) ) (module - (func $keep2 - (f32.add (f32.const 0) (f32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) ) - (func $other - (f32.add (f32.const 0) (f32.const 1)) + (func $other (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 1) + ) + ) ) ) (module - (func $keep2 - (f32.add (f32.const 0) (f32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) ) - (func $other - (f32.add (f32.const 1) (f32.const 0)) + (func $other (type $0) + (drop + (f32.add + (f32.const 1) + (f32.const 0) + ) + ) ) ) (module - (func $keep2 - (f32.add (f32.const 0) (f32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep2 (type $0) + (drop + (f32.add + (f32.const 0) + (f32.const 0) + ) + ) ) - (func $other - (f32.sub (f32.const 0) (f32.const 0)) + (func $other (type $0) + (drop + (f32.sub + (f32.const 0) + (f32.const 0) + ) + ) ) ) (module - (func $erase - (select (i32.const 0) (i32.const 0) (i32.const 0)) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) ) - (func $other - (select (i32.const 0) (i32.const 0) (i32.const 0)) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) ) ) (module - (func $keep - (select (i32.const 0) (i32.const 0) (i32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) ) - (func $other - (select (i32.const 1) (i32.const 0) (i32.const 0)) + (func $other (type $0) + (drop + (select + (i32.const 1) + (i32.const 0) + (i32.const 0) + ) + ) ) ) (module - (func $keep - (select (i32.const 0) (i32.const 0) (i32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) ) - (func $other - (select (i32.const 0) (i32.const 2) (i32.const 0)) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 2) + (i32.const 0) + ) + ) ) ) (module - (func $keep - (select (i32.const 0) (i32.const 0) (i32.const 0)) + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 0) + ) + ) ) - (func $other - (select (i32.const 0) (i32.const 0) (i32.const 3)) + (func $other (type $0) + (drop + (select + (i32.const 0) + (i32.const 0) + (i32.const 3) + ) + ) ) ) (module - (func $erase + (memory 0) + (type $0 (func)) + (func $erase (type $0) (return) ) - (func $other + (func $other (type $0) (return) ) ) (module - (func $erase (result i32) - (return (i32.const 0)) + (memory 0) + (type $0 (func (result i32))) + (func $erase (type $0) (result i32) + (return + (i32.const 0) + ) ) - (func $other (result i32) - (return (i32.const 0)) + (func $other (type $0) (result i32) + (return + (i32.const 0) + ) ) ) (module - (func $keep (result i32) - (return (i32.const 0)) + (memory 0) + (type $0 (func (result i32))) + (func $keep (type $0) (result i32) + (return + (i32.const 0) + ) ) - (func $other (result i32) - (return (i32.const 1)) + (func $other (type $0) (result i32) + (return + (i32.const 1) + ) ) ) (module - (func $erase - (current_memory) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (current_memory) + ) ) - (func $other - (current_memory) + (func $other (type $0) + (drop + (current_memory) + ) ) ) (module - (func $erase - (grow_memory (i32.const 10)) + (memory 0) + (type $0 (func)) + (func $erase (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) ) - (func $other - (grow_memory (i32.const 10)) + (func $other (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) ) ) (module - (func $keep - (grow_memory (i32.const 10)) + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) ) - (func $other - (grow_memory (i32.const 11)) + (func $other (type $0) + (drop + (grow_memory + (i32.const 11) + ) + ) ) ) (module - (func $keep - (current_memory) + (memory 0) + (type $0 (func)) + (func $keep (type $0) + (drop + (current_memory) + ) ) - (func $other - (grow_memory (i32.const 10)) + (func $other (type $0) + (drop + (grow_memory + (i32.const 10) + ) + ) ) ) - diff --git a/test/passes/lower-if-else.txt b/test/passes/lower-if-else.txt deleted file mode 100644 index 93dd6d916..000000000 --- a/test/passes/lower-if-else.txt +++ /dev/null @@ -1,42 +0,0 @@ -(module - (memory 256 256) - (type $0 (func)) - (func $ifs (type $0) - (block $block0 - (if - (i32.const 0) - (i32.const 1) - ) - (block $L0 - (if - (i32.const 0) - (br $L0 - (i32.const 1) - ) - ) - (i32.const 2) - ) - (block $L1 - (if - (i32.const 4) - (br $L1 - (i32.const 5) - ) - ) - (i32.const 6) - ) - (i32.eq - (block $L2 - (if - (i32.const 4) - (br $L2 - (i32.const 5) - ) - ) - (i32.const 6) - ) - (i32.const 177) - ) - ) - ) -) diff --git a/test/passes/lower-if-else.wast b/test/passes/lower-if-else.wast deleted file mode 100644 index 138a8a206..000000000 --- a/test/passes/lower-if-else.wast +++ /dev/null @@ -1,29 +0,0 @@ -(module - (memory 256 256) - (func $ifs - (block - (if - (i32.const 0) - (i32.const 1) - ) - (if_else - (i32.const 0) - (i32.const 1) - (i32.const 2) - ) - (if_else - (i32.const 4) - (i32.const 5) - (i32.const 6) - ) - (i32.eq - (if_else - (i32.const 4) - (i32.const 5) - (i32.const 6) - ) - (i32.const 177) - ) - ) - ) -) diff --git a/test/passes/metrics.txt b/test/passes/metrics.txt index 97a241c0b..e5024b1af 100644 --- a/test/passes/metrics.txt +++ b/test/passes/metrics.txt @@ -1,10 +1,11 @@ Counts [funcs] : 1 - [total] : 18 + [total] : 24 [vars] : 1 binary : 1 block : 1 const : 12 + drop : 6 if : 4 (module (memory 256 256) @@ -14,25 +15,37 @@ Counts (block $block0 (if (i32.const 0) - (i32.const 1) + (drop + (i32.const 1) + ) ) (if (i32.const 0) - (i32.const 1) - (i32.const 2) + (drop + (i32.const 1) + ) + (drop + (i32.const 2) + ) ) (if (i32.const 4) - (i32.const 5) - (i32.const 6) - ) - (i32.eq - (if - (i32.const 4) + (drop (i32.const 5) + ) + (drop (i32.const 6) ) - (i32.const 177) + ) + (drop + (i32.eq + (if + (i32.const 4) + (i32.const 5) + (i32.const 6) + ) + (i32.const 177) + ) ) ) ) diff --git a/test/passes/metrics.wast b/test/passes/metrics.wast index 67ad1fc5b..c1f278daa 100644 --- a/test/passes/metrics.wast +++ b/test/passes/metrics.wast @@ -1,29 +1,42 @@ (module (memory 256 256) - (func $ifs (param $x i32) + (type $0 (func (param i32))) + (func $ifs (type $0) (param $x i32) (local $y f32) - (block + (block $block0 (if (i32.const 0) - (i32.const 1) + (drop + (i32.const 1) + ) ) - (if_else + (if (i32.const 0) - (i32.const 1) - (i32.const 2) + (drop + (i32.const 1) + ) + (drop + (i32.const 2) + ) ) - (if_else + (if (i32.const 4) - (i32.const 5) - (i32.const 6) - ) - (i32.eq - (if_else - (i32.const 4) + (drop (i32.const 5) + ) + (drop (i32.const 6) ) - (i32.const 177) + ) + (drop + (i32.eq + (if + (i32.const 4) + (i32.const 5) + (i32.const 6) + ) + (i32.const 177) + ) ) ) ) diff --git a/test/passes/nm.txt b/test/passes/nm.txt index 1129a16ad..1b12c5cff 100644 --- a/test/passes/nm.txt +++ b/test/passes/nm.txt @@ -1,6 +1,6 @@ $a : 1 - $b : 4 - $c : 11 + $b : 5 + $c : 13 (module (memory 0) (type $0 (func)) @@ -8,23 +8,29 @@ (nop) ) (func $b (type $0) - (loop $loop-out0 $loop-in1 - (nop) - (i32.const 1000) + (drop + (loop $loop-in1 + (nop) + (i32.const 1000) + ) ) ) (func $c (type $0) (block $top (nop) - (i32.const 1000) - (i32.add - (i32.add - (i32.const 1001) - (i32.const 1002) - ) + (drop + (i32.const 1000) + ) + (drop (i32.add - (i32.const 1003) - (i32.const 1004) + (i32.add + (i32.const 1001) + (i32.const 1002) + ) + (i32.add + (i32.const 1003) + (i32.const 1004) + ) ) ) (br $top) diff --git a/test/passes/nm.wast b/test/passes/nm.wast index 72534e55d..8cea1e648 100644 --- a/test/passes/nm.wast +++ b/test/passes/nm.wast @@ -1,29 +1,36 @@ (module - (func $a + (memory 0) + (type $0 (func)) + (func $a (type $0) (nop) ) - (func $b - (loop - (nop) - (i32.const 1000) + (func $b (type $0) + (drop + (loop $loop-in1 + (nop) + (i32.const 1000) + ) ) ) - (func $c + (func $c (type $0) (block $top (nop) - (i32.const 1000) - (i32.add - (i32.add - (i32.const 1001) - (i32.const 1002) - ) + (drop + (i32.const 1000) + ) + (drop (i32.add - (i32.const 1003) - (i32.const 1004) + (i32.add + (i32.const 1001) + (i32.const 1002) + ) + (i32.add + (i32.const 1003) + (i32.const 1004) + ) ) ) (br $top) ) ) ) - diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt index a25c36a5d..e7af4848e 100644 --- a/test/passes/optimize-instructions.txt +++ b/test/passes/optimize-instructions.txt @@ -6,115 +6,165 @@ (i32.eqz (get_local $i1) ) - (i32.const 10) + (drop + (i32.const 10) + ) ) (if (get_local $i1) - (i32.const 12) - (i32.const 11) + (drop + (i32.const 12) + ) + (drop + (i32.const 11) + ) ) (if (i64.eqz (get_local $i2) ) - (i32.const 11) - (i32.const 12) + (drop + (i32.const 11) + ) + (drop + (i32.const 12) + ) ) - (i32.le_s - (i32.const 1) - (i32.const 2) + (drop + (i32.le_s + (i32.const 1) + (i32.const 2) + ) ) - (i32.lt_s - (i32.const 1) - (i32.const 2) + (drop + (i32.lt_s + (i32.const 1) + (i32.const 2) + ) ) - (i32.ge_s - (i32.const 1) - (i32.const 2) + (drop + (i32.ge_s + (i32.const 1) + (i32.const 2) + ) ) - (i32.gt_s - (i32.const 1) - (i32.const 2) + (drop + (i32.gt_s + (i32.const 1) + (i32.const 2) + ) ) - (i32.le_u - (i32.const 1) - (i32.const 2) + (drop + (i32.le_u + (i32.const 1) + (i32.const 2) + ) ) - (i32.lt_u - (i32.const 1) - (i32.const 2) + (drop + (i32.lt_u + (i32.const 1) + (i32.const 2) + ) ) - (i32.ge_u - (i32.const 1) - (i32.const 2) + (drop + (i32.ge_u + (i32.const 1) + (i32.const 2) + ) ) - (i32.gt_u - (i32.const 1) - (i32.const 2) + (drop + (i32.gt_u + (i32.const 1) + (i32.const 2) + ) ) - (i32.eqz - (f32.gt - (f32.const 1) - (f32.const 2) + (drop + (i32.eqz + (f32.gt + (f32.const 1) + (f32.const 2) + ) ) ) - (i32.eqz - (f32.ge - (f32.const 1) - (f32.const 2) + (drop + (i32.eqz + (f32.ge + (f32.const 1) + (f32.const 2) + ) ) ) - (i32.eqz - (f32.lt - (f32.const 1) - (f32.const 2) + (drop + (i32.eqz + (f32.lt + (f32.const 1) + (f32.const 2) + ) ) ) - (i32.eqz - (f32.le - (f32.const 1) - (f32.const 2) + (drop + (i32.eqz + (f32.le + (f32.const 1) + (f32.const 2) + ) ) ) - (i32.eqz - (f64.gt - (f64.const 1) - (f64.const 2) + (drop + (i32.eqz + (f64.gt + (f64.const 1) + (f64.const 2) + ) ) ) - (i32.eqz - (f64.ge - (f64.const 1) - (f64.const 2) + (drop + (i32.eqz + (f64.ge + (f64.const 1) + (f64.const 2) + ) ) ) - (i32.eqz - (f64.lt - (f64.const 1) - (f64.const 2) + (drop + (i32.eqz + (f64.lt + (f64.const 1) + (f64.const 2) + ) ) ) - (i32.eqz - (f64.le - (f64.const 1) - (f64.const 2) + (drop + (i32.eqz + (f64.le + (f64.const 1) + (f64.const 2) + ) ) ) - (f32.ne - (f32.const 1) - (f32.const 2) + (drop + (f32.ne + (f32.const 1) + (f32.const 2) + ) ) - (f32.eq - (f32.const 1) - (f32.const 2) + (drop + (f32.eq + (f32.const 1) + (f32.const 2) + ) ) - (f64.ne - (f64.const 1) - (f64.const 2) + (drop + (f64.ne + (f64.const 1) + (f64.const 2) + ) ) - (f64.eq - (f64.const 1) - (f64.const 2) + (drop + (f64.eq + (f64.const 1) + (f64.const 2) + ) ) ) ) diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast index bea01bd1c..f06d99fd9 100644 --- a/test/passes/optimize-instructions.wast +++ b/test/passes/optimize-instructions.wast @@ -1,48 +1,196 @@ (module (memory 0) - (func $f (param $i1 i32) (param $i2 i64) + (type $0 (func (param i32 i64))) + (func $f (type $0) (param $i1 i32) (param $i2 i64) (if (i32.eqz (get_local $i1) ) - (i32.const 10) + (drop + (i32.const 10) + ) ) (if (i32.eqz (get_local $i1) ) - (i32.const 11) - (i32.const 12) + (drop + (i32.const 11) + ) + (drop + (i32.const 12) + ) ) (if (i64.eqz (get_local $i2) ) - (i32.const 11) - (i32.const 12) - ) - (i32.eqz (i32.gt_s (i32.const 1) (i32.const 2))) - (i32.eqz (i32.ge_s (i32.const 1) (i32.const 2))) - (i32.eqz (i32.lt_s (i32.const 1) (i32.const 2))) - (i32.eqz (i32.le_s (i32.const 1) (i32.const 2))) - (i32.eqz (i32.gt_u (i32.const 1) (i32.const 2))) - (i32.eqz (i32.ge_u (i32.const 1) (i32.const 2))) - (i32.eqz (i32.lt_u (i32.const 1) (i32.const 2))) - (i32.eqz (i32.le_u (i32.const 1) (i32.const 2))) - - (i32.eqz (f32.gt (f32.const 1) (f32.const 2))) - (i32.eqz (f32.ge (f32.const 1) (f32.const 2))) - (i32.eqz (f32.lt (f32.const 1) (f32.const 2))) - (i32.eqz (f32.le (f32.const 1) (f32.const 2))) - (i32.eqz (f64.gt (f64.const 1) (f64.const 2))) - (i32.eqz (f64.ge (f64.const 1) (f64.const 2))) - (i32.eqz (f64.lt (f64.const 1) (f64.const 2))) - (i32.eqz (f64.le (f64.const 1) (f64.const 2))) - - (i32.eqz (f32.eq (f32.const 1) (f32.const 2))) - (i32.eqz (f32.ne (f32.const 1) (f32.const 2))) - (i32.eqz (f64.eq (f64.const 1) (f64.const 2))) - (i32.eqz (f64.ne (f64.const 1) (f64.const 2))) + (drop + (i32.const 11) + ) + (drop + (i32.const 12) + ) + ) + (drop + (i32.eqz + (i32.gt_s + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (i32.ge_s + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (i32.lt_s + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (i32.le_s + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (i32.gt_u + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (i32.ge_u + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (i32.lt_u + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (i32.le_u + (i32.const 1) + (i32.const 2) + ) + ) + ) + (drop + (i32.eqz + (f32.gt + (f32.const 1) + (f32.const 2) + ) + ) + ) + (drop + (i32.eqz + (f32.ge + (f32.const 1) + (f32.const 2) + ) + ) + ) + (drop + (i32.eqz + (f32.lt + (f32.const 1) + (f32.const 2) + ) + ) + ) + (drop + (i32.eqz + (f32.le + (f32.const 1) + (f32.const 2) + ) + ) + ) + (drop + (i32.eqz + (f64.gt + (f64.const 1) + (f64.const 2) + ) + ) + ) + (drop + (i32.eqz + (f64.ge + (f64.const 1) + (f64.const 2) + ) + ) + ) + (drop + (i32.eqz + (f64.lt + (f64.const 1) + (f64.const 2) + ) + ) + ) + (drop + (i32.eqz + (f64.le + (f64.const 1) + (f64.const 2) + ) + ) + ) + (drop + (i32.eqz + (f32.eq + (f32.const 1) + (f32.const 2) + ) + ) + ) + (drop + (i32.eqz + (f32.ne + (f32.const 1) + (f32.const 2) + ) + ) + ) + (drop + (i32.eqz + (f64.eq + (f64.const 1) + (f64.const 2) + ) + ) + ) + (drop + (i32.eqz + (f64.ne + (f64.const 1) + (f64.const 2) + ) + ) + ) ) ) - diff --git a/test/passes/post-emscripten.txt b/test/passes/post-emscripten.txt index c122b77d5..fd2ada3c1 100644 --- a/test/passes/post-emscripten.txt +++ b/test/passes/post-emscripten.txt @@ -2,29 +2,41 @@ (memory 256 256) (type $0 (func (param i32))) (func $b0 (type $0) (param $x i32) - (i32.load offset=1 - (get_local $x) - ) - (i32.load offset=8 - (get_local $x) - ) - (i32.load offset=1023 - (get_local $x) + (drop + (i32.load offset=1 + (get_local $x) + ) ) - (i32.load - (i32.add + (drop + (i32.load offset=8 (get_local $x) - (i32.const 1024) ) ) - (i32.load - (i32.add + (drop + (i32.load offset=1023 (get_local $x) - (i32.const 2048) ) ) - (i32.load offset=4 - (get_local $x) + (drop + (i32.load + (i32.add + (get_local $x) + (i32.const 1024) + ) + ) + ) + (drop + (i32.load + (i32.add + (get_local $x) + (i32.const 2048) + ) + ) + ) + (drop + (i32.load offset=4 + (get_local $x) + ) ) ) ) diff --git a/test/passes/post-emscripten.wast b/test/passes/post-emscripten.wast index 1da5afd61..b554fea53 100644 --- a/test/passes/post-emscripten.wast +++ b/test/passes/post-emscripten.wast @@ -1,42 +1,54 @@ (module (memory 256 256) - (func $b0 (param $x i32) - (i32.load - (i32.add - (get_local $x) - (i32.const 1) + (type $0 (func (param i32))) + (func $b0 (type $0) (param $x i32) + (drop + (i32.load + (i32.add + (get_local $x) + (i32.const 1) + ) ) ) - (i32.load - (i32.add - (get_local $x) - (i32.const 8) + (drop + (i32.load + (i32.add + (get_local $x) + (i32.const 8) + ) ) ) - (i32.load - (i32.add - (get_local $x) - (i32.const 1023) + (drop + (i32.load + (i32.add + (get_local $x) + (i32.const 1023) + ) ) ) - (i32.load - (i32.add - (get_local $x) - (i32.const 1024) + (drop + (i32.load + (i32.add + (get_local $x) + (i32.const 1024) + ) ) ) - (i32.load - (i32.add - (get_local $x) - (i32.const 2048) + (drop + (i32.load + (i32.add + (get_local $x) + (i32.const 2048) + ) ) ) - (i32.load - (i32.add - (i32.const 4) - (get_local $x) + (drop + (i32.load + (i32.add + (i32.const 4) + (get_local $x) + ) ) ) ) ) - diff --git a/test/passes/precompute.txt b/test/passes/precompute.txt index a3e8623f5..9825594b6 100644 --- a/test/passes/precompute.txt +++ b/test/passes/precompute.txt @@ -2,15 +2,25 @@ (memory 0) (type $0 (func (param i32))) (func $x (type $0) (param $x i32) - (i32.const 3) - (i32.add - (i32.const 1) - (get_local $x) + (drop + (i32.const 3) ) - (i32.const 6) - (i32.const -1) - (i32.const 3) - (loop $loop-out0 $in + (drop + (i32.add + (i32.const 1) + (get_local $x) + ) + ) + (drop + (i32.const 6) + ) + (drop + (i32.const -1) + ) + (drop + (i32.const 3) + ) + (loop $in (br $in) ) ) diff --git a/test/passes/precompute.wast b/test/passes/precompute.wast index 0282ac61b..808485a34 100644 --- a/test/passes/precompute.wast +++ b/test/passes/precompute.wast @@ -1,19 +1,45 @@ (module - (func $x (param $x i32) - (i32.add (i32.const 1) (i32.const 2)) ;; precomputable - (i32.add (i32.const 1) (get_local $x)) - (i32.add (i32.const 1) (i32.add (i32.const 2) (i32.const 3))) ;; cascade - (i32.sub (i32.const 1) (i32.const 2)) - (i32.sub + (memory 0) + (type $0 (func (param i32))) + (func $x (type $0) (param $x i32) + (drop (i32.add - (i32.const 0) - (i32.const 4) + (i32.const 1) + (i32.const 2) ) - (i32.const 1) ) - (loop $in ;; infinite loop + (drop + (i32.add + (i32.const 1) + (get_local $x) + ) + ) + (drop + (i32.add + (i32.const 1) + (i32.add + (i32.const 2) + (i32.const 3) + ) + ) + ) + (drop + (i32.sub + (i32.const 1) + (i32.const 2) + ) + ) + (drop + (i32.sub + (i32.add + (i32.const 0) + (i32.const 4) + ) + (i32.const 1) + ) + ) + (loop $in (br $in) ) ) ) - diff --git a/test/passes/remove-imports.txt b/test/passes/remove-imports.txt index a285ef0eb..b8d45e8eb 100644 --- a/test/passes/remove-imports.txt +++ b/test/passes/remove-imports.txt @@ -5,7 +5,11 @@ (type $FUNCSIG$d (func (result f64))) (func $nada (type $FUNCSIG$v) (nop) - (i32.const 0) - (f64.const 0) + (drop + (i32.const 0) + ) + (drop + (f64.const 0) + ) ) ) diff --git a/test/passes/remove-imports.wast b/test/passes/remove-imports.wast index 00190a32d..babd60fdc 100644 --- a/test/passes/remove-imports.wast +++ b/test/passes/remove-imports.wast @@ -1,11 +1,18 @@ (module (memory 1024 1024) + (type $FUNCSIG$v (func)) + (type $FUNCSIG$i (func (result i32))) + (type $FUNCSIG$d (func (result f64))) (import $waka "somewhere" "waka") (import $waka-ret "somewhere" "waka-ret" (result i32)) (import $waka-ret-d "somewhere" "waka-ret-d" (result f64)) - (func $nada + (func $nada (type $FUNCSIG$v) (call_import $waka) - (call_import $waka-ret) - (call_import $waka-ret-d) + (drop + (call_import $waka-ret) + ) + (drop + (call_import $waka-ret-d) + ) ) ) diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index 4290d9e05..1c5c8e713 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -9,7 +9,11 @@ ) (func $b1 (type $0) (param $i1 i32) (block $topmost - (i32.const 0) + (block $block0 + (drop + (i32.const 0) + ) + ) ) ) (func $b2 (type $0) (param $i1 i32) @@ -27,14 +31,22 @@ (func $b4 (type $0) (param $i1 i32) (block $topmost (block $inner - (i32.const 0) + (block $block0 + (drop + (i32.const 0) + ) + ) ) ) ) (func $b5 (type $0) (param $i1 i32) (block $topmost (block $inner - (i32.const 0) + (block $block0 + (drop + (i32.const 0) + ) + ) ) ) ) @@ -47,9 +59,13 @@ ) (func $b7 (type $0) (param $i1 i32) (block $topmost - (br_if $topmost - (i32.const 0) - (i32.const 1) + (block $block0 + (drop + (i32.const 0) + ) + (br_if $topmost + (i32.const 1) + ) ) ) ) @@ -74,9 +90,13 @@ (func $b10 (type $0) (param $i1 i32) (block $topmost (block $inner - (br_if $topmost - (i32.const 0) - (i32.const 1) + (block $block0 + (drop + (i32.const 0) + ) + (br_if $topmost + (i32.const 1) + ) ) ) ) @@ -84,25 +104,41 @@ (func $b11 (type $0) (param $i1 i32) (block $topmost (block $inner - (br_if $inner - (i32.const 0) - (i32.const 1) + (block $block0 + (drop + (i32.const 0) + ) + (br_if $inner + (i32.const 1) + ) ) ) ) ) (func $b12-yes (type $1) (block $topmost - (select + (if + (i32.const 1) (block $block1 - (i32.const 12) - (i32.const 1) + (drop + (i32.const 12) + ) + (block $block2 + (drop + (i32.const 1) + ) + ) ) (block $block3 - (i32.const 27) - (i32.const 2) + (drop + (i32.const 27) + ) + (block $block4 + (drop + (i32.const 2) + ) + ) ) - (i32.const 1) ) ) ) @@ -111,14 +147,18 @@ (if (i32.const 1) (block $block1 - (i32.const 12) + (drop + (i32.const 12) + ) (br_if $topmost (i32.const 1) (i32.const 1) ) ) (block $block3 - (i32.const 27) + (drop + (i32.const 27) + ) (br $topmost (i32.const 2) ) @@ -149,9 +189,13 @@ ) (func $b15 (type $1) (block $topmost - (br_if $topmost - (i32.const 0) + (if (i32.const 18) + (block $block1 + (drop + (i32.const 0) + ) + ) ) ) ) @@ -177,38 +221,42 @@ ) (func $b17 (type $1) (block $a - (select + (if + (i32.const 0) (block $block1 ) (block $block3 ) - (i32.const 0) ) ) (block $a - (select - (i32.const 1) + (if + (i32.const 0) + (drop + (i32.const 1) + ) (block $block6 ) - (i32.const 0) ) ) (block $a - (select + (if + (i32.const 0) (block $block8 ) - (i32.const 1) - (i32.const 0) + (drop + (i32.const 1) + ) ) ) (block $c (block $b - (select + (if + (i32.const 0) (block $block11 ) (block $block13 ) - (i32.const 0) ) ) ) @@ -224,11 +272,11 @@ ) (func $ret-3 (type $1) (block $block0 - (select + (if + (i32.const 0) (nop) (block $block3 ) - (i32.const 0) ) ) ) @@ -243,43 +291,72 @@ (block $a (if (i32.const 0) - (i32.const 1) + (drop + (i32.const 1) + ) (block $block2 - (br $a - (i32.const 2) + (block $block3 + (drop + (i32.const 2) + ) + (br $a) + ) + (drop + (i32.const 3) ) - (i32.const 3) ) ) (if (i32.const 0) (block $block4 - (br $a - (i32.const 2) + (block $block5 + (drop + (i32.const 2) + ) + (br $a) + ) + (drop + (i32.const 3) ) - (i32.const 3) ) - (i32.const 1) + (drop + (i32.const 1) + ) ) (if (block $block6 - (br $a - (i32.const 2) + (block $block7 + (drop + (i32.const 2) + ) + (br $a) ) (i32.const 3) ) - (i32.const 0) - (i32.const 1) + (drop + (i32.const 0) + ) + (drop + (i32.const 1) + ) ) - (select + (if (block $a - (i32.const 1) + (i32.const 0) ) (block $a - (i32.const 2) + (block $block11 + (drop + (i32.const 1) + ) + ) ) (block $a - (i32.const 0) + (block $block13 + (drop + (i32.const 2) + ) + ) ) ) ) @@ -287,37 +364,54 @@ (func $side-effects-and-order (type $2) (result i32) (local $x i32) (block $do-once$0 - (br_if $do-once$0 - (i32.const 0) + (if (call $b13) + (block $block1 + (drop + (i32.const 0) + ) + (br $do-once$0) + ) + ) + (drop + (i32.const 1) ) - (i32.const 1) ) (block $do-once$0 (if (call $b13) - (br $do-once$0 - (call $b14) + (block $block3 + (drop + (call $b14) + ) + (br $do-once$0) ) ) - (i32.const 1) + (drop + (i32.const 1) + ) ) (block $do-once$0 (if (i32.const 0) - (br $do-once$0 - (call $b14) + (block $block5 + (drop + (call $b14) + ) + (br $do-once$0) ) ) - (i32.const 1) + (drop + (i32.const 1) + ) ) (block $do-once$0 (if - (set_local $x + (tee_local $x (i32.const 1) ) (br $do-once$0 - (set_local $x + (tee_local $x (i32.const 2) ) ) diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index b7dc1cc25..f3d20f5e0 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -1,126 +1,172 @@ (module (memory 256 256) - (func $b0-yes (param $i1 i32) + (type $0 (func (param i32))) + (type $1 (func)) + (type $2 (func (result i32))) + (func $b0-yes (type $0) (param $i1 i32) (block $topmost (br $topmost) ) ) - (func $b1 (param $i1 i32) + (func $b1 (type $0) (param $i1 i32) (block $topmost - (br $topmost - (i32.const 0) + (block + (drop + (i32.const 0) + ) + (br $topmost) ) ) ) - (func $b2 (param $i1 i32) + (func $b2 (type $0) (param $i1 i32) (block $topmost (block $inner (br $topmost) ) ) ) - (func $b3-yes (param $i1 i32) + (func $b3-yes (type $0) (param $i1 i32) (block $topmost (block $inner (br $inner) ) ) ) - (func $b4 (param $i1 i32) + (func $b4 (type $0) (param $i1 i32) (block $topmost (block $inner - (br $topmost - (i32.const 0) + (block + (drop + (i32.const 0) + ) + (br $topmost) ) ) ) ) - (func $b5 (param $i1 i32) + (func $b5 (type $0) (param $i1 i32) (block $topmost (block $inner - (br $inner - (i32.const 0) + (block + (drop + (i32.const 0) + ) + (br $inner) ) ) ) ) - (func $b6 (param $i1 i32) - (block $topmost - (br_if $topmost (i32.const 1)) - ) - ) - (func $b7 (param $i1 i32) + (func $b6 (type $0) (param $i1 i32) (block $topmost (br_if $topmost - (i32.const 0) (i32.const 1) ) ) ) - (func $b8 (param $i1 i32) + (func $b7 (type $0) (param $i1 i32) (block $topmost - (block $inner - (br_if $topmost (i32.const 1)) + (block + (drop + (i32.const 0) + ) + (br_if $topmost + (i32.const 1) + ) ) ) ) - (func $b9 (param $i1 i32) + (func $b8 (type $0) (param $i1 i32) (block $topmost (block $inner - (br_if $topmost (i32.const 1)) + (br_if $topmost + (i32.const 1) + ) ) ) ) - (func $b10 (param $i1 i32) + (func $b9 (type $0) (param $i1 i32) (block $topmost (block $inner (br_if $topmost - (i32.const 0) (i32.const 1) ) ) ) ) - (func $b11 (param $i1 i32) + (func $b10 (type $0) (param $i1 i32) (block $topmost (block $inner - (br_if $inner - (i32.const 0) - (i32.const 1) + (block + (drop + (i32.const 0) + ) + (br_if $topmost + (i32.const 1) + ) ) ) ) ) - (func $b12-yes + (func $b11 (type $0) (param $i1 i32) (block $topmost - (if_else (i32.const 1) + (block $inner (block - (i32.const 12) - (br $topmost + (drop + (i32.const 0) + ) + (br_if $inner (i32.const 1) ) ) - (block - (i32.const 27) - (br $topmost - (i32.const 2) + ) + ) + ) + (func $b12-yes (type $1) + (block $topmost + (if + (i32.const 1) + (block $block1 + (drop + (i32.const 12) + ) + (block + (drop + (i32.const 1) + ) + (br $topmost) + ) + ) + (block $block3 + (drop + (i32.const 27) + ) + (block + (drop + (i32.const 2) + ) + (br $topmost) ) ) ) ) ) - (func $b13 (result i32) + (func $b13 (type $2) (result i32) (block $topmost - (if_else (i32.const 1) - (block - (i32.const 12) + (if + (i32.const 1) + (block $block1 + (drop + (i32.const 12) + ) (br_if $topmost (i32.const 1) (i32.const 1) ) ) - (block - (i32.const 27) + (block $block3 + (drop + (i32.const 27) + ) (br $topmost (i32.const 2) ) @@ -129,19 +175,20 @@ (i32.const 3) ) ) - (func $b14 (result i32) + (func $b14 (type $2) (result i32) (block $topmost - (if_else (i32.const 1) - (block + (if + (i32.const 1) + (block $block1 (i32.const 12) ) - (block + (block $block3 (i32.const 27) ) ) ) ) - (func $b15 + (func $b15 (type $1) (block $topmost (if (i32.const 17) @@ -149,15 +196,20 @@ ) ) ) - (func $b15 + (func $b15 (type $1) (block $topmost (if (i32.const 18) - (br $topmost (i32.const 0)) + (block + (drop + (i32.const 0) + ) + (br $topmost) + ) ) ) ) - (func $b16 + (func $b16 (type $1) (block $a (block $b (block $c @@ -186,14 +238,14 @@ (br $a) ) ) - (func $b17 + (func $b17 (type $1) (block $a (if (i32.const 0) - (block + (block $block1 (br $a) ) - (block + (block $block3 (br $a) ) ) @@ -201,8 +253,10 @@ (block $a (if (i32.const 0) - (i32.const 1) - (block + (drop + (i32.const 1) + ) + (block $block6 (br $a) ) ) @@ -210,131 +264,192 @@ (block $a (if (i32.const 0) - (block + (block $block8 (br $a) ) - (i32.const 1) + (drop + (i32.const 1) + ) ) ) (block $c (block $b (if (i32.const 0) - (block + (block $block11 (br $b) ) - (block + (block $block13 (br $c) ) ) ) ) ) - (func $ret-1 + (func $ret-1 (type $1) (return) ) - (func $ret-2 - (block - (block + (func $ret-2 (type $1) + (block $block0 + (block $block1 (return) ) ) ) - (func $ret-3 - (block + (func $ret-3 (type $1) + (block $block0 (if (i32.const 0) (return) - (block + (block $block3 (return) ) ) ) ) - (func $ret-value (result i32) - (block - (block - (return (i32.const 1)) + (func $ret-value (type $2) (result i32) + (block $block0 + (block $block1 + (return + (i32.const 1) + ) ) ) ) - (func $no-select-but-the-last + (func $no-select-but-the-last (type $1) (block $a (if (i32.const 0) - (i32.const 1) - (block - (br $a (i32.const 2)) - (i32.const 3) + (drop + (i32.const 1) + ) + (block $block2 + (block + (drop + (i32.const 2) + ) + (br $a) + ) + (drop + (i32.const 3) + ) ) ) (if (i32.const 0) - (block - (br $a (i32.const 2)) - (i32.const 3) + (block $block4 + (block + (drop + (i32.const 2) + ) + (br $a) + ) + (drop + (i32.const 3) + ) + ) + (drop + (i32.const 1) ) - (i32.const 1) ) (if - (block - (br $a (i32.const 2)) + (block $block6 + (block + (drop + (i32.const 2) + ) + (br $a) + ) (i32.const 3) ) - (i32.const 0) - (i32.const 1) + (drop + (i32.const 0) + ) + (drop + (i32.const 1) + ) ) - (if ;; brs to the inner $a's get removed, the it is selectifiable + (if (block $a - (br $a (i32.const 0)) + (br $a + (i32.const 0) + ) ) (block $a - (br $a (i32.const 1)) + (block + (drop + (i32.const 1) + ) + (br $a) + ) ) (block $a - (br $a (i32.const 2)) + (block + (drop + (i32.const 2) + ) + (br $a) + ) ) ) ) ) - (func $side-effects-and-order (result i32) + (func $side-effects-and-order (type $2) (result i32) (local $x i32) (block $do-once$0 (if (call $b13) - (br $do-once$0 - (i32.const 0) + (block + (drop + (i32.const 0) + ) + (br $do-once$0) ) ) - (i32.const 1) + (drop + (i32.const 1) + ) ) (block $do-once$0 (if (call $b13) - (br $do-once$0 - (call $b14) + (block + (drop + (call $b14) + ) + (br $do-once$0) ) ) - (i32.const 1) + (drop + (i32.const 1) + ) ) (block $do-once$0 (if (i32.const 0) - (br $do-once$0 - (call $b14) + (block + (drop + (call $b14) + ) + (br $do-once$0) ) ) - (i32.const 1) + (drop + (i32.const 1) + ) ) (block $do-once$0 (if - (set_local $x (i32.const 1)) + (tee_local $x + (i32.const 1) + ) (br $do-once$0 - (set_local $x (i32.const 2)) + (tee_local $x + (i32.const 2) + ) ) ) (i32.const 1) ) ) ) - diff --git a/test/passes/remove-unused-functions.txt b/test/passes/remove-unused-functions.txt index cd819d347..1bd30e866 100644 --- a/test/passes/remove-unused-functions.txt +++ b/test/passes/remove-unused-functions.txt @@ -2,7 +2,7 @@ (memory 0) (start $start) (type $0 (func)) - (export "exported" $exported) + (export "exported" (func $exported)) (table 1 1 anyfunc) (elem (i32.const 0) $called_indirect) (func $start (type $0) diff --git a/test/passes/remove-unused-functions.wast b/test/passes/remove-unused-functions.wast index 4c89804bf..9449a25cb 100644 --- a/test/passes/remove-unused-functions.wast +++ b/test/passes/remove-unused-functions.wast @@ -1,46 +1,47 @@ (module + (memory 0) (start $start) + (type $0 (func)) (export "exported" $exported) (table $called_indirect) - (func $start + (func $start (type $0) (call $called0) ) - (func $called0 + (func $called0 (type $0) (call $called1) ) - (func $called1 + (func $called1 (type $0) (nop) ) - (func $called_indirect + (func $called_indirect (type $0) (nop) ) - (func $exported + (func $exported (type $0) (call $called2) ) - (func $called2 + (func $called2 (type $0) (call $called2) (call $called3) ) - (func $called3 + (func $called3 (type $0) (call $called4) ) - (func $called4 + (func $called4 (type $0) (call $called3) ) - (func $remove0 + (func $remove0 (type $0) (call $remove1) ) - (func $remove1 + (func $remove1 (type $0) (nop) ) - (func $remove2 + (func $remove2 (type $0) (call $remove2) ) - (func $remove3 + (func $remove3 (type $0) (call $remove4) ) - (func $remove4 + (func $remove4 (type $0) (call $remove3) ) ) - diff --git a/test/passes/remove-unused-names.txt b/test/passes/remove-unused-names.txt index b36ebb622..fa42e8d28 100644 --- a/test/passes/remove-unused-names.txt +++ b/test/passes/remove-unused-names.txt @@ -6,42 +6,45 @@ (i32.const 0) ) (func $loops (type $1) - (loop $out $in - (br $out) - (br $in) - ) (block $out - (br $out) + (loop $in + (br $out) + (br $in) + ) ) (loop $in (br $in) ) - (loop - (nop) - ) - (loop - (loop $out $in + (nop) + (block $out + (loop $in (br $out) (br $in) ) ) - (block - (loop $out $in + (block $out + (loop $in (br $out) (br $in) ) ) - (loop $out $in - (br $out) - (br $in) + (loop $in + (block $out + (br $out) + (br $in) + ) ) - (loop $out $in - (br $out) - (br $in) + (loop $in + (block $out + (br $out) + (br $in) + ) ) - (loop $out $in - (br $out) - (br $in) + (block $out + (loop $in + (br $out) + (br $in) + ) ) ) (func $merges (type $1) diff --git a/test/passes/remove-unused-names.wast b/test/passes/remove-unused-names.wast index 9423b2675..c8efa0c15 100644 --- a/test/passes/remove-unused-names.wast +++ b/test/passes/remove-unused-names.wast @@ -1,37 +1,42 @@ (module (memory 256 256) - (func $b0 (param $i1 i32) (result i32) + (type $0 (func (param i32) (result i32))) + (type $1 (func)) + (func $b0 (type $0) (param $i1 i32) (result i32) (block $topmost (i32.const 0) ) ) - (func $loops - (loop $out $in - (br $out) - (br $in) - ) - (loop $out $in - (br $out) + (func $loops (type $1) + (block $out + (loop $in + (br $out) + (br $in) + ) ) - (loop $out $in + (loop $in (br $in) ) - (loop $out $in + (loop $in (nop) ) - (loop $out $in - (loop $out $in - (br $out) - (br $in) + (block $out + (loop $in + (block $out + (loop $in + (br $out) + (br $in) + ) + ) ) ) (block $out - (loop $out $in + (loop $in (br $out) (br $in) ) ) - (loop $out $in + (loop $in (block $out (br $out) (br $in) @@ -50,7 +55,7 @@ ) ) ) - (func $merges + (func $merges (type $1) (block $a (block $b (br $a) @@ -59,14 +64,17 @@ ) (block $a (block $b - (br_table $a $b (i32.const 3)) + (br_table $a $b + (i32.const 3) + ) ) ) (block $a (block $b - (br_table $b $a (i32.const 3)) + (br_table $b $a + (i32.const 3) + ) ) ) ) ) - diff --git a/test/passes/remove-unused-names_merge-blocks.txt b/test/passes/remove-unused-names_merge-blocks.txt index 88d284a5a..4557f3da4 100644 --- a/test/passes/remove-unused-names_merge-blocks.txt +++ b/test/passes/remove-unused-names_merge-blocks.txt @@ -16,7 +16,9 @@ (nop) ) (func $b0-yes (type $i) (param $i1 i32) - (i32.const 10) + (drop + (i32.const 10) + ) ) (func $b0-no (type $i) (param $i1 i32) (block $topmost @@ -32,313 +34,527 @@ ) ) (func $b1-yes (type $i) (param $i1 i32) - (i32.const 10) + (drop + (i32.const 10) + ) ) (func $b2-yes (type $i) (param $i1 i32) - (i32.const 5) - (i32.const 10) - (i32.const 15) + (drop + (i32.const 5) + ) + (drop + (i32.const 10) + ) + (drop + (i32.const 15) + ) ) (func $b3-yes (type $i) (param $i1 i32) - (i32.const 3) - (i32.const 6) - (i32.const 10) - (i32.const 15) - (i32.const 20) + (drop + (i32.const 3) + ) + (drop + (i32.const 6) + ) + (drop + (i32.const 10) + ) + (drop + (i32.const 15) + ) + (drop + (i32.const 20) + ) ) (func $b4 (type $i) (param $i1 i32) (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) ) (func $b5 (type $i) (param $i1 i32) (block $middle (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) (br $middle) ) ) (func $b6 (type $i) (param $i1 i32) - (i32.const 5) + (drop + (i32.const 5) + ) (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) - (i32.const 15) + (drop + (i32.const 15) + ) ) (func $b7 (type $i) (param $i1 i32) - (i32.const 3) + (drop + (i32.const 3) + ) (block $middle - (i32.const 6) + (drop + (i32.const 6) + ) (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) - (i32.const 15) + (drop + (i32.const 15) + ) (br $middle) ) - (i32.const 20) + (drop + (i32.const 20) + ) ) (func $unary (type $3) (local $x i32) - (i32.eqz - (block - (i32.const 10) + (drop + (i32.eqz + (block + (i32.const 10) + ) ) ) - (i32.const 10) - (i32.eqz + (drop + (i32.const 10) + ) + (drop + (i32.eqz + (i32.const 20) + ) + ) + (drop + (i32.const 10) + ) + (drop (i32.const 20) ) - (i32.const 10) - (i32.const 20) - (i32.eqz - (i32.const 30) + (drop + (i32.eqz + (i32.const 30) + ) + ) + (drop + (i32.const 10) ) - (i32.const 10) (set_local $x (i32.const 20) ) - (i32.const 10) - (i32.load - (i32.const 20) + (drop + (i32.const 10) + ) + (drop + (i32.load + (i32.const 20) + ) + ) + (drop + (i32.const 10) ) - (i32.const 10) (return (unreachable) ) ) (func $binary (type $3) - (i32.add - (block + (drop + (i32.add + (block + (i32.const 10) + ) + (i32.const 20) + ) + ) + (drop + (i32.const 10) + ) + (drop + (i32.add + (i32.const 20) + (i32.const 30) + ) + ) + (drop + (i32.const 10) + ) + (drop + (i32.const 20) + ) + (drop + (i32.add + (i32.const 30) + (i32.const 40) + ) + ) + (drop + (i32.add (i32.const 10) + (block + (i32.const 20) + ) ) + ) + (drop (i32.const 20) ) - (i32.const 10) - (i32.add + (drop + (i32.add + (i32.const 10) + (i32.const 30) + ) + ) + (drop (i32.const 20) - (i32.const 30) ) - (i32.const 10) - (i32.const 20) - (i32.add + (drop (i32.const 30) - (i32.const 40) ) - (i32.add - (i32.const 10) - (block - (i32.const 20) + (drop + (i32.add + (i32.const 10) + (i32.const 40) ) ) - (i32.const 20) - (i32.add - (i32.const 10) - (i32.const 30) + (drop + (i32.add + (block + (i32.const 10) + ) + (block + (i32.const 20) + ) + ) ) - (i32.const 20) - (i32.const 30) - (i32.add + (drop (i32.const 10) - (i32.const 40) ) - (i32.add - (block - (i32.const 10) - ) - (block + (drop + (i32.const 30) + ) + (drop + (i32.add (i32.const 20) + (i32.const 40) ) ) - (i32.const 10) - (i32.const 30) - (i32.add + (drop + (i32.const 10) + ) + (drop (i32.const 20) + ) + (drop (i32.const 40) ) - (i32.const 10) - (i32.const 20) - (i32.const 40) - (i32.const 50) - (i32.add - (i32.const 30) - (i32.const 60) + (drop + (i32.const 50) + ) + (drop + (i32.add + (i32.const 30) + (i32.const 60) + ) + ) + (drop + (i32.const 20) ) - (i32.const 20) (i32.store (i32.const 10) (i32.const 30) ) - (i32.const 10) + (drop + (i32.const 10) + ) (i32.store (i32.const 20) (i32.const 30) ) - (i32.add - (unreachable) - (block - (i32.const 10) - (i32.const 20) + (drop + (i32.add + (unreachable) + (block + (drop + (i32.const 10) + ) + (i32.const 20) + ) ) ) (unreachable) - (i32.const 20) - (i32.add - (i32.const 10) - (i32.const 30) - ) - ) - (func $trinary (type $3) - (i32.const 10) - (i32.const 30) - (i32.const 50) - (select + (drop (i32.const 20) - (i32.const 40) - (i32.const 60) ) - (i32.const 20) - (i32.const 40) - (select - (block + (drop + (i32.add (i32.const 10) + (i32.const 30) ) + ) + ) + (func $trinary (type $3) + (drop + (i32.const 10) + ) + (drop (i32.const 30) + ) + (drop (i32.const 50) ) - (i32.const 10) - (i32.const 40) - (select - (i32.const 20) - (block - (i32.const 30) + (drop + (select + (i32.const 20) + (i32.const 40) + (i32.const 60) ) - (i32.const 50) ) - (i32.const 10) - (i32.const 30) - (select + (drop (i32.const 20) + ) + (drop (i32.const 40) - (block + ) + (drop + (select + (block + (i32.const 10) + ) + (i32.const 30) (i32.const 50) ) ) - (i32.const 30) - (select - (block - (i32.const 10) - ) - (block + (drop + (i32.const 10) + ) + (drop + (i32.const 40) + ) + (drop + (select (i32.const 20) + (block + (i32.const 30) + ) + (i32.const 50) ) - (i32.const 40) ) - (i32.const 20) - (select - (block - (i32.const 10) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) + (drop + (select + (i32.const 20) + (i32.const 40) + (block + (i32.const 50) + ) ) + ) + (drop (i32.const 30) - (block + ) + (drop + (select + (block + (i32.const 10) + ) + (block + (i32.const 20) + ) (i32.const 40) ) ) - (i32.const 10) - (select + (drop (i32.const 20) - (block + ) + (drop + (select + (block + (i32.const 10) + ) (i32.const 30) + (block + (i32.const 40) + ) ) - (block - (i32.const 40) + ) + (drop + (i32.const 10) + ) + (drop + (select + (i32.const 20) + (block + (i32.const 30) + ) + (block + (i32.const 40) + ) ) ) (unreachable) - (i32.const 30) - (i32.const 50) - (select - (i32.const 20) - (i32.const 40) - (i32.const 60) + (drop + (i32.const 30) ) - (i32.const 10) - (select - (unreachable) - (block - (i32.const 30) + (drop + (i32.const 50) + ) + (drop + (select + (i32.const 20) (i32.const 40) - ) - (block - (i32.const 50) (i32.const 60) ) ) - (i32.const 10) + (drop + (i32.const 10) + ) + (drop + (select + (unreachable) + (block + (drop + (i32.const 30) + ) + (i32.const 40) + ) + (block + (drop + (i32.const 50) + ) + (i32.const 60) + ) + ) + ) + (drop + (i32.const 10) + ) (unreachable) - (i32.const 50) - (select - (i32.const 20) - (i32.const 40) - (i32.const 60) + (drop + (i32.const 50) ) - (i32.const 10) - (i32.const 30) - (select - (i32.const 20) - (unreachable) - (block - (i32.const 50) + (drop + (select + (i32.const 20) + (i32.const 40) (i32.const 60) ) ) - (i32.const 10) - (i32.const 30) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) + (drop + (select + (i32.const 20) + (unreachable) + (block + (drop + (i32.const 50) + ) + (i32.const 60) + ) + ) + ) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) (unreachable) - (select - (i32.const 20) - (i32.const 40) - (i32.const 60) + (drop + (select + (i32.const 20) + (i32.const 40) + (i32.const 60) + ) ) - (i32.const 10) - (i32.const 30) - (i32.const 50) - (select - (i32.const 20) - (i32.const 40) - (unreachable) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) + (drop + (i32.const 50) + ) + (drop + (select + (i32.const 20) + (i32.const 40) + (unreachable) + ) ) ) (func $breaks (type $3) (block $out - (i32.const 10) - (br $out + (drop + (i32.const 10) + ) + (drop (i32.const 20) ) - (i32.const 10) + (br $out) + (drop + (i32.const 10) + ) (br_if $out (i32.const 20) ) - (i32.const 10) - (i32.const 30) - (br_if $out + (drop + (i32.const 10) + ) + (drop (i32.const 20) + ) + (drop + (i32.const 30) + ) + (br_if $out (i32.const 40) ) - (i32.const 10) - (br_table $out $out - (i32.const 20) + (drop + (i32.const 10) ) - (i32.const 10) - (i32.const 30) (br_table $out $out (i32.const 20) - (i32.const 40) ) + (drop + (block $out2 + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) + (br_table $out2 $out2 + (i32.const 20) + (i32.const 40) + ) + ) + ) + (unreachable) ) ) (func $calls (type $3) @@ -347,80 +563,120 @@ (i32.const 10) ) ) - (i32.const 10) + (drop + (i32.const 10) + ) (call $call-i (i32.const 20) ) - (i32.const 10) - (i32.const 20) + (drop + (i32.const 10) + ) + (drop + (i32.const 20) + ) (call $call-i (i32.const 30) ) - (i32.const 10) - (i32.const 30) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) (call $call-ii (i32.const 20) (i32.const 40) ) (unreachable) - (i32.const 20) + (drop + (i32.const 20) + ) (call $call-ii (i32.const 10) (i32.const 30) ) - (i32.const 10) + (drop + (i32.const 10) + ) (call $call-ii (unreachable) (block - (i32.const 20) + (drop + (i32.const 20) + ) (i32.const 30) ) ) - (i32.const 10) + (drop + (i32.const 10) + ) (unreachable) (call $call-ii (i32.const 20) (i32.const 30) ) - (i32.const 10) - (i32.const 30) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) (call $call-ii (i32.const 20) (unreachable) ) - (i32.const 10) - (i32.const 30) - (i32.const 50) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) + (drop + (i32.const 50) + ) (call $call-iii (i32.const 20) (i32.const 40) (i32.const 60) ) - (i32.const 10) - (i32.const 40) + (drop + (i32.const 10) + ) + (drop + (i32.const 40) + ) (call $call-iii (i32.const 20) (i32.const 30) (i32.const 50) ) - (i32.const 10) - (i32.const 30) - (i32.const 50) + (drop + (i32.const 50) + ) + (drop + (i32.const 10) + ) + (drop + (i32.const 30) + ) (call_indirect $ii (i32.const 20) (i32.const 40) (i32.const 60) ) + (drop + (i32.const 50) + ) (call_indirect $ii (unreachable) (block - (i32.const 30) + (drop + (i32.const 30) + ) (i32.const 40) ) - (block - (i32.const 50) - (i32.const 60) - ) + (i32.const 60) ) ) (func $block-type-change (type $3) diff --git a/test/passes/remove-unused-names_merge-blocks.wast b/test/passes/remove-unused-names_merge-blocks.wast index 85bb11da6..562c5bbba 100644 --- a/test/passes/remove-unused-names_merge-blocks.wast +++ b/test/passes/remove-unused-names_merge-blocks.wast @@ -1,23 +1,29 @@ (module (memory 256 256) (type $i (func (param i32))) - (type $ii (func (param i32) (param i32))) - (type $iii (func (param i32) (param i32) (param i32))) + (type $ii (func (param i32 i32))) + (type $iii (func (param i32 i32 i32))) + (type $3 (func)) (table $call-i) - (func $call-i (param i32) + (func $call-i (type $i) (param $0 i32) + (nop) ) - (func $call-ii (param i32) (param i32) + (func $call-ii (type $ii) (param $0 i32) (param $1 i32) + (nop) ) - (func $call-iii (param i32) (param i32) (param i32) + (func $call-iii (type $iii) (param $0 i32) (param $1 i32) (param $2 i32) + (nop) ) - (func $b0-yes (param $i1 i32) + (func $b0-yes (type $i) (param $i1 i32) (block $topmost - (block - (i32.const 10) + (block $block0 + (drop + (i32.const 10) + ) ) ) ) - (func $b0-no (param $i1 i32) + (func $b0-no (type $i) (param $i1 i32) (block $topmost (block $block0 (br $block0) @@ -25,577 +31,836 @@ (br $topmost) ) ) - (func $b0-br-but-ok (param $i1 i32) + (func $b0-br-but-ok (type $i) (param $i1 i32) (block $topmost (block $block0 (br $topmost) ) ) ) - (func $b1-yes (param $i1 i32) + (func $b1-yes (type $i) (param $i1 i32) (block $topmost - (block - (block - (i32.const 10) + (block $block0 + (block $block1 + (drop + (i32.const 10) + ) ) ) ) ) - (func $b2-yes (param $i1 i32) + (func $b2-yes (type $i) (param $i1 i32) (block $topmost - (i32.const 5) - (block - (i32.const 10) + (drop + (i32.const 5) + ) + (block $block0 + (drop + (i32.const 10) + ) + ) + (drop + (i32.const 15) ) - (i32.const 15) ) ) - (func $b3-yes (param $i1 i32) + (func $b3-yes (type $i) (param $i1 i32) (block $topmost - (i32.const 3) - (block - (i32.const 6) - (block - (i32.const 10) + (drop + (i32.const 3) + ) + (block $block0 + (drop + (i32.const 6) ) - (i32.const 15) + (block $block1 + (drop + (i32.const 10) + ) + ) + (drop + (i32.const 15) + ) + ) + (drop + (i32.const 20) ) - (i32.const 20) ) ) - (func $b4 (param $i1 i32) + (func $b4 (type $i) (param $i1 i32) (block $topmost (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) ) ) - (func $b5 (param $i1 i32) + (func $b5 (type $i) (param $i1 i32) (block $topmost (block $middle (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) (br $middle) ) ) ) - (func $b6 (param $i1 i32) + (func $b6 (type $i) (param $i1 i32) (block $topmost - (i32.const 5) + (drop + (i32.const 5) + ) (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) - (i32.const 15) + (drop + (i32.const 15) + ) ) ) - (func $b7 (param $i1 i32) + (func $b7 (type $i) (param $i1 i32) (block $topmost - (i32.const 3) + (drop + (i32.const 3) + ) (block $middle - (i32.const 6) + (drop + (i32.const 6) + ) (block $inner - (i32.const 10) + (drop + (i32.const 10) + ) (br $inner) ) - (i32.const 15) + (drop + (i32.const 15) + ) (br $middle) ) - (i32.const 20) + (drop + (i32.const 20) + ) ) ) - (func $unary + (func $unary (type $3) (local $x i32) - (i32.eqz - (block - (i32.const 10) + (drop + (i32.eqz + (block $block0 + (i32.const 10) + ) ) ) - (i32.eqz - (block - (i32.const 10) - (i32.const 20) + (drop + (i32.eqz + (block $block1 + (drop + (i32.const 10) + ) + (i32.const 20) + ) ) ) - (i32.eqz - (block - (i32.const 10) - (i32.const 20) - (i32.const 30) + (drop + (i32.eqz + (block $block2 + (drop + (i32.const 10) + ) + (drop + (i32.const 20) + ) + (i32.const 30) + ) ) ) (set_local $x - (block - (i32.const 10) + (block $block3 + (drop + (i32.const 10) + ) (i32.const 20) ) ) - (i32.load - (block - (i32.const 10) - (i32.const 20) + (drop + (i32.load + (block $block4 + (drop + (i32.const 10) + ) + (i32.const 20) + ) ) ) (return - (block - (i32.const 10) + (block $block5 + (drop + (i32.const 10) + ) (unreachable) ) ) ) - (func $binary - (i32.add - (block - (i32.const 10) - ) - (i32.const 20) - ) - (i32.add - (block - (i32.const 10) - (i32.const 20) - ) - (i32.const 30) - ) - (i32.add - (block - (i32.const 10) - (i32.const 20) - (i32.const 30) - ) - (i32.const 40) - ) - (i32.add - (i32.const 10) - (block + (func $binary (type $3) + (drop + (i32.add + (block $block0 + (i32.const 10) + ) (i32.const 20) ) ) - (i32.add - (i32.const 10) - (block - (i32.const 20) + (drop + (i32.add + (block $block1 + (drop + (i32.const 10) + ) + (i32.const 20) + ) (i32.const 30) ) ) - (i32.add - (i32.const 10) - (block - (i32.const 20) - (i32.const 30) + (drop + (i32.add + (block $block2 + (drop + (i32.const 10) + ) + (drop + (i32.const 20) + ) + (i32.const 30) + ) (i32.const 40) ) ) - (i32.add - (block + (drop + (i32.add (i32.const 10) + (block $block3 + (i32.const 20) + ) ) - (block - (i32.const 20) + ) + (drop + (i32.add + (i32.const 10) + (block $block4 + (drop + (i32.const 20) + ) + (i32.const 30) + ) ) ) - (i32.add - (block + (drop + (i32.add (i32.const 10) - (i32.const 20) + (block $block5 + (drop + (i32.const 20) + ) + (drop + (i32.const 30) + ) + (i32.const 40) + ) ) - (block - (i32.const 30) - (i32.const 40) + ) + (drop + (i32.add + (block $block6 + (i32.const 10) + ) + (block $block7 + (i32.const 20) + ) ) ) - (i32.add - (block - (i32.const 10) - (i32.const 20) - (i32.const 30) + (drop + (i32.add + (block $block8 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block9 + (drop + (i32.const 30) + ) + (i32.const 40) + ) ) - (block - (i32.const 40) - (i32.const 50) - (i32.const 60) + ) + (drop + (i32.add + (block $block10 + (drop + (i32.const 10) + ) + (drop + (i32.const 20) + ) + (i32.const 30) + ) + (block $block11 + (drop + (i32.const 40) + ) + (drop + (i32.const 50) + ) + (i32.const 60) + ) ) ) (i32.store (i32.const 10) - (block - (i32.const 20) + (block $block12 + (drop + (i32.const 20) + ) (i32.const 30) ) ) (i32.store - (block - (i32.const 10) + (block $block13 + (drop + (i32.const 10) + ) (i32.const 20) ) (i32.const 30) ) - (i32.add - (unreachable) ;; do not move across this TODO: move non-side-effecting - (block - (i32.const 10) - (i32.const 20) + (drop + (i32.add + (unreachable) + (block $block14 + (drop + (i32.const 10) + ) + (i32.const 20) + ) ) ) - (i32.add - (block - (unreachable) ;; moves out, so does not block the rest - (i32.const 10) - ) - (block - (i32.const 20) - (i32.const 30) + (drop + (i32.add + (block $block15 + (unreachable) + (i32.const 10) + ) + (block $block16 + (drop + (i32.const 20) + ) + (i32.const 30) + ) ) ) ) - (func $trinary - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - (i32.const 40) - ) - (block - (i32.const 50) - (i32.const 60) + (func $trinary (type $3) + (drop + (select + (block $block0 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block1 + (drop + (i32.const 30) + ) + (i32.const 40) + ) + (block $block2 + (drop + (i32.const 50) + ) + (i32.const 60) + ) ) ) - (select - (block - (i32.const 10) - ) - (block - (i32.const 20) - (i32.const 30) - ) - (block - (i32.const 40) - (i32.const 50) + (drop + (select + (block $block3 + (i32.const 10) + ) + (block $block4 + (drop + (i32.const 20) + ) + (i32.const 30) + ) + (block $block5 + (drop + (i32.const 40) + ) + (i32.const 50) + ) ) ) - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - ) - (block - (i32.const 40) - (i32.const 50) + (drop + (select + (block $block6 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block7 + (i32.const 30) + ) + (block $block8 + (drop + (i32.const 40) + ) + (i32.const 50) + ) ) ) - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - (i32.const 40) - ) - (block - (i32.const 50) + (drop + (select + (block $block9 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block10 + (drop + (i32.const 30) + ) + (i32.const 40) + ) + (block $block11 + (i32.const 50) + ) ) ) - (select - (block - (i32.const 10) - ) - (block - (i32.const 20) - ) - (block - (i32.const 30) - (i32.const 40) + (drop + (select + (block $block12 + (i32.const 10) + ) + (block $block13 + (i32.const 20) + ) + (block $block14 + (drop + (i32.const 30) + ) + (i32.const 40) + ) ) ) - (select - (block - (i32.const 10) - ) - (block - (i32.const 20) - (i32.const 30) - ) - (block - (i32.const 40) + (drop + (select + (block $block15 + (i32.const 10) + ) + (block $block16 + (drop + (i32.const 20) + ) + (i32.const 30) + ) + (block $block17 + (i32.const 40) + ) ) ) - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - ) - (block - (i32.const 40) + (drop + (select + (block $block18 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block19 + (i32.const 30) + ) + (block $block20 + (i32.const 40) + ) ) ) - ;; now for bad stuff - (select - (block - (unreachable) - (i32.const 20) - ) - (block - (i32.const 30) - (i32.const 40) - ) - (block - (i32.const 50) - (i32.const 60) + (drop + (select + (block $block21 + (unreachable) + (i32.const 20) + ) + (block $block22 + (drop + (i32.const 30) + ) + (i32.const 40) + ) + (block $block23 + (drop + (i32.const 50) + ) + (i32.const 60) + ) ) ) - (select - (block - (i32.const 10) - (unreachable) - ) - (block - (i32.const 30) - (i32.const 40) - ) - (block - (i32.const 50) - (i32.const 60) + (drop + (select + (block $block24 + (drop + (i32.const 10) + ) + (unreachable) + ) + (block $block25 + (drop + (i32.const 30) + ) + (i32.const 40) + ) + (block $block26 + (drop + (i32.const 50) + ) + (i32.const 60) + ) ) ) - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (unreachable) - (i32.const 40) - ) - (block - (i32.const 50) - (i32.const 60) + (drop + (select + (block $block27 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block28 + (unreachable) + (i32.const 40) + ) + (block $block29 + (drop + (i32.const 50) + ) + (i32.const 60) + ) ) ) - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - (unreachable) - ) - (block - (i32.const 50) - (i32.const 60) + (drop + (select + (block $block30 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block31 + (drop + (i32.const 30) + ) + (unreachable) + ) + (block $block32 + (drop + (i32.const 50) + ) + (i32.const 60) + ) ) ) - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - (i32.const 40) - ) - (block - (unreachable) - (i32.const 60) + (drop + (select + (block $block33 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block34 + (drop + (i32.const 30) + ) + (i32.const 40) + ) + (block $block35 + (unreachable) + (i32.const 60) + ) ) ) - (select - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - (i32.const 40) - ) - (block - (i32.const 50) - (unreachable) + (drop + (select + (block $block36 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block37 + (drop + (i32.const 30) + ) + (i32.const 40) + ) + (block $block38 + (drop + (i32.const 50) + ) + (unreachable) + ) ) ) ) - (func $breaks + (func $breaks (type $3) (block $out - (br $out - (block - (i32.const 10) - (i32.const 20) + (block + (drop + (block $block0 + (drop + (i32.const 10) + ) + (i32.const 20) + ) ) + (br $out) ) (br_if $out - (block - (i32.const 10) + (block $block1 + (drop + (i32.const 10) + ) (i32.const 20) ) ) - (br_if $out - (block - (i32.const 10) - (i32.const 20) + (block + (drop + (block $block2 + (drop + (i32.const 10) + ) + (i32.const 20) + ) ) - (block - (i32.const 30) - (i32.const 40) + (br_if $out + (block $block3 + (drop + (i32.const 30) + ) + (i32.const 40) + ) ) ) (br_table $out $out - (block - (i32.const 10) + (block $block4 + (drop + (i32.const 10) + ) (i32.const 20) ) ) - (br_table $out $out - (block - (i32.const 10) - (i32.const 20) - ) - (block - (i32.const 30) - (i32.const 40) + (drop + (block $out2 + (br_table $out2 $out2 + (block $block5 + (drop + (i32.const 10) + ) + (i32.const 20) + ) + (block $block6 + (drop + (i32.const 30) + ) + (i32.const 40) + ) + ) ) ) + (unreachable) ) ) - (func $calls + (func $calls (type $3) (call $call-i - (block + (block $block0 (i32.const 10) ) ) (call $call-i - (block - (i32.const 10) + (block $block1 + (drop + (i32.const 10) + ) (i32.const 20) ) ) (call $call-i - (block - (i32.const 10) - (i32.const 20) + (block $block2 + (drop + (i32.const 10) + ) + (drop + (i32.const 20) + ) (i32.const 30) ) ) (call $call-ii - (block - (i32.const 10) + (block $block3 + (drop + (i32.const 10) + ) (i32.const 20) ) - (block - (i32.const 30) + (block $block4 + (drop + (i32.const 30) + ) (i32.const 40) ) ) (call $call-ii - (block + (block $block5 (unreachable) (i32.const 10) ) - (block - (i32.const 20) + (block $block6 + (drop + (i32.const 20) + ) (i32.const 30) ) ) (call $call-ii - (block - (i32.const 10) + (block $block7 + (drop + (i32.const 10) + ) (unreachable) ) - (block - (i32.const 20) + (block $block8 + (drop + (i32.const 20) + ) (i32.const 30) ) ) (call $call-ii - (block - (i32.const 10) + (block $block9 + (drop + (i32.const 10) + ) (i32.const 20) ) - (block + (block $block10 (unreachable) (i32.const 30) ) ) (call $call-ii - (block - (i32.const 10) + (block $block11 + (drop + (i32.const 10) + ) (i32.const 20) ) - (block - (i32.const 30) + (block $block12 + (drop + (i32.const 30) + ) (unreachable) ) ) (call $call-iii - (block - (i32.const 10) + (block $block13 + (drop + (i32.const 10) + ) (i32.const 20) ) - (block - (i32.const 30) + (block $block14 + (drop + (i32.const 30) + ) (i32.const 40) ) - (block - (i32.const 50) + (block $block15 + (drop + (i32.const 50) + ) (i32.const 60) ) ) (call $call-iii - (block - (i32.const 10) + (block $block16 + (drop + (i32.const 10) + ) (i32.const 20) ) (i32.const 30) - (block - (i32.const 40) + (block $block17 + (drop + (i32.const 40) + ) (i32.const 50) ) ) (call_indirect $ii - (block - (i32.const 10) + (block $block18 + (drop + (i32.const 10) + ) (i32.const 20) ) - (block - (i32.const 30) + (block $block19 + (drop + (i32.const 30) + ) (i32.const 40) ) - (block - (i32.const 50) + (block $block20 + (drop + (i32.const 50) + ) (i32.const 60) ) ) (call_indirect $ii (unreachable) - (block - (i32.const 30) + (block $block21 + (drop + (i32.const 30) + ) (i32.const 40) ) - (block - (i32.const 50) + (block $block22 + (drop + (i32.const 50) + ) (i32.const 60) ) ) ) - (func $block-type-change + (func $block-type-change (type $3) (local $0 f64) (local $1 f64) (if (f64.gt (get_local $0) - (block + (block $block0 (nop) (get_local $1) ) @@ -604,4 +869,3 @@ ) ) ) - diff --git a/test/passes/reorder-functions.wast b/test/passes/reorder-functions.wast index 99a8363d4..a69afa3b9 100644 --- a/test/passes/reorder-functions.wast +++ b/test/passes/reorder-functions.wast @@ -1,6 +1,16 @@ (module (memory 256 256) - (func $a (call $a)) - (func $b (call $b) (call $b)) - (func $c (call $c) (call $c) (call $c)) + (type $0 (func)) + (func $a (type $0) + (call $a) + ) + (func $b (type $0) + (call $b) + (call $b) + ) + (func $c (type $0) + (call $c) + (call $c) + (call $c) + ) ) diff --git a/test/passes/reorder-locals.txt b/test/passes/reorder-locals.txt index 7ecb7c4a4..c2b481cab 100644 --- a/test/passes/reorder-locals.txt +++ b/test/passes/reorder-locals.txt @@ -45,7 +45,9 @@ ) (func $zero (type $1) (local $b i32) - (get_local $b) + (drop + (get_local $b) + ) ) (func $null (type $1) (nop) diff --git a/test/passes/reorder-locals.wast b/test/passes/reorder-locals.wast index 832889a78..872d352ee 100644 --- a/test/passes/reorder-locals.wast +++ b/test/passes/reorder-locals.wast @@ -1,29 +1,59 @@ (module (memory 256 256) - (func $b0-yes (param $a i32) (param $b i32) + (type $0 (func (param i32 i32))) + (type $1 (func)) + (func $b0-yes (type $0) (param $a i32) (param $b i32) (local $x i32) (local $y i32) (local $z i32) - - ;; Should reverse the order of the locals. - (set_local $x (get_local $x)) - (set_local $y (get_local $y)) (set_local $y (get_local $y)) - (set_local $z (get_local $z)) (set_local $z (get_local $z)) (set_local $z (get_local $z)) - - ;; Should not touch the args. - (set_local $b (get_local $b)) (set_local $b (get_local $b)) (set_local $b (get_local $b)) - (set_local $b (get_local $b)) (set_local $b (get_local $b)) (set_local $b (get_local $b)) + (set_local $x + (get_local $x) + ) + (set_local $y + (get_local $y) + ) + (set_local $y + (get_local $y) + ) + (set_local $z + (get_local $z) + ) + (set_local $z + (get_local $z) + ) + (set_local $z + (get_local $z) + ) + (set_local $b + (get_local $b) + ) + (set_local $b + (get_local $b) + ) + (set_local $b + (get_local $b) + ) + (set_local $b + (get_local $b) + ) + (set_local $b + (get_local $b) + ) + (set_local $b + (get_local $b) + ) ) - (func $zero + (func $zero (type $1) (local $a i32) (local $b i32) (local $c i32) - (get_local $b) ;; a and c are untouched + (drop + (get_local $b) + ) ) - (func $null + (func $null (type $1) (local $a i32) (local $c i32) - (nop) ;; a and c are untouched + (nop) ) ) - diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals.txt index 0ca96893f..72bd7aa12 100644 --- a/test/passes/simplify-locals.txt +++ b/test/passes/simplify-locals.txt @@ -7,75 +7,138 @@ (type $4 (func (param i32))) (type $5 (func (param i32) (result i32))) (type $6 (func (param i32 i32 i32 i32 i32 i32))) - (import $waka "env" "waka") - (import $waka_int "env" "waka_int" (result i32)) - (import $_i64Subtract "env" "i64sub" (param i32 i32 i32 i32) (result i32)) - (import $___udivmoddi4 "env" "moddi" (param i32 i32 i32 i32 i32) (result i32)) + (type $7 (func (param i32 i32))) + (import "env" "waka" (func $waka)) + (import "env" "waka_int" (func $waka_int (result i32))) + (import "env" "i64sub" (func $_i64Subtract (param i32 i32 i32 i32) (result i32))) + (import "env" "moddi" (func $___udivmoddi4 (param i32 i32 i32 i32 i32) (result i32))) (func $b0-yes (type $4) (param $i1 i32) (local $x i32) (local $y i32) (local $a i32) (local $b i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) (nop) - (i32.const 5) + (drop + (i32.const 5) + ) (block $block0 (nop) - (i32.const 7) + (drop + (i32.const 7) + ) ) (nop) - (i32.const 11) - (i32.const 9) - (get_local $y) + (drop + (i32.const 11) + ) + (drop + (i32.const 9) + ) + (drop + (get_local $y) + ) (block $block1 - (i32.const 8) + (drop + (i32.const 8) + ) + (drop + (get_local $y) + ) + ) + (drop + (i32.const 11) + ) + (drop (get_local $y) ) - (i32.const 11) - (get_local $y) (nop) (nop) (nop) (nop) (nop) (nop) - (i32.const 17) + (drop + (i32.const 17) + ) (block $block2 (nop) (nop) - (i32.const 1) - (i32.const 2) - (i32.const 3) - (i32.const 4) + (drop + (i32.const 1) + ) + (drop + (i32.const 2) + ) + (drop + (i32.const 3) + ) + (drop + (i32.const 4) + ) (nop) (nop) - (i32.const 6) - (i32.const 5) - (i32.const 7) - (i32.const 8) + (drop + (i32.const 6) + ) + (drop + (i32.const 5) + ) + (drop + (i32.const 7) + ) + (drop + (i32.const 8) + ) (nop) (nop) (call_import $waka) - (i32.const 9) - (i32.const 10) - (i32.const 11) - (i32.const 12) + (drop + (i32.const 9) + ) + (drop + (i32.const 10) + ) + (drop + (i32.const 11) + ) + (drop + (i32.const 12) + ) (nop) (nop) - (i32.load - (i32.const 24) + (drop + (i32.load + (i32.const 24) + ) + ) + (drop + (i32.const 13) + ) + (drop + (i32.const 14) + ) + (drop + (i32.const 15) + ) + (drop + (i32.const 16) ) - (i32.const 13) - (i32.const 14) - (i32.const 15) - (i32.const 16) (nop) (nop) (i32.store (i32.const 48) (i32.const 96) ) - (i32.const 17) - (i32.const 18) + (drop + (i32.const 17) + ) + (drop + (i32.const 18) + ) ) (block $block3 (nop) @@ -87,15 +150,21 @@ (call_import $waka_int) ) (call_import $waka) - (get_local $a) + (drop + (get_local $a) + ) (call_import $waka) (set_local $a (call_import $waka_int) ) - (i32.load - (i32.const 1) + (drop + (i32.load + (i32.const 1) + ) + ) + (drop + (get_local $a) ) - (get_local $a) (call_import $waka) (set_local $a (call_import $waka_int) @@ -104,7 +173,9 @@ (i32.const 1) (i32.const 2) ) - (get_local $a) + (drop + (get_local $a) + ) (call_import $waka) (nop) (set_local $a @@ -114,8 +185,10 @@ ) (call_import $waka) (nop) - (i32.load - (i32.const 1) + (drop + (i32.load + (i32.const 1) + ) ) (set_local $a (i32.load @@ -129,7 +202,9 @@ ) ) (call_import $waka) - (get_local $a) + (drop + (get_local $a) + ) (call_import $waka) (set_local $a (i32.load @@ -140,73 +215,123 @@ (i32.const 1) (i32.const 2) ) - (get_local $a) + (drop + (get_local $a) + ) (call_import $waka) (nop) (set_local $a - (i32.store - (i32.const 104) - (i32.const 105) + (block $block0 + (block $block1 + (nop) + (i32.store + (i32.const 104) + (tee_local $5 + (i32.const 105) + ) + ) + ) + (get_local $5) ) ) (call_import $waka) (set_local $a - (i32.store - (i32.const 106) - (i32.const 107) + (block $block2 + (block $block4 + (nop) + (i32.store + (i32.const 106) + (tee_local $6 + (i32.const 107) + ) + ) + ) + (get_local $6) ) ) (call_import $waka) - (get_local $a) + (drop + (get_local $a) + ) (call_import $waka) (set_local $a - (i32.store - (i32.const 108) - (i32.const 109) + (block $block5 + (block $block6 + (nop) + (i32.store + (i32.const 108) + (tee_local $7 + (i32.const 109) + ) + ) + ) + (get_local $7) ) ) - (i32.load - (i32.const 1) + (drop + (i32.load + (i32.const 1) + ) + ) + (drop + (get_local $a) ) - (get_local $a) (call_import $waka) (set_local $a - (i32.store - (i32.const 110) - (i32.const 111) + (block $block7 + (block $block8 + (nop) + (i32.store + (i32.const 110) + (tee_local $8 + (i32.const 111) + ) + ) + ) + (get_local $8) ) ) (i32.store (i32.const 1) (i32.const 2) ) - (get_local $a) + (drop + (get_local $a) + ) (call_import $waka) ) (block $out-of-block (nop) (nop) - (block $b - (block $c - (br $b - (i32.const 1337) + (drop + (block $b + (block $c + (br $b + (i32.const 1337) + ) ) + (nop) + (i32.const 9876) ) - (nop) - (i32.const 9876) ) ) (block $loopey (set_local $a (i32.const 1337) ) - (loop $loop-out4 $loop-in5 - (get_local $a) - (set_local $a - (i32.const 9876) + (drop + (loop $loop-in5 + (drop + (get_local $a) + ) + (tee_local $a + (i32.const 9876) + ) ) ) - (get_local $a) + (drop + (get_local $a) + ) ) ) (func $Ia (type $5) (param $a i32) (result i32) @@ -229,7 +354,7 @@ ) (nop) (i32.store8 - (set_local $bi3 + (tee_local $bi3 (i32.const 1) ) (get_local $bi3) @@ -240,7 +365,7 @@ (get_local $bi3) ) (set_local $di3 - (set_local $bi3 + (tee_local $bi3 (i32.const 123) ) ) @@ -248,7 +373,9 @@ (get_local $bi3) (get_local $di3) ) - (i32.const 456) + (drop + (i32.const 456) + ) ) (func $___remdi3 (type $FUNCSIG$iiiii) (param $$a$0 i32) (param $$a$1 i32) (param $$b$0 i32) (param $$b$1 i32) (result i32) (local $$1$1 i32) @@ -285,124 +412,126 @@ (nop) (nop) (nop) - (call_import $___udivmoddi4 - (call_import $_i64Subtract - (i32.xor - (set_local $$1$0 - (i32.or - (i32.shr_s - (get_local $$a$1) - (i32.const 31) - ) - (i32.shl - (if - (i32.lt_s - (get_local $$a$1) + (drop + (call_import $___udivmoddi4 + (call_import $_i64Subtract + (i32.xor + (tee_local $$1$0 + (i32.or + (i32.shr_s + (get_local $$a$1) + (i32.const 31) + ) + (i32.shl + (if + (i32.lt_s + (get_local $$a$1) + (i32.const 0) + ) + (i32.const -1) (i32.const 0) ) - (i32.const -1) - (i32.const 0) + (i32.const 1) ) - (i32.const 1) ) ) + (get_local $$a$0) ) - (get_local $$a$0) - ) - (i32.xor - (set_local $$1$1 - (i32.or - (i32.shr_s - (if - (i32.lt_s - (get_local $$a$1) + (i32.xor + (tee_local $$1$1 + (i32.or + (i32.shr_s + (if + (i32.lt_s + (get_local $$a$1) + (i32.const 0) + ) + (i32.const -1) (i32.const 0) ) - (i32.const -1) - (i32.const 0) + (i32.const 31) ) - (i32.const 31) - ) - (i32.shl - (if - (i32.lt_s - (get_local $$a$1) + (i32.shl + (if + (i32.lt_s + (get_local $$a$1) + (i32.const 0) + ) + (i32.const -1) (i32.const 0) ) - (i32.const -1) - (i32.const 0) + (i32.const 1) ) - (i32.const 1) ) ) + (get_local $$a$1) ) - (get_local $$a$1) + (get_local $$1$0) + (get_local $$1$1) ) - (get_local $$1$0) - (get_local $$1$1) - ) - (i32.load - (i32.const 168) - ) - (call_import $_i64Subtract - (i32.xor - (set_local $$2$0 - (i32.or - (i32.shr_s - (get_local $$b$1) - (i32.const 31) - ) - (i32.shl - (if - (i32.lt_s - (get_local $$b$1) + (i32.load + (i32.const 168) + ) + (call_import $_i64Subtract + (i32.xor + (tee_local $$2$0 + (i32.or + (i32.shr_s + (get_local $$b$1) + (i32.const 31) + ) + (i32.shl + (if + (i32.lt_s + (get_local $$b$1) + (i32.const 0) + ) + (i32.const -1) (i32.const 0) ) - (i32.const -1) - (i32.const 0) + (i32.const 1) ) - (i32.const 1) ) ) + (get_local $$b$0) ) - (get_local $$b$0) - ) - (i32.xor - (set_local $$2$1 - (i32.or - (i32.shr_s - (if - (i32.lt_s - (get_local $$b$1) + (i32.xor + (tee_local $$2$1 + (i32.or + (i32.shr_s + (if + (i32.lt_s + (get_local $$b$1) + (i32.const 0) + ) + (i32.const -1) (i32.const 0) ) - (i32.const -1) - (i32.const 0) + (i32.const 31) ) - (i32.const 31) - ) - (i32.shl - (if - (i32.lt_s - (get_local $$b$1) + (i32.shl + (if + (i32.lt_s + (get_local $$b$1) + (i32.const 0) + ) + (i32.const -1) (i32.const 0) ) - (i32.const -1) - (i32.const 0) + (i32.const 1) ) - (i32.const 1) ) ) + (get_local $$b$1) ) - (get_local $$b$1) + (get_local $$2$0) + (get_local $$2$1) ) - (get_local $$2$0) - (get_local $$2$1) - ) - (i32.load - (i32.const 168) + (i32.load + (i32.const 168) + ) + (get_local $$rem) ) - (get_local $$rem) ) (set_local $$10$0 (call_import $_i64Subtract @@ -458,7 +587,9 @@ ) (i32.const 1) ) - (get_local $x) + (drop + (get_local $x) + ) (block $waka2 (set_local $x (if @@ -517,8 +648,12 @@ (get_local $r) (get_local $t) ) - (get_local $m) - (get_local $t) + (drop + (get_local $m) + ) + (drop + (get_local $t) + ) ) (func $switch-def (type $5) (param $i3 i32) (result i32) (local $i1 i32) @@ -539,4 +674,32 @@ (get_local $i1) ) ) + (func $no-out-of-label (type $7) (param $x i32) (param $y i32) + (loop $moar + (set_local $x + (block $block0 + (br_if $moar + (get_local $x) + ) + (i32.const 0) + ) + ) + ) + (drop + (get_local $x) + ) + (block $moar + (set_local $y + (block $block1 + (br_if $moar + (get_local $y) + ) + (i32.const 0) + ) + ) + ) + (drop + (get_local $y) + ) + ) ) diff --git a/test/passes/simplify-locals.wast b/test/passes/simplify-locals.wast index 521e8bac4..2b5b84a5f 100644 --- a/test/passes/simplify-locals.wast +++ b/test/passes/simplify-locals.wast @@ -1,153 +1,386 @@ (module (memory 256 256) + (type $FUNCSIG$v (func)) + (type $FUNCSIG$i (func (result i32))) + (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) + (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) + (type $4 (func (param i32))) + (type $5 (func (param i32) (result i32))) + (type $6 (func (param i32 i32 i32 i32 i32 i32))) (import $waka "env" "waka") (import $waka_int "env" "waka_int" (result i32)) (import $_i64Subtract "env" "i64sub" (param i32 i32 i32 i32) (result i32)) (import $___udivmoddi4 "env" "moddi" (param i32 i32 i32 i32 i32) (result i32)) - (func $b0-yes (param $i1 i32) + (func $b0-yes (type $4) (param $i1 i32) (local $x i32) (local $y i32) (local $a i32) (local $b i32) - (set_local $x (i32.const 5)) - (get_local $x) - (block - (set_local $x (i32.const 7)) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (set_local $x + (i32.const 5) + ) + (drop (get_local $x) ) - (set_local $x (i32.const 11)) - (get_local $x) - (set_local $x (i32.const 9)) - (get_local $y) - (block - (set_local $x (i32.const 8)) + (block $block0 + (set_local $x + (i32.const 7) + ) + (drop + (get_local $x) + ) + ) + (set_local $x + (i32.const 11) + ) + (drop + (get_local $x) + ) + (set_local $x + (i32.const 9) + ) + (drop (get_local $y) ) - (set_local $x (i32.const 11)) - (get_local $y) - (set_local $x (i32.const 17)) - (get_local $x) - (get_local $x) - (get_local $x) - (get_local $x) - (get_local $x) - (get_local $x) - (block - (set_local $a (i32.const 1)) - (set_local $b (i32.const 2)) - (get_local $a) - (get_local $b) - (set_local $a (i32.const 3)) - (set_local $b (i32.const 4)) - (set_local $a (i32.const 5)) - (set_local $b (i32.const 6)) - (get_local $b) - (get_local $a) - (set_local $a (i32.const 7)) - (set_local $b (i32.const 8)) - (set_local $a (i32.const 9)) - (set_local $b (i32.const 10)) + (block $block1 + (set_local $x + (i32.const 8) + ) + (drop + (get_local $y) + ) + ) + (set_local $x + (i32.const 11) + ) + (drop + (get_local $y) + ) + (set_local $x + (i32.const 17) + ) + (drop + (get_local $x) + ) + (drop + (get_local $x) + ) + (drop + (get_local $x) + ) + (drop + (get_local $x) + ) + (drop + (get_local $x) + ) + (drop + (get_local $x) + ) + (block $block2 + (set_local $a + (i32.const 1) + ) + (set_local $b + (i32.const 2) + ) + (drop + (get_local $a) + ) + (drop + (get_local $b) + ) + (set_local $a + (i32.const 3) + ) + (set_local $b + (i32.const 4) + ) + (set_local $a + (i32.const 5) + ) + (set_local $b + (i32.const 6) + ) + (drop + (get_local $b) + ) + (drop + (get_local $a) + ) + (set_local $a + (i32.const 7) + ) + (set_local $b + (i32.const 8) + ) + (set_local $a + (i32.const 9) + ) + (set_local $b + (i32.const 10) + ) (call_import $waka) - (get_local $a) - (get_local $b) - (set_local $a (i32.const 11)) - (set_local $b (i32.const 12)) - (set_local $a (i32.const 13)) - (set_local $b (i32.const 14)) - (i32.load - (i32.const 24) + (drop + (get_local $a) + ) + (drop + (get_local $b) + ) + (set_local $a + (i32.const 11) + ) + (set_local $b + (i32.const 12) + ) + (set_local $a + (i32.const 13) + ) + (set_local $b + (i32.const 14) + ) + (drop + (i32.load + (i32.const 24) + ) + ) + (drop + (get_local $a) + ) + (drop + (get_local $b) + ) + (set_local $a + (i32.const 15) + ) + (set_local $b + (i32.const 16) + ) + (set_local $a + (i32.const 17) + ) + (set_local $b + (i32.const 18) ) - (get_local $a) - (get_local $b) - (set_local $a (i32.const 15)) - (set_local $b (i32.const 16)) - (set_local $a (i32.const 17)) - (set_local $b (i32.const 18)) (i32.store (i32.const 48) (i32.const 96) ) - (get_local $a) - (get_local $b) + (drop + (get_local $a) + ) + (drop + (get_local $b) + ) ) - (block - (set_local $a (call_import $waka_int)) - (get_local $a) ;; yes + (block $block3 + (set_local $a + (call_import $waka_int) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (call_import $waka_int)) + (set_local $a + (call_import $waka_int) + ) (call_import $waka) - (get_local $a) ;; no + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (call_import $waka_int)) - (i32.load (i32.const 1)) - (get_local $a) ;; no + (set_local $a + (call_import $waka_int) + ) + (drop + (i32.load + (i32.const 1) + ) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (call_import $waka_int)) - (i32.store (i32.const 1) (i32.const 2)) - (get_local $a) ;; no + (set_local $a + (call_import $waka_int) + ) + (i32.store + (i32.const 1) + (i32.const 2) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.load (i32.const 100))) - (get_local $a) ;; yes + (set_local $a + (i32.load + (i32.const 100) + ) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.load (i32.const 101))) - (i32.load (i32.const 1)) - (get_local $a) ;; yes + (set_local $a + (i32.load + (i32.const 101) + ) + ) + (drop + (i32.load + (i32.const 1) + ) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.load (i32.const 102))) + (set_local $a + (i32.load + (i32.const 102) + ) + ) (call_import $waka) - (get_local $a) ;; no + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.load (i32.const 103))) - (i32.store (i32.const 1) (i32.const 2)) - (get_local $a) ;; no + (set_local $a + (i32.load + (i32.const 103) + ) + ) + (i32.store + (i32.const 1) + (i32.const 2) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.store (i32.const 104) (i32.const 105))) - (get_local $a) ;; yes + (set_local $a + (block + (block + (set_local $5 + (i32.const 105) + ) + (i32.store + (i32.const 104) + (get_local $5) + ) + ) + (get_local $5) + ) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.store (i32.const 106) (i32.const 107))) + (set_local $a + (block + (block + (set_local $6 + (i32.const 107) + ) + (i32.store + (i32.const 106) + (get_local $6) + ) + ) + (get_local $6) + ) + ) (call_import $waka) - (get_local $a) ;; no + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.store (i32.const 108) (i32.const 109))) - (i32.load (i32.const 1)) - (get_local $a) ;; no + (set_local $a + (block + (block + (set_local $7 + (i32.const 109) + ) + (i32.store + (i32.const 108) + (get_local $7) + ) + ) + (get_local $7) + ) + ) + (drop + (i32.load + (i32.const 1) + ) + ) + (drop + (get_local $a) + ) (call_import $waka) - - (set_local $a (i32.store (i32.const 110) (i32.const 111))) - (i32.store (i32.const 1) (i32.const 2)) - (get_local $a) ;; no + (set_local $a + (block + (block + (set_local $8 + (i32.const 111) + ) + (i32.store + (i32.const 110) + (get_local $8) + ) + ) + (get_local $8) + ) + ) + (i32.store + (i32.const 1) + (i32.const 2) + ) + (drop + (get_local $a) + ) (call_import $waka) ) (block $out-of-block - (set_local $a (i32.const 1337)) + (set_local $a + (i32.const 1337) + ) (block $b (block $c (br $b) ) - (set_local $a (i32.const 9876)) + (set_local $a + (i32.const 9876) + ) + ) + (drop + (get_local $a) ) - (get_local $a) ) (block $loopey - (set_local $a (i32.const 1337)) - (loop + (set_local $a + (i32.const 1337) + ) + (drop + (loop $loop-in5 + (drop + (get_local $a) + ) + (tee_local $a + (i32.const 9876) + ) + ) + ) + (drop (get_local $a) - (set_local $a (i32.const 9876)) ) - (get_local $a) ) ) - (func $Ia (param $a i32) (result i32) + (func $Ia (type $5) (param $a i32) (result i32) (local $b i32) (block $switch$0 (block $switch-default$6 @@ -160,7 +393,7 @@ (get_local $b) ) ) - (func $memories (param $i2 i32) (param $i3 i32) (param $bi2 i32) (param $bi3 i32) (param $ci3 i32) (param $di3 i32) + (func $memories (type $6) (param $i2 i32) (param $i3 i32) (param $bi2 i32) (param $bi3 i32) (param $ci3 i32) (param $di3 i32) (local $set_with_no_get i32) (set_local $i3 (i32.const 1) @@ -184,15 +417,19 @@ (get_local $ci3) ) (set_local $di3 - (set_local $bi3 (i32.const 123)) + (tee_local $bi3 + (i32.const 123) + ) ) (i32.store8 (get_local $bi3) (get_local $di3) ) - (set_local $set_with_no_get (i32.const 456)) + (set_local $set_with_no_get + (i32.const 456) + ) ) - (func $___remdi3 (param $$a$0 i32) (param $$a$1 i32) (param $$b$0 i32) (param $$b$1 i32) (result i32) + (func $___remdi3 (type $FUNCSIG$iiiii) (param $$a$0 i32) (param $$a$1 i32) (param $$b$0 i32) (param $$b$1 i32) (result i32) (local $$1$1 i32) (local $$1$0 i32) (local $$rem i32) @@ -325,30 +562,32 @@ (get_local $$1$1) ) ) - (set_local $$4$1 ;; first this moves, then $$4$0 should be able to move + (set_local $$4$1 (i32.load (i32.const 168) ) ) - (call_import $___udivmoddi4 - (get_local $$4$0) - (get_local $$4$1) - (call_import $_i64Subtract - (i32.xor + (drop + (call_import $___udivmoddi4 + (get_local $$4$0) + (get_local $$4$1) + (call_import $_i64Subtract + (i32.xor + (get_local $$2$0) + (get_local $$b$0) + ) + (i32.xor + (get_local $$2$1) + (get_local $$b$1) + ) (get_local $$2$0) - (get_local $$b$0) - ) - (i32.xor (get_local $$2$1) - (get_local $$b$1) ) - (get_local $$2$0) - (get_local $$2$1) - ) - (i32.load - (i32.const 168) + (i32.load + (i32.const 168) + ) + (get_local $$rem) ) - (get_local $$rem) ) (set_local $$10$0 (call_import $_i64Subtract @@ -378,7 +617,7 @@ (get_local $__stackBase__) ) (return - (block + (block $block12 (i32.store (i32.const 168) (get_local $$10$1) @@ -387,46 +626,64 @@ ) ) ) - (func $block-returns + (func $block-returns (type $FUNCSIG$v) (local $x i32) (block $out (block $waka - (set_local $x (i32.const 12)) + (set_local $x + (i32.const 12) + ) (br_if $waka (i32.const 1) ) - (set_local $x (i32.const 34)) + (set_local $x + (i32.const 34) + ) ) - (br_if $out ;; barrier + (br_if $out (i32.const 1) ) - (get_local $x) ;; a use, so setlocals are not all killed + (drop + (get_local $x) + ) (block $waka2 (if (i32.const 1) - (set_local $x (i32.const 13)) - (set_local $x (i32.const 24)) + (set_local $x + (i32.const 13) + ) + (set_local $x + (i32.const 24) + ) ) (if (i32.const 1) - (block - (set_local $x (i32.const 14)) + (block $block3 + (set_local $x + (i32.const 14) + ) ) - (block - (set_local $x (i32.const 25)) + (block $block5 + (set_local $x + (i32.const 25) + ) ) ) ) - (br_if $out ;; barrier + (br_if $out (i32.const 1) ) (block $sink-out-of-me-i-have-but-one-exit - (set_local $x (i32.const 99)) + (set_local $x + (i32.const 99) + ) + ) + (drop + (get_local $x) ) - (get_local $x) ) ) - (func $multiple (param $s i32) (param $r i32) (param $f i32) (param $p i32) (param $t i32) (param $m i32) + (func $multiple (type $6) (param $s i32) (param $r i32) (param $f i32) (param $p i32) (param $t i32) (param $m i32) (set_local $s (get_local $m) ) @@ -436,22 +693,26 @@ (get_local $p) ) ) - (set_local $t ;; t is equal to p's original value; p must not be set to before t gets that value + (set_local $t (get_local $p) ) (set_local $p (i32.load - (i32.const r) + (i32.const 0) ) ) (i32.store (get_local $r) (get_local $t) ) - (get_local $s) - (get_local $t) + (drop + (get_local $s) + ) + (drop + (get_local $t) + ) ) - (func $switch-def (param $i3 i32) (result i32) + (func $switch-def (type $5) (param $i3 i32) (result i32) (local $i1 i32) (set_local $i1 (i32.const 10) @@ -470,5 +731,24 @@ (get_local $i1) ) ) + (func $no-out-of-label (param $x i32) (param $y i32) + (loop $moar + (set_local $x + (block + (br_if $moar (get_local $x)) + (i32.const 0) + ) + ) + ) + (drop (get_local $x)) + (block $moar + (set_local $y + (block + (br_if $moar (get_local $y)) + (i32.const 0) + ) + ) + ) + (drop (get_local $y)) + ) ) - diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt index 7fa247bdd..1adcc3e6f 100644 --- a/test/passes/vacuum.txt +++ b/test/passes/vacuum.txt @@ -5,6 +5,8 @@ (type $2 (func (result f32))) (type $3 (func (result i32))) (type $4 (func (param i32 f64 i32 i32))) + (type $FUNCSIG$i (func (result i32))) + (import "env" "int" (func $int (result i32))) (func $b (type $0) (nop) ) @@ -39,8 +41,18 @@ ) ) (func $binary (type $2) (result f32) - (unreachable) - (unreachable) + (drop + (f32.add + (unreachable) + (f32.const 3) + ) + ) + (drop + (f32.add + (f32.const 4) + (unreachable) + ) + ) (f32.add (unreachable) (unreachable) @@ -51,23 +63,45 @@ ) ) (func $select (type $3) (result i32) - (unreachable) - (unreachable) - (unreachable) + (drop + (select + (unreachable) + (i32.const 4) + (i32.const 5) + ) + ) + (drop + (select + (i32.const 6) + (unreachable) + (i32.const 7) + ) + ) + (drop + (select + (i32.const 8) + (i32.const 9) + (unreachable) + ) + ) (select (unreachable) (unreachable) (i32.const 10) ) - (select - (unreachable) - (i32.const 11) - (unreachable) + (drop + (select + (unreachable) + (i32.const 11) + (unreachable) + ) ) - (select - (i32.const 12) - (unreachable) - (unreachable) + (drop + (select + (i32.const 12) + (unreachable) + (unreachable) + ) ) (select (unreachable) @@ -110,7 +144,7 @@ (f64.ne (f64.promote/f32 (f32.load - (set_local $l + (tee_local $l (i32.add (get_local $b) (i32.const 60) @@ -126,4 +160,22 @@ (unreachable) ) ) + (func $if-drop (type $0) + (block $out + (if + (i32.const 0) + (drop + (call_import $int) + ) + (br $out) + ) + (if + (i32.const 1) + (br $out) + (drop + (call_import $int) + ) + ) + ) + ) ) diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast index a6f713123..3630512b4 100644 --- a/test/passes/vacuum.wast +++ b/test/passes/vacuum.wast @@ -1,36 +1,60 @@ (module (memory 256 256) - (func $b - (i32.const 50) + (type $0 (func)) + (type $1 (func (param i32))) + (type $2 (func (result f32))) + (type $3 (func (result i32))) + (type $4 (func (param i32 f64 i32 i32))) + (import $int "env" "int" (result i32)) + (func $b (type $0) + (drop + (i32.const 50) + ) (nop) - (i32.const 51) + (drop + (i32.const 51) + ) (nop) (nop) - (i32.const 52) + (drop + (i32.const 52) + ) (block $waka1 - (i32.const 53) + (drop + (i32.const 53) + ) (br $waka1) - (i32.const 54) + (drop + (i32.const 54) + ) ) (block $waka2 (nop) (br $waka2) - (i32.const 56) + (drop + (i32.const 56) + ) ) (block $waka3 (br_table $waka3 $waka3 $waka3 (i32.const 57) ) - (i32.const 58) + (drop + (i32.const 58) + ) ) (if (i32.const 100) (nop) - (i32.const 101) + (drop + (i32.const 101) + ) ) (if (i32.const 102) - (i32.const 103) + (drop + (i32.const 103) + ) (nop) ) (if @@ -39,17 +63,27 @@ (nop) ) ) - (func $l + (func $l (type $0) (local $x i32) (local $y i32) - (get_local $x) - (set_local $x (get_local $x)) - (block $in-a-block + (drop (get_local $x) ) - (block $two-in-a-block + (set_local $x (get_local $x) - (get_local $y) + ) + (block $in-a-block + (drop + (get_local $x) + ) + ) + (block $two-in-a-block + (drop + (get_local $x) + ) + (drop + (get_local $y) + ) ) (set_local $x (block $result-used @@ -58,82 +92,197 @@ ) (set_local $x (block $two-and-result-used - (get_local $x) + (drop + (get_local $x) + ) (get_local $y) ) ) ) - (func $loopy (param $0 i32) - (loop (nop)) - (loop + (func $loopy (type $1) (param $0 i32) + (loop $loop-in1 + (nop) + ) + (loop $loop-in3 (nop) (nop) ) - (loop - (get_local $0) - (i32.const 20) + (drop + (loop $loop-in5 + (drop + (get_local $0) + ) + (i32.const 20) + ) ) ) - (func $unary (result f32) - (f32.abs (f32.const 1.0)) ;; unneeded position - (f32.abs (unreachable)) ;; side effects - - (f32.abs (f32.const 2.0)) ;; return position + (func $unary (type $2) (result f32) + (drop + (f32.abs + (f32.const 1) + ) + ) + (f32.abs + (unreachable) + ) + (f32.abs + (f32.const 2) + ) ) - (func $binary (result f32) - (f32.add (f32.const 1.0) (f32.const 2.0)) - (f32.add (unreachable) (f32.const 3.0)) - (f32.add (f32.const 4.0) (unreachable)) - (f32.add (unreachable) (unreachable)) - - (f32.add (f32.const 5.0) (f32.const 6.0)) + (func $binary (type $2) (result f32) + (drop + (f32.add + (f32.const 1) + (f32.const 2) + ) + ) + (drop + (f32.add + (unreachable) + (f32.const 3) + ) + ) + (drop + (f32.add + (f32.const 4) + (unreachable) + ) + ) + (f32.add + (unreachable) + (unreachable) + ) + (f32.add + (f32.const 5) + (f32.const 6) + ) ) - (func $select (result i32) - (select (i32.const 1) (i32.const 2) (i32.const 3)) - (select (unreachable) (i32.const 4) (i32.const 5)) - (select (i32.const 6) (unreachable) (i32.const 7)) - (select (i32.const 8) (i32.const 9) (unreachable)) - (select (unreachable) (unreachable) (i32.const 10)) - (select (unreachable) (i32.const 11) (unreachable)) - (select (i32.const 12) (unreachable) (unreachable)) - (select (unreachable) (unreachable) (unreachable)) - - (select (i32.const 13) (i32.const 14) (i32.const 15)) + (func $select (type $3) (result i32) + (drop + (select + (i32.const 1) + (i32.const 2) + (i32.const 3) + ) + ) + (drop + (select + (unreachable) + (i32.const 4) + (i32.const 5) + ) + ) + (drop + (select + (i32.const 6) + (unreachable) + (i32.const 7) + ) + ) + (drop + (select + (i32.const 8) + (i32.const 9) + (unreachable) + ) + ) + (select + (unreachable) + (unreachable) + (i32.const 10) + ) + (drop + (select + (unreachable) + (i32.const 11) + (unreachable) + ) + ) + (drop + (select + (i32.const 12) + (unreachable) + (unreachable) + ) + ) + (select + (unreachable) + (unreachable) + (unreachable) + ) + (select + (i32.const 13) + (i32.const 14) + (i32.const 15) + ) ) - (func $block-to-one - (block - (nop) (nop) + (func $block-to-one (type $0) + (block $block0 + (nop) + (nop) ) - (block - (nop) (unreachable) + (block $block1 + (nop) + (unreachable) ) - (block - (nop) (unreachable) (nop) + (block $block2 + (nop) + (unreachable) + (nop) ) - (block - (unreachable) (nop) + (block $block3 + (unreachable) + (nop) ) - (block + (block $block4 (unreachable) ) ) - (func $recurse + (func $recurse (type $0) (nop) - (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.const 1.0) ) ) ) ) ) ) + (drop + (f32.abs + (f32.abs + (f32.abs + (f32.abs + (f32.abs + (f32.abs + (f32.const 1) + ) + ) + ) + ) + ) + ) + ) ) - (func $func-block - (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.abs (f32.const 1.0) ) ) ) ) ) ) + (func $func-block (type $0) + (drop + (f32.abs + (f32.abs + (f32.abs + (f32.abs + (f32.abs + (f32.abs + (f32.const 1) + ) + ) + ) + ) + ) + ) + ) ) - (func $Gu (param $b i32) (param $e f64) (param $l i32) (param $d i32) - (if ;; if condition must remain valid + (func $Gu (type $4) (param $b i32) (param $e f64) (param $l i32) (param $d i32) + (if (if (get_local $d) - (block + (block $block1 (nop) (f64.ne (f64.promote/f32 (f32.load - (set_local $l + (tee_local $l (i32.add (get_local $b) (i32.const 60) @@ -149,5 +298,20 @@ (unreachable) ) ) + (func $if-drop + (block $out + (drop + (if (i32.const 0) + (call_import $int) + (br $out) + ) + ) + (drop + (if (i32.const 1) + (br $out) + (call_import $int) + ) + ) + ) + ) ) - |