summaryrefslogtreecommitdiff
path: root/test/passes/optimize-instructions.wast
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-11-07 10:40:45 -0800
committerGitHub <noreply@github.com>2018-11-07 10:40:45 -0800
commitb2070673bd4f6e4eb9eb7707bc0e64c76e9ecef7 (patch)
tree96ed117bd9f2ad18ec54180165310b3623a851a3 /test/passes/optimize-instructions.wast
parentfb8db513e2772654b3804795c72aebd9eb8f3bca (diff)
downloadbinaryen-b2070673bd4f6e4eb9eb7707bc0e64c76e9ecef7.tar.gz
binaryen-b2070673bd4f6e4eb9eb7707bc0e64c76e9ecef7.tar.bz2
binaryen-b2070673bd4f6e4eb9eb7707bc0e64c76e9ecef7.zip
Fix a bug with (add (sub 0 X) Y) => (sub Y X) (#1727)
We need to verify that the reordering is valid if there are side effects. Original bug report: https://groups.google.com/forum/?nomobile=true#!topic/emscripten-discuss/HIlGf8o2Ato
Diffstat (limited to 'test/passes/optimize-instructions.wast')
-rw-r--r--test/passes/optimize-instructions.wast28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index aa979c62a..53ed761d8 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -3526,6 +3526,34 @@
)
)
)
+ (func $add-sub-zero-reorder-1 (param $temp i32) (result i32)
+ (i32.add
+ (i32.add
+ (i32.sub
+ (i32.const 0) ;; this zero looks like we could remove it by subtracting the get of $temp from the parent, but that would reorder it *after* the tee :(
+ (get_local $temp)
+ )
+ (tee_local $temp ;; cannot move this tee before the get
+ (i32.const 1)
+ )
+ )
+ (i32.const 2)
+ )
+ )
+ (func $add-sub-zero-reorder-2 (param $temp i32) (result i32)
+ (i32.add
+ (i32.add
+ (tee_local $temp ;; in this order, the tee already comes first, so all is good for the optimization
+ (i32.const 1)
+ )
+ (i32.sub
+ (i32.const 0)
+ (get_local $temp)
+ )
+ )
+ (i32.const 2)
+ )
+ )
)
(module
(import "env" "memory" (memory $0 (shared 256 256)))