diff options
-rw-r--r-- | src/passes/CoalesceLocals.cpp | 4 | ||||
-rw-r--r-- | test/passes/coalesce-locals.txt | 31 | ||||
-rw-r--r-- | test/passes/coalesce-locals.wast | 30 |
3 files changed, 64 insertions, 1 deletions
diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp index 87eefb85c..5ab68da23 100644 --- a/src/passes/CoalesceLocals.cpp +++ b/src/passes/CoalesceLocals.cpp @@ -597,11 +597,13 @@ void CoalesceLocals::pickIndices(std::vector<Index>& indices) { // Remove a copy from a set of an if, where one if arm is a get of the same set static void removeIfCopy(Expression** origin, SetLocal* set, If* iff, Expression*& copy, Expression*& other, Module* module) { // replace the origin with the if, and sink the set into the other non-copying arm + bool tee = set->isTee(); *origin = iff; set->value = other; set->finalize(); other = set; - if (!isConcreteWasmType(set->type)) { + // if this is not a tee, then we can get rid of the copy in that arm + if (!tee) { // we don't need the copy at all copy = nullptr; if (!iff->ifTrue) { diff --git a/test/passes/coalesce-locals.txt b/test/passes/coalesce-locals.txt index ed6838ae8..32da026ac 100644 --- a/test/passes/coalesce-locals.txt +++ b/test/passes/coalesce-locals.txt @@ -7,6 +7,7 @@ (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $7 (func (param i32) (result i32))) + (type $8 (func (param f64 i32) (result i64))) (import "env" "_emscripten_autodebug_i32" (func $_emscripten_autodebug_i32 (param i32 i32) (result i32))) (import "env" "get" (func $get (result i32))) (import "env" "set" (func $set (param i32))) @@ -1122,4 +1123,34 @@ ) ) ) + (func $tee_if_with_unreachable_else (type $8) (param $0 f64) (param $1 i32) (result i64) + (call $tee_if_with_unreachable_else + (if (result f64) + (get_local $1) + (get_local $0) + (tee_local $0 + (unreachable) + ) + ) + (f64.lt + (f64.const -128) + (get_local $0) + ) + ) + ) + (func $tee_if_with_unreachable_true (type $8) (param $0 f64) (param $1 i32) (result i64) + (call $tee_if_with_unreachable_else + (if (result f64) + (get_local $1) + (tee_local $0 + (unreachable) + ) + (get_local $0) + ) + (f64.lt + (f64.const -128) + (get_local $0) + ) + ) + ) ) diff --git a/test/passes/coalesce-locals.wast b/test/passes/coalesce-locals.wast index d959cc820..ee92bb05e 100644 --- a/test/passes/coalesce-locals.wast +++ b/test/passes/coalesce-locals.wast @@ -1097,4 +1097,34 @@ ) ) ) + (func $tee_if_with_unreachable_else (param $0 f64) (param $1 i32) (result i64) + (call $tee_if_with_unreachable_else + (tee_local $0 + (if (result f64) + (get_local $1) + (get_local $0) + (unreachable) + ) + ) + (f64.lt + (f64.const -128) + (get_local $0) + ) + ) + ) + (func $tee_if_with_unreachable_true (param $0 f64) (param $1 i32) (result i64) + (call $tee_if_with_unreachable_else + (tee_local $0 + (if (result f64) + (get_local $1) + (unreachable) + (get_local $0) + ) + ) + (f64.lt + (f64.const -128) + (get_local $0) + ) + ) + ) ) |