summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2018-04-11 12:02:29 -0700
committerGitHub <noreply@github.com>2018-04-11 12:02:29 -0700
commit92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb (patch)
tree671827c29364ef509ce2a6ba050d9b119c54c9cc /test
parent9b5ce471992033eeec9a8779bce55f2429496431 (diff)
downloadbinaryen-92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb.tar.gz
binaryen-92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb.tar.bz2
binaryen-92afb40eea6e9a09af2d355ff9ab6a4bd04c54bb.zip
Some simple integer math opts (#1504)
Stuff like x + 5 != 2 => x != -3. Also some cleanups of utility functions I noticed while writing this, isTypeFloat => isFloatType. Inspired by https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/generic.rules
Diffstat (limited to 'test')
-rw-r--r--test/memorygrowth.fromasm4
-rw-r--r--test/memorygrowth.fromasm.clamp4
-rw-r--r--test/memorygrowth.fromasm.imprecise4
-rw-r--r--test/passes/optimize-instructions.txt306
-rw-r--r--test/passes/optimize-instructions.wast320
5 files changed, 632 insertions, 6 deletions
diff --git a/test/memorygrowth.fromasm b/test/memorygrowth.fromasm
index 5b67a3408..031e1b8ce 100644
--- a/test/memorygrowth.fromasm
+++ b/test/memorygrowth.fromasm
@@ -9582,8 +9582,8 @@
(i32.load
(i32.const 1160)
)
- (i32.load offset=64
- (i32.const 0)
+ (i32.load
+ (i32.const 64)
)
(i32.const 1204)
)
diff --git a/test/memorygrowth.fromasm.clamp b/test/memorygrowth.fromasm.clamp
index 5b67a3408..031e1b8ce 100644
--- a/test/memorygrowth.fromasm.clamp
+++ b/test/memorygrowth.fromasm.clamp
@@ -9582,8 +9582,8 @@
(i32.load
(i32.const 1160)
)
- (i32.load offset=64
- (i32.const 0)
+ (i32.load
+ (i32.const 64)
)
(i32.const 1204)
)
diff --git a/test/memorygrowth.fromasm.imprecise b/test/memorygrowth.fromasm.imprecise
index f36b78409..062d52a2b 100644
--- a/test/memorygrowth.fromasm.imprecise
+++ b/test/memorygrowth.fromasm.imprecise
@@ -9573,8 +9573,8 @@
)
(func $Qa (; 31 ;) (result i32)
(select
- (i32.load offset=64
- (i32.const 0)
+ (i32.load
+ (i32.const 64)
)
(i32.const 1204)
(i32.load
diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt
index d77a1e1c2..5ed72a62e 100644
--- a/test/passes/optimize-instructions.txt
+++ b/test/passes/optimize-instructions.txt
@@ -8,6 +8,8 @@
(type $6 (func (param i32 i32) (result i32)))
(type $7 (func (param i64) (result i64)))
(type $8 (func (result i64)))
+ (type $9 (func (param i32 i64 f32 f64)))
+ (type $10 (func (param i32 i64 f32)))
(memory $0 0)
(export "load-off-2" (func $load-off-2))
(func $f (; 0 ;) (type $0) (param $i1 i32) (param $i2 i64)
@@ -2416,6 +2418,310 @@
)
(unreachable)
)
+ (func $abstract-additions (; 64 ;) (type $9) (param $x32 i32) (param $x64 i64) (param $y32 f32) (param $y64 f64)
+ (drop
+ (get_local $x32)
+ )
+ (drop
+ (get_local $x32)
+ )
+ (drop
+ (get_local $x32)
+ )
+ (drop
+ (get_local $x32)
+ )
+ (drop
+ (get_local $x64)
+ )
+ (drop
+ (get_local $x64)
+ )
+ (drop
+ (get_local $x64)
+ )
+ (drop
+ (get_local $x64)
+ )
+ (drop
+ (i32.const 0)
+ )
+ (drop
+ (i64.const 0)
+ )
+ (drop
+ (f32.mul
+ (get_local $y32)
+ (f32.const 0)
+ )
+ )
+ (drop
+ (f64.mul
+ (get_local $y64)
+ (f64.const 0)
+ )
+ )
+ (drop
+ (get_local $x32)
+ )
+ (drop
+ (get_local $x64)
+ )
+ (drop
+ (get_local $y32)
+ )
+ (drop
+ (get_local $y64)
+ )
+ (drop
+ (i32.const 0)
+ )
+ (drop
+ (i64.const 0)
+ )
+ (drop
+ (i32.and
+ (unreachable)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i64.and
+ (unreachable)
+ (i64.const 0)
+ )
+ )
+ (drop
+ (get_local $x32)
+ )
+ (drop
+ (get_local $x32)
+ )
+ (drop
+ (get_local $x64)
+ )
+ (drop
+ (get_local $x64)
+ )
+ (drop
+ (get_local $y32)
+ )
+ (drop
+ (get_local $y64)
+ )
+ (drop
+ (f32.div
+ (get_local $y32)
+ (f32.const 1.2000000476837158)
+ )
+ )
+ (drop
+ (i32.mul
+ (get_local $x32)
+ (i32.const -1)
+ )
+ )
+ (drop
+ (i64.mul
+ (get_local $x64)
+ (i64.const -1)
+ )
+ )
+ (drop
+ (f32.mul
+ (get_local $y32)
+ (f32.const -1)
+ )
+ )
+ (drop
+ (f64.mul
+ (get_local $y64)
+ (f64.const -1)
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.const 10)
+ )
+ )
+ (drop
+ (i32.le_u
+ (i32.add
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.const 20)
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.const 30)
+ )
+ )
+ (drop
+ (i64.eq
+ (get_local $x64)
+ (i64.const 10)
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.const 10)
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.add
+ (get_local $x32)
+ (i32.const 10)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.const 30)
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.sub
+ (get_local $x32)
+ (i32.const 30)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.add
+ (get_local $x32)
+ (i32.const 30)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (get_local $x32)
+ (i32.sub
+ (get_local $x32)
+ (i32.const 10)
+ )
+ )
+ )
+ (drop
+ (i64.le_s
+ (i64.sub
+ (get_local $x64)
+ (i64.const 288230376151711744)
+ )
+ (i64.const 9223372036854775807)
+ )
+ )
+ )
+ (func $negatives-are-sometimes-better (; 65 ;) (type $10) (param $x i32) (param $y i64) (param $z f32)
+ (drop
+ (i32.sub
+ (get_local $x)
+ (i32.const -64)
+ )
+ )
+ (drop
+ (i32.add
+ (get_local $x)
+ (i32.const -64)
+ )
+ )
+ (drop
+ (i32.sub
+ (get_local $x)
+ (i32.const -8192)
+ )
+ )
+ (drop
+ (i32.sub
+ (get_local $x)
+ (i32.const -1048576)
+ )
+ )
+ (drop
+ (i32.sub
+ (get_local $x)
+ (i32.const -134217728)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -64)
+ )
+ )
+ (drop
+ (i64.add
+ (get_local $y)
+ (i64.const -64)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -8192)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -1048576)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -134217728)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -17179869184)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -2199023255552)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -281474976710656)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -36028797018963968)
+ )
+ )
+ (drop
+ (i64.sub
+ (get_local $y)
+ (i64.const -4611686018427387904)
+ )
+ )
+ (drop
+ (f32.add
+ (get_local $z)
+ (f32.const 64)
+ )
+ )
+ )
)
(module
(type $0 (func))
diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast
index 5d1ba7308..e4d7773ee 100644
--- a/test/passes/optimize-instructions.wast
+++ b/test/passes/optimize-instructions.wast
@@ -2838,6 +2838,326 @@
)
(unreachable)
)
+ (func $abstract-additions (param $x32 i32) (param $x64 i64) (param $y32 f32) (param $y64 f64)
+ (drop
+ (i32.or
+ (i32.const 0)
+ (get_local $x32)
+ )
+ )
+ (drop
+ (i32.shl
+ (get_local $x32)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.shr_u
+ (get_local $x32)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.shr_s
+ (get_local $x32)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i64.or
+ (i64.const 0)
+ (get_local $x64)
+ )
+ )
+ (drop
+ (i64.shl
+ (get_local $x64)
+ (i64.const 0)
+ )
+ )
+ (drop
+ (i64.shr_u
+ (get_local $x64)
+ (i64.const 0)
+ )
+ )
+ (drop
+ (i64.shr_s
+ (get_local $x64)
+ (i64.const 0)
+ )
+ )
+ (drop
+ (i32.mul
+ (get_local $x32)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i64.mul
+ (get_local $x64)
+ (i64.const 0)
+ )
+ )
+ (drop
+ (f32.mul
+ (get_local $y32)
+ (f32.const 0)
+ )
+ )
+ (drop
+ (f64.mul
+ (get_local $y64)
+ (f64.const 0)
+ )
+ )
+ (drop
+ (i32.mul
+ (get_local $x32)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i64.mul
+ (get_local $x64)
+ (i64.const 1)
+ )
+ )
+ (drop
+ (f32.mul
+ (get_local $y32)
+ (f32.const 1)
+ )
+ )
+ (drop
+ (f64.mul
+ (get_local $y64)
+ (f64.const 1)
+ )
+ )
+ (drop
+ (i32.and
+ (get_local $x32)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i64.and
+ (get_local $x64)
+ (i64.const 0)
+ )
+ )
+ (drop
+ (i32.and
+ (unreachable)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i64.and
+ (unreachable)
+ (i64.const 0)
+ )
+ )
+ (drop
+ (i32.div_s
+ (get_local $x32)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.div_u
+ (get_local $x32)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i64.div_s
+ (get_local $x64)
+ (i64.const 1)
+ )
+ )
+ (drop
+ (i64.div_u
+ (get_local $x64)
+ (i64.const 1)
+ )
+ )
+ (drop
+ (f32.div
+ (get_local $y32)
+ (f32.const 1)
+ )
+ )
+ (drop
+ (f64.div
+ (get_local $y64)
+ (f64.const 1)
+ )
+ )
+ (drop
+ (f32.div
+ (get_local $y32)
+ (f32.const 1.2)
+ )
+ )
+ (drop
+ (i32.mul
+ (get_local $x32)
+ (i32.const -1)
+ )
+ )
+ (drop
+ (i64.mul
+ (get_local $x64)
+ (i64.const -1)
+ )
+ )
+ (drop
+ (f32.mul
+ (get_local $y32)
+ (f32.const -1)
+ )
+ )
+ (drop
+ (f64.mul
+ (get_local $y64)
+ (f64.const -1)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.add
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.const 20)
+ )
+ )
+ (drop
+ (i32.le_u
+ (i32.add
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.const 20)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.sub
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.const 20)
+ )
+ )
+ (drop
+ (i64.eq
+ (i64.add
+ (get_local $x64)
+ (i64.const 10)
+ )
+ (i64.const 20)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.const 20)
+ (i32.add
+ (get_local $x32)
+ (i32.const 10)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.add
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.add
+ (get_local $x32)
+ (i32.const 20)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.sub
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.const 20)
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.add
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.sub
+ (get_local $x32)
+ (i32.const 20)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.sub
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.add
+ (get_local $x32)
+ (i32.const 20)
+ )
+ )
+ )
+ (drop
+ (i32.eq
+ (i32.sub
+ (get_local $x32)
+ (i32.const 10)
+ )
+ (i32.sub
+ (get_local $x32)
+ (i32.const 20)
+ )
+ )
+ )
+ (drop
+ (i64.le_s
+ (i64.sub
+ (get_local $x64)
+ (i64.const 288230376151711744)
+ )
+ (i64.const 9223372036854775807)
+ )
+ )
+ )
+ (func $negatives-are-sometimes-better (param $x i32) (param $y i64) (param $z f32)
+ (drop (i32.add (get_local $x) (i32.const 0x40)))
+ (drop (i32.sub (get_local $x) (i32.const 0x40)))
+ (drop (i32.add (get_local $x) (i32.const 0x2000)))
+ (drop (i32.add (get_local $x) (i32.const 0x100000)))
+ (drop (i32.add (get_local $x) (i32.const 0x8000000)))
+
+ (drop (i64.add (get_local $y) (i64.const 0x40)))
+ (drop (i64.sub (get_local $y) (i64.const 0x40)))
+ (drop (i64.add (get_local $y) (i64.const 0x2000)))
+ (drop (i64.add (get_local $y) (i64.const 0x100000)))
+ (drop (i64.add (get_local $y) (i64.const 0x8000000)))
+
+ (drop (i64.add (get_local $y) (i64.const 0x400000000)))
+ (drop (i64.add (get_local $y) (i64.const 0x20000000000)))
+ (drop (i64.add (get_local $y) (i64.const 0x1000000000000)))
+ (drop (i64.add (get_local $y) (i64.const 0x80000000000000)))
+ (drop (i64.add (get_local $y) (i64.const 0x4000000000000000)))
+
+ (drop (f32.add (get_local $z) (f32.const 0x40)))
+ )
)
(module
(import "env" "memory" (memory $0 (shared 256 256)))