summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/CoalesceLocals.cpp8
-rw-r--r--test/passes/coalesce-locals-learning.txt8
-rw-r--r--test/passes/coalesce-locals.txt49
-rw-r--r--test/passes/coalesce-locals.wast10
4 files changed, 61 insertions, 14 deletions
diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp
index fb81a5981..b36542a97 100644
--- a/src/passes/CoalesceLocals.cpp
+++ b/src/passes/CoalesceLocals.cpp
@@ -168,9 +168,13 @@ struct CoalesceLocals : public WalkerPass<CFGWalker<CoalesceLocals, Visitor<Coal
static void doVisitSetLocal(CoalesceLocals* self, Expression** currp) {
auto* curr = (*currp)->cast<SetLocal>();
- // if in unreachable code, ignore
+ // if in unreachable code, we don't need the tee (but might need the value, if it has side effects)
if (!self->currBasicBlock) {
- *currp = Builder(*self->getModule()).replaceWithIdenticalType(curr);
+ if (curr->isTee()) {
+ *currp = curr->value;
+ } else {
+ *currp = Builder(*self->getModule()).makeDrop(curr->value);
+ }
return;
}
self->currBasicBlock->contents.actions.emplace_back(Action::Set, curr->index, currp);
diff --git a/test/passes/coalesce-locals-learning.txt b/test/passes/coalesce-locals-learning.txt
index 3bd04680d..2377c4051 100644
--- a/test/passes/coalesce-locals-learning.txt
+++ b/test/passes/coalesce-locals-learning.txt
@@ -108,11 +108,15 @@
)
(block $block
(br $block)
- (nop)
(drop
(i32.const 0)
)
- (nop)
+ (drop
+ (i32.const 0)
+ )
+ (drop
+ (i32.const -1)
+ )
)
(drop
(get_local $0)
diff --git a/test/passes/coalesce-locals.txt b/test/passes/coalesce-locals.txt
index 8f2908153..f8dc3ef0f 100644
--- a/test/passes/coalesce-locals.txt
+++ b/test/passes/coalesce-locals.txt
@@ -6,6 +6,7 @@
(type $4 (func (param i32)))
(type $FUNCSIG$i (func (result i32)))
(type $FUNCSIG$vi (func (param i32)))
+ (type $7 (func (param i32) (result i32)))
(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)))
@@ -112,11 +113,15 @@
)
(block $block
(br $block)
- (nop)
(drop
(i32.const 0)
)
- (nop)
+ (drop
+ (i32.const 0)
+ )
+ (drop
+ (i32.const -1)
+ )
)
(drop
(get_local $0)
@@ -902,37 +907,53 @@
(local $0 i32)
(block $x
(return)
- (nop)
+ (drop
+ (i32.const 1)
+ )
+ (drop
+ (i32.const 0)
+ )
(drop
(i32.const 0)
)
- (nop)
)
(block $y
(unreachable)
- (nop)
+ (drop
+ (i32.const 1)
+ )
+ (drop
+ (i32.const 0)
+ )
(drop
(i32.const 0)
)
- (nop)
)
(block $z
(br $z)
- (nop)
+ (drop
+ (i32.const 1)
+ )
+ (drop
+ (i32.const 0)
+ )
(drop
(i32.const 0)
)
- (nop)
)
(block $z14
(br_table $z14 $z14
(i32.const 100)
)
- (nop)
+ (drop
+ (i32.const 1)
+ )
+ (drop
+ (i32.const 0)
+ )
(drop
(i32.const 0)
)
- (nop)
)
)
(func $nop-in-unreachable (type $2)
@@ -1083,4 +1104,12 @@
(br $top)
)
)
+ (func $tee_br (type $7) (param $0 i32) (result i32)
+ (block $b
+ (return
+ (br $b)
+ )
+ )
+ (i32.const 1)
+ )
)
diff --git a/test/passes/coalesce-locals.wast b/test/passes/coalesce-locals.wast
index d6d499d36..336c75e0e 100644
--- a/test/passes/coalesce-locals.wast
+++ b/test/passes/coalesce-locals.wast
@@ -1075,4 +1075,14 @@
(br $top)
)
)
+ (func $tee_br (param $x i32) (result i32)
+ (block $b
+ (return
+ (tee_local $x
+ (br $b)
+ )
+ )
+ )
+ (i32.const 1)
+ )
)