summaryrefslogtreecommitdiff
path: root/test/passes/optimize-instructions_all-features.wast
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-10-05 09:00:05 -0700
committerGitHub <noreply@github.com>2020-10-05 09:00:05 -0700
commit3da66481b94cba2d3f5717316755fe3a60fcbe52 (patch)
treee00684455d7550bf12da608e7e086cba16092e95 /test/passes/optimize-instructions_all-features.wast
parentecaa818922fe2571649a621a00f7f3c40ebb217a (diff)
downloadbinaryen-3da66481b94cba2d3f5717316755fe3a60fcbe52.tar.gz
binaryen-3da66481b94cba2d3f5717316755fe3a60fcbe52.tar.bz2
binaryen-3da66481b94cba2d3f5717316755fe3a60fcbe52.zip
Ordering correction fix in OptimizeInstructions for #3047 (#3195)
(found by the fuzzer) It is not valid to replace x | (y | x) ==> y | x, if x, y cannot be reordered. It is also not valid to replace x ^ (y ^ x) ==> y, if x, y cannot be reordered, for a more subtle reason: if they cannot be reordered then y can affect the value of x (the opposite is not possible as we checked x for side effects so that we could remove one copy). If so, then the second appearance of x could be different, if e.g. it reads a local y writes to. Whereas, if it's ok to reorder, then it's ok to do x ^ (y ^ x) ==> x ^ (x ^ y) ==> y.
Diffstat (limited to 'test/passes/optimize-instructions_all-features.wast')
-rw-r--r--test/passes/optimize-instructions_all-features.wast48
1 files changed, 47 insertions, 1 deletions
diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast
index c8a48391c..71646de93 100644
--- a/test/passes/optimize-instructions_all-features.wast
+++ b/test/passes/optimize-instructions_all-features.wast
@@ -4805,7 +4805,53 @@
(local.get $x)
(local.get $y)
)
- ))
+ ))
+ ;; x | (y | x) where x and y cannot be reordered - skip
+ (drop
+ (i32.or
+ (local.get $x)
+ (i32.or
+ (local.tee $x
+ (i32.const 1)
+ )
+ (local.get $x)
+ )
+ )
+ )
+ (drop
+ (i32.or
+ (i32.or
+ (local.get $x)
+ (local.tee $x
+ (i32.const 1)
+ )
+ )
+ (local.get $x)
+ )
+ )
+ ;; x ^ (y ^ x) where x and y cannot be reordered - skip
+ (drop
+ (i32.xor
+ (local.get $x)
+ (i32.xor
+ (local.tee $x
+ (i32.const 1)
+ )
+ (local.get $x)
+ )
+ )
+ )
+ (drop
+ (i32.xor
+ (i32.xor
+ (local.get $x)
+ (local.tee $x
+ (i32.const 1)
+ )
+ )
+ (local.get $x)
+ )
+ )
)
(func $optimize-bulk-memory-copy (param $dst i32) (param $src i32) (param $sz i32)
(memory.copy ;; skip