From 8f897c7d5543fd1529b8279801ddbb59ffff7f1b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 23 Sep 2016 15:14:34 -0700 Subject: autoDrop fix --- test/unit.asm.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/unit.asm.js') diff --git a/test/unit.asm.js b/test/unit.asm.js index d4426bd90..931a75191 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -572,6 +572,21 @@ function asm(global, env, buffer) { return temp | 0; } + function dropIgnoredImportInIf($0,$1,$2) { + $0 = $0|0; + $1 = $1|0; + $2 = $2|0; + do { + if ($0) { + $0 = 1; + lb($2 | 0) | 0; + } else { + break; + } + } while(0); + return; + } + var FUNCTION_TABLE_a = [ z, big_negative, z, z ]; var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ]; var FUNCTION_TABLE_c = [ z, cneg ]; -- cgit v1.2.3 From 8ef9aafab1a2c47f9a09c8e64636da570870dc00 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 23 Sep 2016 15:35:58 -0700 Subject: replace two drops in an if-else with one on the if --- src/passes/Vacuum.cpp | 9 +++++++-- test/passes/vacuum.txt | 10 ++++++++++ test/passes/vacuum.wast | 12 ++++++++++++ test/unit.asm.js | 14 ++++++++++++++ test/unit.fromasm | 13 +++++++++++++ test/unit.fromasm.imprecise | 13 +++++++++++++ test/unit.fromasm.imprecise.no-opts | 19 +++++++++++++++++++ test/unit.fromasm.no-opts | 19 +++++++++++++++++++ 8 files changed, 107 insertions(+), 2 deletions(-) (limited to 'test/unit.asm.js') diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 0fdd12dec..03becb04c 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -193,9 +193,14 @@ struct Vacuum : public WalkerPass> curr->ifTrue = curr->ifFalse; curr->ifFalse = nullptr; curr->condition = Builder(*getModule()).makeUnary(EqZInt32, curr->condition); + } else if (curr->ifTrue->is() && curr->ifFalse->is()) { + // instead of dropping both sides, drop the if + curr->ifTrue = curr->ifTrue->cast()->value; + curr->ifFalse = curr->ifFalse->cast()->value; + curr->finalize(); + replaceCurrent(Builder(*getModule()).makeDrop(curr)); } - } - if (!curr->ifFalse) { + } else { // no else if (curr->ifTrue->is()) { // no nothing diff --git a/test/passes/vacuum.txt b/test/passes/vacuum.txt index c2fb9fc29..6b5d63b2a 100644 --- a/test/passes/vacuum.txt +++ b/test/passes/vacuum.txt @@ -207,4 +207,14 @@ (func $relooperJumpThreading3 (type $0) (nop) ) + (func $if2drops (type $3) (result i32) + (drop + (if + (i32.const 1) + (call $if2drops) + (call $if2drops) + ) + ) + (i32.const 2) + ) ) diff --git a/test/passes/vacuum.wast b/test/passes/vacuum.wast index ecc176385..3584df3ff 100644 --- a/test/passes/vacuum.wast +++ b/test/passes/vacuum.wast @@ -412,4 +412,16 @@ ) ) ) + (func $if2drops (result i32) + (if + (i32.const 1) + (drop + (call $if2drops) + ) + (drop + (call $if2drops) + ) + ) + (i32.const 2) + ) ) diff --git a/test/unit.asm.js b/test/unit.asm.js index 931a75191..7b4b2a96f 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -587,6 +587,20 @@ function asm(global, env, buffer) { return; } + function dropIgnoredImportsInIf($0,$1,$2) { + $0 = $0|0; + $1 = $1|0; + $2 = $2|0; + do { + if ($0) { + lb($1 | 0) | 0; + } else { + lb($2 | 0) | 0; + } + } while(0); + return; + } + var FUNCTION_TABLE_a = [ z, big_negative, z, z ]; var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ]; var FUNCTION_TABLE_c = [ z, cneg ]; diff --git a/test/unit.fromasm b/test/unit.fromasm index c4af783eb..123e087e6 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -1031,4 +1031,17 @@ ) ) ) + (func $dropIgnoredImportsInIf (param $0 i32) (param $1 i32) (param $2 i32) + (drop + (if + (get_local $0) + (call $lb + (get_local $1) + ) + (call $lb + (get_local $2) + ) + ) + ) + ) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 91e75d5c6..b170c8b82 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -1012,4 +1012,17 @@ ) ) ) + (func $dropIgnoredImportsInIf (param $0 i32) (param $1 i32) (param $2 i32) + (drop + (if + (get_local $0) + (call $lb + (get_local $1) + ) + (call $lb + (get_local $2) + ) + ) + ) + ) ) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index ffcd9f449..913920f8b 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -1644,4 +1644,23 @@ ) (return) ) + (func $dropIgnoredImportsInIf (param $$0 i32) (param $$1 i32) (param $$2 i32) + (block $do-once$0 + (if + (get_local $$0) + (drop + (call $lb + (get_local $$1) + ) + ) + (drop + (call $lb + (get_local $$2) + ) + ) + ) + (nop) + ) + (return) + ) ) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index a8ca0e47a..21e7ea79e 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -1650,4 +1650,23 @@ ) (return) ) + (func $dropIgnoredImportsInIf (param $$0 i32) (param $$1 i32) (param $$2 i32) + (block $do-once$0 + (if + (get_local $$0) + (drop + (call $lb + (get_local $$1) + ) + ) + (drop + (call $lb + (get_local $$2) + ) + ) + ) + (nop) + ) + (return) + ) ) -- cgit v1.2.3