summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/SimplifyLocals.cpp8
-rw-r--r--test/emcc_hello_world.fromasm4
-rw-r--r--test/emcc_hello_world.fromasm.imprecise4
-rw-r--r--test/passes/simplify-locals.txt32
-rw-r--r--test/unit.fromasm.imprecise8
5 files changed, 17 insertions, 39 deletions
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp
index fbdc248e3..f0c786b1c 100644
--- a/src/passes/SimplifyLocals.cpp
+++ b/src/passes/SimplifyLocals.cpp
@@ -62,7 +62,7 @@ struct SimplifyLocals : public WalkerPass<LinearExecutionWalker<SimplifyLocals,
void visitGetLocal(GetLocal *curr) {
auto found = sinkables.find(curr->index);
if (found != sinkables.end()) {
- // sink it, and nop the origin TODO: clean up nops
+ // sink it, and nop the origin
replaceCurrent(*found->second.item);
// reuse the getlocal that is dying
*found->second.item = curr;
@@ -75,11 +75,11 @@ struct SimplifyLocals : public WalkerPass<LinearExecutionWalker<SimplifyLocals,
}
void visitSetLocal(SetLocal *curr) {
- // if we are a potentially-sinkable thing, forget it - this
- // write overrides the last TODO: optimizable
- // TODO: if no get_locals left, can remove the set as well (== expressionizer in emscripten optimizer)
+ // if we are a potentially-sinkable thing, then the previous
+ // store is dead, leave just the value
auto found = sinkables.find(curr->index);
if (found != sinkables.end()) {
+ *found->second.item = (*found->second.item)->cast<SetLocal>()->value;
sinkables.erase(found);
}
}
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 3f72ff7a6..52aab6da5 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -9568,9 +9568,7 @@
(i32.const 76)
)
(block
- (set_local $label
- (i32.const 0)
- )
+ (i32.const 0)
(set_local $$a$0
(call $_fmt_u
(get_local $$148)
diff --git a/test/emcc_hello_world.fromasm.imprecise b/test/emcc_hello_world.fromasm.imprecise
index 231c877ce..6708ecfd6 100644
--- a/test/emcc_hello_world.fromasm.imprecise
+++ b/test/emcc_hello_world.fromasm.imprecise
@@ -9566,9 +9566,7 @@
(i32.const 76)
)
(block
- (set_local $label
- (i32.const 0)
- )
+ (i32.const 0)
(set_local $$a$0
(call $_fmt_u
(get_local $$148)
diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals.txt
index 0b7026928..a84ac43a0 100644
--- a/test/passes/simplify-locals.txt
+++ b/test/passes/simplify-locals.txt
@@ -39,47 +39,31 @@
(block $block2
(nop)
(nop)
- (set_local $a
- (i32.const 1)
- )
+ (i32.const 1)
(i32.const 2)
- (set_local $a
- (i32.const 3)
- )
+ (i32.const 3)
(i32.const 4)
(nop)
(nop)
(i32.const 6)
- (set_local $a
- (i32.const 5)
- )
- (set_local $a
- (i32.const 7)
- )
+ (i32.const 5)
+ (i32.const 7)
(i32.const 8)
(nop)
(nop)
(call_import $waka)
- (set_local $a
- (i32.const 9)
- )
+ (i32.const 9)
(i32.const 10)
- (set_local $a
- (i32.const 11)
- )
+ (i32.const 11)
(i32.const 12)
(nop)
(nop)
(i32.load
(i32.const 24)
)
- (set_local $a
- (i32.const 13)
- )
+ (i32.const 13)
(i32.const 14)
- (set_local $a
- (i32.const 15)
- )
+ (i32.const 15)
(i32.const 16)
(nop)
(nop)
diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise
index 1ccbda8a1..e829c7f3c 100644
--- a/test/unit.fromasm.imprecise
+++ b/test/unit.fromasm.imprecise
@@ -127,13 +127,11 @@
)
)
(func $conversions
- (local $i i32)
(local $d f64)
+ (local $i i32)
(local $f f32)
- (set_local $i
- (i32.trunc_s/f64
- (get_local $d)
- )
+ (i32.trunc_s/f64
+ (get_local $d)
)
(set_local $d
(f64.convert_s/i32