summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-12-15 13:46:35 -0800
committerGitHub <noreply@github.com>2022-12-15 13:46:35 -0800
commitbead42c46d48e4c5584f035f7a805911dc59ae35 (patch)
tree4079c1b3e7e850ad568fbb1b957aba985258425b /test
parent7769196090e7ce2c150cd8a58fad0c89430d3d2b (diff)
downloadbinaryen-bead42c46d48e4c5584f035f7a805911dc59ae35.tar.gz
binaryen-bead42c46d48e4c5584f035f7a805911dc59ae35.tar.bz2
binaryen-bead42c46d48e4c5584f035f7a805911dc59ae35.zip
Properly use pass options in nested pass runners (up to -O1) (#5351)
This fixes a TODO. There is a runtime cost to this in higher opt levels, as passing through -O3 makes nested optimization work take longer. But it can lead to better results. For now, this PR moves us from 0 before to a maximum of 1, as a compromise. 1 does not regress compile times, but there may be further benefits to allowing 2 and 3 in the future. Also fix a fuzzer bug that becomes uncovered by tihs PR: Now that we actually optimize in simplify-globals, we need to handle the case of the optimizer there seeing a call with the effects of writing to a global (we had an assert on that never happening, but with function effects that can happen, and so a GlobalSet is not the only thing that can set a global). Aside from the opt and shrink levels this passes through all other options, like trapsNeverHappen.
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/simplify-globals_func-effects.wast91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/lit/passes/simplify-globals_func-effects.wast b/test/lit/passes/simplify-globals_func-effects.wast
new file mode 100644
index 000000000..8257c5ce7
--- /dev/null
+++ b/test/lit/passes/simplify-globals_func-effects.wast
@@ -0,0 +1,91 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: foreach %s %t wasm-opt --generate-global-effects --simplify-globals -S -o - | filecheck %s
+
+;; Compute function effects and then simplify globals. We must handle the case
+;; of an expression that is not a global.set that sets a global - a function
+;; whose effects we've computed to include some sets to globals.
+
+(module
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (global $A (mut i32) (i32.const 10))
+ (global $A (mut i32) (i32.const 10))
+
+ ;; CHECK: (global $B i32 (i32.const 20))
+ (global $B (mut i32) (i32.const 20))
+
+ ;; CHECK: (global $C (mut i32) (i32.const 30))
+ (global $C (mut i32) (i32.const 30))
+
+ ;; CHECK: (func $set
+ ;; CHECK-NEXT: (global.set $A
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $set
+ (global.set $A
+ (i32.const 0)
+ )
+ )
+
+ ;; CHECK: (func $test
+ ;; CHECK-NEXT: (global.set $A
+ ;; CHECK-NEXT: (i32.const 11)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (global.set $C
+ ;; CHECK-NEXT: (i32.const 33)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 11)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 20)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 33)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (call $set)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (global.get $A)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 20)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (i32.const 33)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test
+ (global.set $A
+ (i32.const 11)
+ )
+ (global.set $C
+ (i32.const 33)
+ )
+ ;; We can infer $A here since we see the write to it, above.
+ (drop
+ (global.get $A)
+ )
+ ;; We can infer $B since we'll prove it is immutable.
+ (drop
+ (global.get $B)
+ )
+ ;; We can infer $C here since we see the write to it, above.
+ (drop
+ (global.get $C)
+ )
+ ;; This call sets $A. After the call we can no longer infer $A, but we can
+ ;; still infer the others.
+ (call $set)
+ (drop
+ (global.get $A)
+ )
+ (drop
+ (global.get $B)
+ )
+ (drop
+ (global.get $C)
+ )
+ )
+)