diff options
-rw-r--r-- | src/passes/Vacuum.cpp | 5 | ||||
-rw-r--r-- | test/passes/remove-unused-names_vacuum_ignore-implicit-traps.txt | 52 | ||||
-rw-r--r-- | test/passes/remove-unused-names_vacuum_ignore-implicit-traps.wast | 81 |
3 files changed, 137 insertions, 1 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 43a5f8a09..0e01c0370 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -96,9 +96,12 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> { // it is ok to remove a load if the result is not used, and it has no // side effects (the load itself may trap, if we are not ignoring such // things) + auto* load = curr->cast<Load>(); if (!resultUsed && !EffectAnalyzer(getPassOptions(), curr).hasSideEffects()) { - return curr->cast<Load>()->ptr; + if (!typeMatters || load->ptr->type == type) { + return load->ptr; + } } return curr; } diff --git a/test/passes/remove-unused-names_vacuum_ignore-implicit-traps.txt b/test/passes/remove-unused-names_vacuum_ignore-implicit-traps.txt new file mode 100644 index 000000000..2a4b8e490 --- /dev/null +++ b/test/passes/remove-unused-names_vacuum_ignore-implicit-traps.txt @@ -0,0 +1,52 @@ +(module + (type $0 (func)) + (type $FUNCSIG$j (func (result i32))) + (type $FUNCSIG$i (func (result i32))) + (type $legaltype$wasm2js_scratch_load_i64 (func (result i32))) + (type $FUNCSIG$vj (func (param i32 i32))) + (type $legaltype$wasm2js_scratch_store_i64 (func (param i32 i32))) + (type $FUNCSIG$ii (func (param i32) (result i32))) + (type $FUNCSIG$vii (func (param i32 i32))) + (type $FUNCSIG$f (func (result f32))) + (type $FUNCSIG$vf (func (param f32))) + (type $FUNCSIG$d (func (result f64))) + (type $FUNCSIG$vd (func (param f64))) + (import "env" "wasm2js_scratch_load_i32" (func $wasm2js_scratch_load_i32 (param i32) (result i32))) + (import "env" "wasm2js_scratch_store_i32" (func $wasm2js_scratch_store_i32 (param i32 i32))) + (import "env" "wasm2js_scratch_load_f32" (func $wasm2js_scratch_load_f32 (result f32))) + (import "env" "wasm2js_scratch_store_f32" (func $wasm2js_scratch_store_f32 (param f32))) + (import "env" "wasm2js_scratch_load_f64" (func $wasm2js_scratch_load_f64 (result f64))) + (import "env" "wasm2js_scratch_store_f64" (func $wasm2js_scratch_store_f64 (param f64))) + (import "env" "getTempRet0" (func $getTempRet0 (result i32))) + (import "env" "wasm2js_scratch_load_i64" (func $legalimport$wasm2js_scratch_load_i64 (result i32))) + (import "env" "wasm2js_scratch_store_i64" (func $legalimport$wasm2js_scratch_store_i64 (param i32 i32))) + (import "env" "wasm2js_scratch_load_i64" (func $wasm2js_scratch_load_i64 (result i32))) + (import "env" "wasm2js_scratch_store_i64" (func $wasm2js_scratch_store_i64 (param i32 i32))) + (memory $0 1 1) + (global $i64toi32_i32$HIGH_BITS (mut i32) (i32.const 0)) + (func $0 (; 11 ;) (type $0) + (local $0 f64) + (local $1 i32) + (nop) + ) + (func $legalfunc$wasm2js_scratch_load_i64 (; 12 ;) (type $FUNCSIG$j) (result i32) + (local $0 i32) + (local $1 i32) + (local.set $1 + (i32.or + (call $legalimport$wasm2js_scratch_load_i64) + (i32.const 0) + ) + ) + (global.set $i64toi32_i32$HIGH_BITS + (call $getTempRet0) + ) + (local.get $1) + ) + (func $legalfunc$wasm2js_scratch_store_i64 (; 13 ;) (type $FUNCSIG$vj) (param $0 i32) (param $1 i32) + (call $legalimport$wasm2js_scratch_store_i64 + (local.get $0) + (local.get $1) + ) + ) +) diff --git a/test/passes/remove-unused-names_vacuum_ignore-implicit-traps.wast b/test/passes/remove-unused-names_vacuum_ignore-implicit-traps.wast new file mode 100644 index 000000000..532fdc7c8 --- /dev/null +++ b/test/passes/remove-unused-names_vacuum_ignore-implicit-traps.wast @@ -0,0 +1,81 @@ +(module + (type $0 (func)) + (type $FUNCSIG$j (func (result i32))) + (type $FUNCSIG$i (func (result i32))) + (type $legaltype$wasm2js_scratch_load_i64 (func (result i32))) + (type $FUNCSIG$vj (func (param i32 i32))) + (type $legaltype$wasm2js_scratch_store_i64 (func (param i32 i32))) + (import "env" "wasm2js_scratch_load_i32" (func $wasm2js_scratch_load_i32 (param i32) (result i32))) + (import "env" "wasm2js_scratch_store_i32" (func $wasm2js_scratch_store_i32 (param i32 i32))) + (import "env" "wasm2js_scratch_load_f32" (func $wasm2js_scratch_load_f32 (result f32))) + (import "env" "wasm2js_scratch_store_f32" (func $wasm2js_scratch_store_f32 (param f32))) + (import "env" "wasm2js_scratch_load_f64" (func $wasm2js_scratch_load_f64 (result f64))) + (import "env" "wasm2js_scratch_store_f64" (func $wasm2js_scratch_store_f64 (param f64))) + (import "env" "getTempRet0" (func $getTempRet0 (result i32))) + (import "env" "wasm2js_scratch_load_i64" (func $legalimport$wasm2js_scratch_load_i64 (result i32))) + (import "env" "wasm2js_scratch_store_i64" (func $legalimport$wasm2js_scratch_store_i64 (param i32 i32))) + (import "env" "wasm2js_scratch_load_i64" (func $wasm2js_scratch_load_i64 (result i64))) + (import "env" "wasm2js_scratch_store_i64" (func $wasm2js_scratch_store_i64 (param i64))) + (memory $0 1 1) + (global $i64toi32_i32$HIGH_BITS (mut i32) (i32.const 0)) + (func $0 (; 11 ;) (type $0) + (local $0 f64) + (local $1 i32) + (block $label$1 + (block + (nop) + (drop + (if (result f64) + (i32.const 1) + (block (result f64) + (nop) + (f64.load + (i32.const 19) + ) + ) + (block + (drop + (f64.const 1) + ) + (br $label$1) + (nop) + ) + ) + ) + ) + (nop) + ) + ) + (func $legalfunc$wasm2js_scratch_load_i64 (; 12 ;) (result i32) + (local $0 i32) + (local $1 i32) + (local.set $1 + (i32.or + (call $legalimport$wasm2js_scratch_load_i64) + (block (result i32) + (nop) + (block (result i32) + (nop) + (i32.const 0) + ) + ) + ) + ) + (global.set $i64toi32_i32$HIGH_BITS + (call $getTempRet0) + ) + (local.get $1) + ) + (func $legalfunc$wasm2js_scratch_store_i64 (; 13 ;) (param $0 i32) (param $1 i32) + (call $legalimport$wasm2js_scratch_store_i64 + (block (result i32) + (nop) + (local.get $0) + ) + (block (result i32) + (nop) + (local.get $1) + ) + ) + ) +) |