summaryrefslogtreecommitdiff
path: root/test/passes/optimize-instructions.wast
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-02-16 22:42:31 -0800
committerGitHub <noreply@github.com>2017-02-16 22:42:31 -0800
commitc6ea79d1532face076c2dfeb8eadb58319e4e5fd (patch)
tree12a840d94dda462827a8874371bb9858948ea42b /test/passes/optimize-instructions.wast
parent0728a53fb6bf0540b9789c7bcd26e195800c5ecc (diff)
downloadbinaryen-c6ea79d1532face076c2dfeb8eadb58319e4e5fd.tar.gz
binaryen-c6ea79d1532face076c2dfeb8eadb58319e4e5fd.tar.bz2
binaryen-c6ea79d1532face076c2dfeb8eadb58319e4e5fd.zip
Optimize "squared" operations (#905)
* optimize 'almost' sign extends: when we can remove one entirely, then extra shifts can be left behind. with that in place, we can then optimize 'squared' operations like shl on shl, as doing so does not break our sign extend opts
Diffstat (limited to 'test/passes/optimize-instructions.wast')
-rw-r--r--test/passes/optimize-instructions.wast96
1 files changed, 95 insertions, 1 deletions
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index b9bd420da..c59bb3ade 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -539,7 +539,7 @@
(get_local $0)
(i32.const 24)
)
- (i32.const 23) ;; different shift
+ (i32.const 23) ;; different shift, smaller
)
(i32.const 0)
)
@@ -1238,4 +1238,98 @@
)
)
)
+ (func $almost-sign-ext (param $0 i32) (param $0 i32)
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.const 100) ;; too big, there is a sign bit, due to the extra shift
+ (i32.const 25)
+ )
+ (i32.const 24) ;; different shift, but larger, so ok to opt if we leave a shift, in theory
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shl
+ (i32.const 50) ;; small enough, no sign bit
+ (i32.const 25)
+ )
+ (i32.const 24) ;; different shift, but larger, so ok to opt if we leave a shift
+ )
+ )
+ )
+ (func $squaring (param $0 i32) (param $1 i32)
+ (drop
+ (i32.and
+ (i32.and
+ (get_local $0)
+ (i32.const 11)
+ )
+ (i32.const 200)
+ )
+ )
+ (drop
+ (i32.and
+ (i32.and
+ (get_local $0)
+ (i32.const 11)
+ )
+ (get_local $0) ;; non-const, cannot optimize this!
+ )
+ )
+ (drop
+ (i32.and
+ (i32.and
+ (i32.const 11) ;; flipped order
+ (get_local $0)
+ )
+ (i32.const 200)
+ )
+ )
+ (drop
+ (i32.or
+ (i32.or
+ (get_local $0)
+ (i32.const 11)
+ )
+ (i32.const 200)
+ )
+ )
+ (drop
+ (i32.shl
+ (i32.shl
+ (get_local $0)
+ (i32.const 11)
+ )
+ (i32.const 200)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (i32.shr_s
+ (get_local $0)
+ (i32.const 11)
+ )
+ (i32.const 200)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (i32.shr_u
+ (get_local $0)
+ (i32.const 11)
+ )
+ (i32.const 200)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (i32.shr_s ;; but do not optimize a mixture or different shifts!
+ (get_local $0)
+ (i32.const 11)
+ )
+ (i32.const 200)
+ )
+ )
+ )
)