summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/SimplifyGlobals.cpp5
-rw-r--r--test/lit/passes/simplify-globals-dominance.wast55
2 files changed, 60 insertions, 0 deletions
diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp
index 97e91bbab..398a6c3ca 100644
--- a/src/passes/SimplifyGlobals.cpp
+++ b/src/passes/SimplifyGlobals.cpp
@@ -341,6 +341,11 @@ struct ConstantGlobalApplier
return std::make_unique<ConstantGlobalApplier>(constantGlobals, optimize);
}
+ // It is ok to look at adjacent blocks together, as if a later part of a block
+ // is not reached that is fine - changes we make there would not be reached in
+ // that case.
+ bool connectAdjacentBlocks = true;
+
bool refinalize = false;
void replaceCurrent(Expression* rep) {
diff --git a/test/lit/passes/simplify-globals-dominance.wast b/test/lit/passes/simplify-globals-dominance.wast
new file mode 100644
index 000000000..948e8c5ec
--- /dev/null
+++ b/test/lit/passes/simplify-globals-dominance.wast
@@ -0,0 +1,55 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: foreach %s %t wasm-opt --simplify-globals -all -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (global $global (mut i32) (i32.const 0))
+ (global $global (mut i32) (i32.const 0))
+
+ ;; CHECK: (func $test (type $none_=>_none)
+ ;; CHECK-NEXT: (global.set $global
+ ;; CHECK-NEXT: (i32.const 10)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (if
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: (block
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 10)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (call $test)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (global.get $global)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (global.get $global)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test
+ (global.set $global
+ (i32.const 10)
+ )
+ (if
+ (i32.const 0)
+ (block
+ ;; This is dominated by the set, so we can apply 10 here.
+ (drop
+ (global.get $global)
+ )
+ (call $test)
+ ;; This is after a call, so we do nothing (we are still dominated by the
+ ;; global.set, but the call might set the global to another value).
+ (drop
+ (global.get $global)
+ )
+ )
+ ;; This is dominated by the set, but we do not optimize it yet. TODO
+ (drop
+ (global.get $global)
+ )
+ )
+ )
+)