diff options
-rw-r--r-- | src/asm2wasm.h | 6 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm | 28 | ||||
-rw-r--r-- | test/emcc_hello_world.fromasm.imprecise | 28 | ||||
-rw-r--r-- | test/unit.asm.js | 21 | ||||
-rw-r--r-- | test/unit.fromasm | 22 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 22 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise.no-opts | 60 | ||||
-rw-r--r-- | test/unit.fromasm.no-opts | 60 |
8 files changed, 213 insertions, 34 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 6c3fcd8cf..84db006c4 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -807,8 +807,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) { passRunner.add<ReFinalize>(); // FinalizeCalls changes call types, need to percolate passRunner.add<AutoDrop>(); // FinalizeCalls may cause us to require additional drops if (optimize) { - passRunner.add("vacuum"); // autodrop can add some garbage - passRunner.add("remove-unused-brs"); // vacuum may open up more opportunities + // autodrop can add some garbage + passRunner.add("vacuum"); + passRunner.add("remove-unused-brs"); + passRunner.add("optimize-instructions"); } passRunner.run(); diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm index 575a33d1c..ec5237261 100644 --- a/test/emcc_hello_world.fromasm +++ b/test/emcc_hello_world.fromasm @@ -403,16 +403,14 @@ ) ) (br_if $while-in$1 - (i32.eqz - (i32.eq - (tee_local $2 - (i32.add - (get_local $2) - (i32.const 1) - ) + (i32.ne + (tee_local $2 + (i32.add + (get_local $2) + (i32.const 1) ) - (i32.const 87) ) + (i32.const 87) ) ) (block @@ -5951,14 +5949,12 @@ ) ) (br_if $while-in$95 - (i32.eqz - (i32.lt_u - (get_local $13) - (tee_local $8 - (i32.mul - (get_local $8) - (i32.const 10) - ) + (i32.ge_u + (get_local $13) + (tee_local $8 + (i32.mul + (get_local $8) + (i32.const 10) ) ) ) diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise index 249892261..f42a477ba 100644 --- a/test/emcc_hello_world.fromasm.imprecise +++ b/test/emcc_hello_world.fromasm.imprecise @@ -396,16 +396,14 @@ ) ) (br_if $while-in$1 - (i32.eqz - (i32.eq - (tee_local $2 - (i32.add - (get_local $2) - (i32.const 1) - ) + (i32.ne + (tee_local $2 + (i32.add + (get_local $2) + (i32.const 1) ) - (i32.const 87) ) + (i32.const 87) ) ) (block @@ -5944,14 +5942,12 @@ ) ) (br_if $while-in$95 - (i32.eqz - (i32.lt_u - (get_local $13) - (tee_local $8 - (i32.mul - (get_local $8) - (i32.const 10) - ) + (i32.ge_u + (get_local $13) + (tee_local $8 + (i32.mul + (get_local $8) + (i32.const 10) ) ) ) diff --git a/test/unit.asm.js b/test/unit.asm.js index c87bb62c6..7280224ae 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -9,6 +9,7 @@ function asm(global, env, buffer) { var Math_ceil = global.Math.ceil; var tempDoublePtr = env.tempDoublePtr | 0; var n = env.gb | 0; + var STACKTOP = env.STACKTOP | 0; var setTempRet0=env.setTempRet0; var abort = env.abort; @@ -415,6 +416,26 @@ function asm(global, env, buffer) { return i$lcssa | 0 } + function optimize_exprs_at_end($e) { + $e = $e|0; + var $0 = 0, $1 = 0, $arrayidx = 0, $cmp = 0, $conv = 0, $dec = 0, $i$012 = 0, $i$012$lcssa = 0, $i$111 = 0, $inc = 0, $incdec$ptr = 0, $incdec$ptr$lcssa = 0, $s$0$lcssa = 0, $s$010 = 0, $s$1 = 0, $tobool = 0, $tobool5 = 0, $tobool5$9 = 0, $tobool8 = 0, label = 0; + while(1) { + if ($cmp) { + break; + } + $inc = $i$012; + $tobool = ($inc|0)==1; + if ($tobool) { + label = 5; + break; + } else { + $i$012 = $inc; + } + } + if ((label|0) == 2) { + } + } + 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 dd47ae812..c5e8b9ac4 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -13,6 +13,7 @@ (import "global" "Infinity" (global $u f64)) (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) (import "env" "gb" (global $n i32)) + (import "env" "STACKTOP" (global $STACKTOP i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -786,4 +787,25 @@ ) (get_local $1) ) + (func $optimize_exprs_at_end (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (loop $while-in$1 + (block $while-out$0 + (br_if $while-out$0 + (get_local $1) + ) + (br_if $while-in$1 + (i32.ne + (get_local $2) + (i32.const 1) + ) + ) + (set_local $3 + (i32.const 5) + ) + ) + ) + ) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index a1980e06c..d38321636 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -10,6 +10,7 @@ (import "global" "Infinity" (global $u f64)) (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) (import "env" "gb" (global $n i32)) + (import "env" "STACKTOP" (global $STACKTOP i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -767,4 +768,25 @@ ) (get_local $1) ) + (func $optimize_exprs_at_end (param $0 i32) + (local $1 i32) + (local $2 i32) + (local $3 i32) + (loop $while-in$1 + (block $while-out$0 + (br_if $while-out$0 + (get_local $1) + ) + (br_if $while-in$1 + (i32.ne + (get_local $2) + (i32.const 1) + ) + ) + (set_local $3 + (i32.const 5) + ) + ) + ) + ) ) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index b14ba5011..c46cc19c2 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -10,6 +10,7 @@ (import "global" "Infinity" (global $u f64)) (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) (import "env" "gb" (global $n i32)) + (import "env" "STACKTOP" (global $STACKTOP i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -1249,4 +1250,63 @@ (get_local $i$lcssa) ) ) + (func $optimize_exprs_at_end (param $$e i32) + (local $$0 i32) + (local $$1 i32) + (local $$arrayidx i32) + (local $$cmp i32) + (local $$conv i32) + (local $$dec i32) + (local $$i$012 i32) + (local $$i$012$lcssa i32) + (local $$i$111 i32) + (local $$inc i32) + (local $$incdec$ptr i32) + (local $$incdec$ptr$lcssa i32) + (local $$s$0$lcssa i32) + (local $$s$010 i32) + (local $$s$1 i32) + (local $$tobool i32) + (local $$tobool5 i32) + (local $$tobool5$9 i32) + (local $$tobool8 i32) + (local $label i32) + (loop $while-in$1 + (block $while-out$0 + (if + (get_local $$cmp) + (br $while-out$0) + ) + (set_local $$inc + (get_local $$i$012) + ) + (set_local $$tobool + (i32.eq + (get_local $$inc) + (i32.const 1) + ) + ) + (if + (get_local $$tobool) + (block + (set_local $label + (i32.const 5) + ) + (br $while-out$0) + ) + (set_local $$i$012 + (get_local $$inc) + ) + ) + (br $while-in$1) + ) + ) + (if + (i32.eq + (get_local $label) + (i32.const 2) + ) + (nop) + ) + ) ) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index c71478ff8..e5e34c1ec 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -12,6 +12,7 @@ (import "global" "Infinity" (global $u f64)) (import "env" "tempDoublePtr" (global $tempDoublePtr i32)) (import "env" "gb" (global $n i32)) + (import "env" "STACKTOP" (global $STACKTOP i32)) (import "env" "setTempRet0" (func $setTempRet0 (param i32) (result i32))) (import "env" "abort" (func $abort (param f64) (result f64))) (import "env" "print" (func $print (param i32))) @@ -1255,4 +1256,63 @@ (get_local $i$lcssa) ) ) + (func $optimize_exprs_at_end (param $$e i32) + (local $$0 i32) + (local $$1 i32) + (local $$arrayidx i32) + (local $$cmp i32) + (local $$conv i32) + (local $$dec i32) + (local $$i$012 i32) + (local $$i$012$lcssa i32) + (local $$i$111 i32) + (local $$inc i32) + (local $$incdec$ptr i32) + (local $$incdec$ptr$lcssa i32) + (local $$s$0$lcssa i32) + (local $$s$010 i32) + (local $$s$1 i32) + (local $$tobool i32) + (local $$tobool5 i32) + (local $$tobool5$9 i32) + (local $$tobool8 i32) + (local $label i32) + (loop $while-in$1 + (block $while-out$0 + (if + (get_local $$cmp) + (br $while-out$0) + ) + (set_local $$inc + (get_local $$i$012) + ) + (set_local $$tobool + (i32.eq + (get_local $$inc) + (i32.const 1) + ) + ) + (if + (get_local $$tobool) + (block + (set_local $label + (i32.const 5) + ) + (br $while-out$0) + ) + (set_local $$i$012 + (get_local $$inc) + ) + ) + (br $while-in$1) + ) + ) + (if + (i32.eq + (get_local $label) + (i32.const 2) + ) + (nop) + ) + ) ) |