summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast_utils.h4
-rw-r--r--test/passes/simplify-locals.txt42
2 files changed, 24 insertions, 22 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h
index 598081342..190b2876e 100644
--- a/src/ast_utils.h
+++ b/src/ast_utils.h
@@ -56,7 +56,9 @@ struct EffectAnalyzer : public WasmWalker<EffectAnalyzer> {
// checks if these effects would invalidate another set (e.g., if we write, we invalidate someone that reads, they can't be moved past us)
bool invalidates(EffectAnalyzer& other) {
- return branches || ((writesMemory || calls) && other.accessesMemory()) || (writesLocal && other.accessesLocal());
+ return branches || other.branches
+ || ((writesMemory || calls) && other.accessesMemory()) || (writesLocal && other.accessesLocal())
+ || (accessesMemory() && (other.writesMemory || other.calls)) || (accessesLocal() && other.writesLocal);
}
void visitIf(If *curr) { branches = true; }
diff --git a/test/passes/simplify-locals.txt b/test/passes/simplify-locals.txt
index 59e400dd7..477d95250 100644
--- a/test/passes/simplify-locals.txt
+++ b/test/passes/simplify-locals.txt
@@ -50,11 +50,11 @@
(set_local $a
(i32.const 1)
)
- (nop)
- (get_local $a)
(set_local $b
(i32.const 2)
)
+ (get_local $a)
+ (get_local $b)
(set_local $a
(i32.const 3)
)
@@ -78,12 +78,12 @@
(set_local $a
(i32.const 9)
)
- (nop)
- (call_import $waka)
- (get_local $a)
(set_local $b
(i32.const 10)
)
+ (call_import $waka)
+ (get_local $a)
+ (get_local $b)
(set_local $a
(i32.const 11)
)
@@ -93,14 +93,14 @@
(set_local $a
(i32.const 13)
)
- (nop)
+ (set_local $b
+ (i32.const 14)
+ )
(i32.load
(i32.const 24)
)
(get_local $a)
- (set_local $b
- (i32.const 14)
- )
+ (get_local $b)
(set_local $a
(i32.const 15)
)
@@ -110,15 +110,15 @@
(set_local $a
(i32.const 17)
)
- (nop)
+ (set_local $b
+ (i32.const 18)
+ )
(i32.store
(i32.const 48)
(i32.const 96)
)
(get_local $a)
- (set_local $b
- (i32.const 18)
- )
+ (get_local $b)
)
(block $block3
(nop)
@@ -132,13 +132,13 @@
(call_import $waka)
(get_local $a)
(call_import $waka)
- (nop)
- (i32.load
- (i32.const 1)
- )
(set_local $a
(call_import $waka_int)
)
+ (i32.load
+ (i32.const 1)
+ )
+ (get_local $a)
(call_import $waka)
(set_local $a
(call_import $waka_int)
@@ -202,16 +202,16 @@
(call_import $waka)
(get_local $a)
(call_import $waka)
- (nop)
- (i32.load
- (i32.const 1)
- )
(set_local $a
(i32.store
(i32.const 108)
(i32.const 109)
)
)
+ (i32.load
+ (i32.const 1)
+ )
+ (get_local $a)
(call_import $waka)
(set_local $a
(i32.store