summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-03-10 10:44:37 -0800
committerGitHub <noreply@github.com>2017-03-10 10:44:37 -0800
commitd54c03e99f9a43bde1b6cec94f05b0af412d0e4f (patch)
tree94128b81f1f1d2e9ecf83fe2e699e2528f6c49fc /test
parentd79d71ac7dfe807a5e98b94c9d1f67df4da7998a (diff)
downloadbinaryen-d54c03e99f9a43bde1b6cec94f05b0af412d0e4f.tar.gz
binaryen-d54c03e99f9a43bde1b6cec94f05b0af412d0e4f.tar.bz2
binaryen-d54c03e99f9a43bde1b6cec94f05b0af412d0e4f.zip
optimize pow (#934)
* optimize pow(x,2) => x*x * optimize pow(x, 0.5) => sqrt(x)
Diffstat (limited to 'test')
-rw-r--r--test/passes/post-emscripten.txt71
-rw-r--r--test/passes/post-emscripten.wast56
2 files changed, 125 insertions, 2 deletions
diff --git a/test/passes/post-emscripten.txt b/test/passes/post-emscripten.txt
index 179dec8c8..947318051 100644
--- a/test/passes/post-emscripten.txt
+++ b/test/passes/post-emscripten.txt
@@ -1,6 +1,9 @@
(module
(type $0 (func (param i32)))
- (type $1 (func (param i32) (result i32)))
+ (type $FUNCSIG$ddd (func (param f64 f64) (result f64)))
+ (type $2 (func (param i32) (result i32)))
+ (type $3 (func))
+ (import "global.Math" "pow" (func $Math_pow (param f64 f64) (result f64)))
(memory $0 256 256)
(export "load-off-2" (func $load-off-2))
(func $b0 (type $0) (param $x i32)
@@ -41,7 +44,7 @@
)
)
)
- (func $load-off-2 (type $1) (param $0 i32) (result i32)
+ (func $load-off-2 (type $2) (param $0 i32) (result i32)
(i32.store
(i32.const 6)
(get_local $0)
@@ -112,4 +115,68 @@
(get_local $0)
)
)
+ (func $pow2 (type $3)
+ (local $x f64)
+ (local $y f64)
+ (local $2 f64)
+ (local $3 f64)
+ (drop
+ (f64.mul
+ (tee_local $2
+ (f64.const 1)
+ )
+ (get_local $2)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (f64.const 1)
+ (f64.const 3)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (f64.const 2)
+ (f64.const 1)
+ )
+ )
+ (set_local $x
+ (f64.const 5)
+ )
+ (drop
+ (f64.mul
+ (get_local $x)
+ (get_local $x)
+ )
+ )
+ (drop
+ (f64.mul
+ (tee_local $y
+ (f64.const 7)
+ )
+ (get_local $y)
+ )
+ )
+ (drop
+ (f64.mul
+ (tee_local $3
+ (f64.const 8)
+ )
+ (get_local $3)
+ )
+ )
+ )
+ (func $pow.2 (type $3)
+ (drop
+ (f64.sqrt
+ (f64.const 1)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (f64.const 1)
+ (f64.const 0.51)
+ )
+ )
+ )
)
diff --git a/test/passes/post-emscripten.wast b/test/passes/post-emscripten.wast
index f262975f5..5c255ffca 100644
--- a/test/passes/post-emscripten.wast
+++ b/test/passes/post-emscripten.wast
@@ -1,6 +1,7 @@
(module
(memory 256 256)
(type $0 (func (param i32)))
+ (import "global.Math" "pow" (func $Math_pow (param f64 f64) (result f64)))
(func $b0 (type $0) (param $x i32)
(drop
(i32.load
@@ -152,4 +153,59 @@
)
)
)
+ (func $pow2
+ (local $x f64)
+ (local $y f64)
+ (drop
+ (call $Math_pow
+ (f64.const 1)
+ (f64.const 2)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (f64.const 1)
+ (f64.const 3)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (f64.const 2)
+ (f64.const 1)
+ )
+ )
+ (set_local $x (f64.const 5))
+ (drop
+ (call $Math_pow
+ (get_local $x)
+ (f64.const 2)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (tee_local $y (f64.const 7))
+ (f64.const 2)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (f64.const 8)
+ (f64.const 2)
+ )
+ )
+ )
+ (func $pow.2
+ (drop
+ (call $Math_pow
+ (f64.const 1)
+ (f64.const 0.5)
+ )
+ )
+ (drop
+ (call $Math_pow
+ (f64.const 1)
+ (f64.const 0.51)
+ )
+ )
+ )
)