Transition to TypeFlags for specific type checks; Optimize logical ops a bit

This commit is contained in:
dcodeIO
2018-01-10 23:19:14 +01:00
parent fc777b3a89
commit d89703cdad
18 changed files with 750 additions and 720 deletions

View File

@ -0,0 +1,19 @@
var binaryen = require("binaryen");
var mod = new binaryen.Module();
var funcType = mod.addFunctionType("i", binaryen.i32, [ binaryen.i32 ]);
var func = mod.addFunction("test", funcType, [],
mod.if(
mod.i32.eqz(mod.getLocal(0, binaryen.i32)),
mod.i32.const(0),
mod.getLocal(0, binaryen.i32)
)
);
mod.addExport("test", "test");
console.log(mod.emitText());
if (!mod.validate())
console.log("-> does not validate");
mod.optimize();
console.log(mod.emitText());

View File

@ -0,0 +1,14 @@
(module
(type $i (func (param i32) (result i32)))
(memory $0 0)
(export "test" (func $test))
(func $test (; 0 ;) (type $i) (param $0 i32) (result i32)
(if (result i32)
(i32.eqz
(get_local $0)
)
(i32.const 0)
(get_local $0)
)
)
)

View File

@ -55,32 +55,38 @@
)
)
(if
(if (result i32)
(i32.and
(if (result i32)
(tee_local $7
(i64.eq
(i64.shl
(get_local $5)
(i64.const 1)
(i32.and
(if (result i32)
(tee_local $7
(i64.eq
(i64.shl
(get_local $5)
(i64.const 1)
)
(i64.const 0)
)
)
(get_local $7)
(f64.ne
(tee_local $9
(get_local $1)
)
(get_local $9)
)
)
(i64.const 0)
(i32.const 1)
)
)
(get_local $7)
(tee_local $7
(f64.ne
(tee_local $9
(get_local $1)
)
(get_local $9)
)
(i32.eq
(get_local $3)
(i32.const 2047)
)
)
(get_local $7)
(i32.eq
(get_local $3)
(i32.const 2047)
)
(i32.const 1)
)
(return
(f64.div
@ -434,31 +440,37 @@
)
)
(if
(if (result i32)
(i32.and
(if (result i32)
(tee_local $3
(i32.eqz
(i32.shl
(get_local $5)
(i32.const 1)
(i32.and
(if (result i32)
(tee_local $3
(i32.eqz
(i32.shl
(get_local $5)
(i32.const 1)
)
)
)
(get_local $3)
(f32.ne
(tee_local $8
(get_local $1)
)
(get_local $8)
)
)
(i32.const 1)
)
)
(get_local $3)
(tee_local $3
(f32.ne
(tee_local $8
(get_local $1)
)
(get_local $8)
)
(i32.eq
(get_local $4)
(i32.const 255)
)
)
(get_local $3)
(i32.eq
(get_local $4)
(i32.const 255)
)
(i32.const 1)
)
(return
(f32.div

View File

@ -70,32 +70,42 @@
)
)
(if
(if (result i32)
(tee_local $8
(if (result i32)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i64.eq
(i64.shl
(get_local $3)
(i64.const 1)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i64.eq
(i64.shl
(get_local $3)
(i64.const 1)
)
(i64.const 0)
)
)
)
(f64.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i64.const 0)
(i32.const 1)
)
)
(get_local $8)
(f64.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
)
(i32.eq
(get_local $4)
(i32.const 2047)
)
(get_local $8)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 2047)
)
(i32.const 1)
)
(return
(f64.div
@ -530,32 +540,42 @@
)
)
(if
(if (result i32)
(tee_local $8
(if (result i32)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i32.eq
(i32.shl
(get_local $3)
(i32.const 1)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i32.eq
(i32.shl
(get_local $3)
(i32.const 1)
)
(i32.const 0)
)
)
)
(f32.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i32.const 0)
(i32.const 1)
)
)
(get_local $8)
(f32.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
)
(i32.eq
(get_local $4)
(i32.const 255)
)
(get_local $8)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 255)
)
(i32.const 1)
)
(return
(f32.div

View File

@ -209,19 +209,22 @@
)
)
(if
(if (result i32)
(i32.lt_u
(get_local $2)
(i32.const 2)
)
(i32.lt_u
(get_local $2)
(i32.const 2)
)
(i32.gt_u
(get_local $2)
(i32.const 3)
(i32.and
(select
(i32.gt_u
(get_local $2)
(i32.const 3)
)
(i32.lt_u
(get_local $2)
(i32.const 2)
)
(i32.ge_u
(get_local $2)
(i32.const 2)
)
)
(i32.const 1)
)
(i32.store8
(i32.add

View File

@ -235,19 +235,24 @@
)
)
(if
(if (result i32)
(i32.lt_u
(get_local $8)
(i32.const 2)
)
(i32.lt_u
(get_local $8)
(i32.const 2)
)
(i32.gt_u
(get_local $8)
(i32.const 3)
(i32.and
(select
(i32.gt_u
(get_local $8)
(i32.const 3)
)
(i32.lt_u
(get_local $8)
(i32.const 2)
)
(i32.eqz
(i32.lt_u
(get_local $8)
(i32.const 2)
)
)
)
(i32.const 1)
)
(i32.store8
(i32.add

View File

@ -13,75 +13,85 @@
(local $1 f64)
(drop
(if (result i32)
(i32.eqz
(i32.const 0)
)
(i32.const 0)
(unreachable)
(i32.const 0)
)
)
(drop
(if (result f64)
(f64.ne
(f64.eq
(f64.const 0)
(f64.const 0)
)
(unreachable)
(f64.const 0)
(unreachable)
)
)
(drop
(if (result i32)
(i32.const 1)
(i32.const 1)
(i32.eqz
(i32.const 1)
)
(unreachable)
(i32.const 1)
)
)
(drop
(if (result f64)
(f64.ne
(f64.eq
(f64.const 1)
(f64.const 0)
)
(f64.const 1)
(unreachable)
(f64.const 1)
)
)
(drop
(if (result i32)
(tee_local $0
(if (result i32)
(i32.const 1)
(i32.const 2)
(i32.const 1)
(i32.eqz
(tee_local $0
(select
(i32.const 1)
(i32.const 2)
(i32.eqz
(i32.const 1)
)
)
)
)
(get_local $0)
(unreachable)
(get_local $0)
)
)
(drop
(if (result f64)
(f64.ne
(f64.eq
(tee_local $1
(if (result f64)
(f64.ne
(select
(f64.const 1)
(f64.const 2)
(f64.eq
(f64.const 1)
(f64.const 0)
)
(f64.const 2)
(f64.const 1)
)
)
(f64.const 0)
)
(get_local $1)
(unreachable)
(get_local $1)
)
)
(set_global $logical/i
(if (result i32)
(select
(i32.const 1)
(i32.const 2)
(i32.const 1)
(i32.eqz
(i32.const 1)
)
)
)
(if
@ -94,10 +104,12 @@
(unreachable)
)
(set_global $logical/i
(if (result i32)
(i32.const 0)
(i32.const 0)
(select
(i32.const 1)
(i32.const 0)
(i32.eqz
(i32.const 0)
)
)
)
(if
@ -110,13 +122,12 @@
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(i64.const 1)
(i64.const 0)
)
(i64.const 2)
(select
(i64.const 1)
(i64.const 2)
(i64.eqz
(i64.const 1)
)
)
)
(if
@ -129,13 +140,12 @@
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(i64.const 0)
(select
(i64.const 1)
(i64.const 0)
(i64.eqz
(i64.const 0)
)
(i64.const 0)
(i64.const 1)
)
)
(if
@ -148,13 +158,13 @@
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(select
(f32.const 1)
(f32.const 2)
(f32.eq
(f32.const 1)
(f32.const 0)
)
(f32.const 2)
(f32.const 1)
)
)
(if
@ -167,13 +177,13 @@
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(select
(f32.const 1)
(f32.const 0)
(f32.eq
(f32.const 0)
(f32.const 0)
)
(f32.const 0)
(f32.const 1)
)
)
(if
@ -186,13 +196,13 @@
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(select
(f64.const 1)
(f64.const 2)
(f64.eq
(f64.const 1)
(f64.const 0)
)
(f64.const 2)
(f64.const 1)
)
)
(if
@ -205,13 +215,13 @@
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(select
(f64.const 1)
(f64.const 0)
(f64.eq
(f64.const 0)
(f64.const 0)
)
(f64.const 0)
(f64.const 1)
)
)
(if

View File

@ -18,13 +18,13 @@
)
(loop $continue|0
(if
(if (result i32)
(get_local $2)
(select
(i32.rem_u
(get_local $3)
(i32.const 4)
)
(get_local $2)
(get_local $2)
)
(block
(set_local $4

View File

@ -26,13 +26,15 @@
(block $break|0
(loop $continue|0
(if
(if (result i32)
(select
(get_local $2)
(i32.rem_u
(get_local $4)
(i32.const 4)
)
(get_local $2)
(i32.eqz
(get_local $2)
)
)
(block
(block

View File

@ -65,13 +65,13 @@
)
(loop $continue|0
(if
(if (result i32)
(get_local $2)
(select
(i32.rem_u
(get_local $3)
(i32.const 4)
)
(get_local $2)
(get_local $2)
)
(block
(set_local $4
@ -1687,32 +1687,38 @@
)
)
(if
(if (result i32)
(i32.and
(if (result i32)
(tee_local $7
(i64.eq
(i64.shl
(get_local $5)
(i64.const 1)
(i32.and
(if (result i32)
(tee_local $7
(i64.eq
(i64.shl
(get_local $5)
(i64.const 1)
)
(i64.const 0)
)
)
(get_local $7)
(f64.ne
(tee_local $9
(get_local $1)
)
(get_local $9)
)
)
(i64.const 0)
(i32.const 1)
)
)
(get_local $7)
(tee_local $7
(f64.ne
(tee_local $9
(get_local $1)
)
(get_local $9)
)
(i32.eq
(get_local $3)
(i32.const 2047)
)
)
(get_local $7)
(i32.eq
(get_local $3)
(i32.const 2047)
)
(i32.const 1)
)
(return
(f64.div
@ -2066,31 +2072,37 @@
)
)
(if
(if (result i32)
(i32.and
(if (result i32)
(tee_local $3
(i32.eqz
(i32.shl
(get_local $5)
(i32.const 1)
(i32.and
(if (result i32)
(tee_local $3
(i32.eqz
(i32.shl
(get_local $5)
(i32.const 1)
)
)
)
(get_local $3)
(f32.ne
(tee_local $8
(get_local $1)
)
(get_local $8)
)
)
(i32.const 1)
)
)
(get_local $3)
(tee_local $3
(f32.ne
(tee_local $8
(get_local $1)
)
(get_local $8)
)
(i32.eq
(get_local $4)
(i32.const 255)
)
)
(get_local $3)
(i32.eq
(get_local $4)
(i32.const 255)
)
(i32.const 1)
)
(return
(f32.div

View File

@ -86,13 +86,13 @@
)
(loop $continue|0
(if
(if (result i32)
(get_local $2)
(select
(i32.rem_u
(get_local $3)
(i32.const 4)
)
(get_local $2)
(get_local $2)
)
(block
(set_local $4
@ -1708,32 +1708,38 @@
)
)
(if
(if (result i32)
(i32.and
(if (result i32)
(tee_local $7
(i64.eq
(i64.shl
(get_local $5)
(i64.const 1)
(i32.and
(if (result i32)
(tee_local $7
(i64.eq
(i64.shl
(get_local $5)
(i64.const 1)
)
(i64.const 0)
)
)
(get_local $7)
(f64.ne
(tee_local $9
(get_local $1)
)
(get_local $9)
)
)
(i64.const 0)
(i32.const 1)
)
)
(get_local $7)
(tee_local $7
(f64.ne
(tee_local $9
(get_local $1)
)
(get_local $9)
)
(i32.eq
(get_local $3)
(i32.const 2047)
)
)
(get_local $7)
(i32.eq
(get_local $3)
(i32.const 2047)
)
(i32.const 1)
)
(return
(f64.div
@ -2087,31 +2093,37 @@
)
)
(if
(if (result i32)
(i32.and
(if (result i32)
(tee_local $3
(i32.eqz
(i32.shl
(get_local $5)
(i32.const 1)
(i32.and
(if (result i32)
(tee_local $3
(i32.eqz
(i32.shl
(get_local $5)
(i32.const 1)
)
)
)
(get_local $3)
(f32.ne
(tee_local $8
(get_local $1)
)
(get_local $8)
)
)
(i32.const 1)
)
)
(get_local $3)
(tee_local $3
(f32.ne
(tee_local $8
(get_local $1)
)
(get_local $8)
)
(i32.eq
(get_local $4)
(i32.const 255)
)
)
(get_local $3)
(i32.eq
(get_local $4)
(i32.const 255)
)
(i32.const 1)
)
(return
(f32.div

View File

@ -134,13 +134,15 @@
(block $break|0
(loop $continue|0
(if
(if (result i32)
(select
(get_local $2)
(i32.rem_u
(get_local $4)
(i32.const 4)
)
(get_local $2)
(i32.eqz
(get_local $2)
)
)
(block
(block
@ -1988,32 +1990,42 @@
)
)
(if
(if (result i32)
(tee_local $8
(if (result i32)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i64.eq
(i64.shl
(get_local $3)
(i64.const 1)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i64.eq
(i64.shl
(get_local $3)
(i64.const 1)
)
(i64.const 0)
)
)
)
(f64.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i64.const 0)
(i32.const 1)
)
)
(get_local $8)
(f64.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
)
(i32.eq
(get_local $4)
(i32.const 2047)
)
(get_local $8)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 2047)
)
(i32.const 1)
)
(return
(f64.div
@ -2448,32 +2460,42 @@
)
)
(if
(if (result i32)
(tee_local $8
(if (result i32)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i32.eq
(i32.shl
(get_local $3)
(i32.const 1)
(i32.and
(if (result i32)
(i32.eqz
(tee_local $8
(i32.eq
(i32.shl
(get_local $3)
(i32.const 1)
)
(i32.const 0)
)
)
)
(f32.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
(get_local $8)
)
(i32.const 0)
(i32.const 1)
)
)
(get_local $8)
(f32.ne
(tee_local $7
(get_local $1)
)
(get_local $7)
)
)
(i32.eq
(get_local $4)
(i32.const 255)
)
(get_local $8)
)
(get_local $8)
(i32.eq
(get_local $4)
(i32.const 255)
)
(i32.const 1)
)
(return
(f32.div
@ -4209,75 +4231,85 @@
)
(drop
(if (result i32)
(i32.eqz
(i32.const 0)
)
(i32.const 0)
(unreachable)
(i32.const 0)
)
)
(drop
(if (result f64)
(f64.ne
(f64.eq
(f64.const 0)
(f64.const 0)
)
(unreachable)
(f64.const 0)
(unreachable)
)
)
(drop
(if (result i32)
(i32.const 1)
(i32.const 1)
(i32.eqz
(i32.const 1)
)
(unreachable)
(i32.const 1)
)
)
(drop
(if (result f64)
(f64.ne
(f64.eq
(f64.const 1)
(f64.const 0)
)
(f64.const 1)
(unreachable)
(f64.const 1)
)
)
(drop
(if (result i32)
(tee_local $0
(if (result i32)
(i32.const 1)
(i32.const 2)
(i32.const 1)
(i32.eqz
(tee_local $0
(select
(i32.const 1)
(i32.const 2)
(i32.eqz
(i32.const 1)
)
)
)
)
(get_local $0)
(unreachable)
(get_local $0)
)
)
(drop
(if (result f64)
(f64.ne
(f64.eq
(tee_local $3
(if (result f64)
(f64.ne
(select
(f64.const 1)
(f64.const 2)
(f64.eq
(f64.const 1)
(f64.const 0)
)
(f64.const 2)
(f64.const 1)
)
)
(f64.const 0)
)
(get_local $3)
(unreachable)
(get_local $3)
)
)
(set_global $logical/i
(if (result i32)
(select
(i32.const 1)
(i32.const 2)
(i32.const 1)
(i32.eqz
(i32.const 1)
)
)
)
(if
@ -4290,10 +4322,12 @@
(unreachable)
)
(set_global $logical/i
(if (result i32)
(i32.const 0)
(i32.const 0)
(select
(i32.const 1)
(i32.const 0)
(i32.eqz
(i32.const 0)
)
)
)
(if
@ -4306,13 +4340,12 @@
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(i64.const 1)
(i64.const 0)
)
(i64.const 2)
(select
(i64.const 1)
(i64.const 2)
(i64.eqz
(i64.const 1)
)
)
)
(if
@ -4325,13 +4358,12 @@
(unreachable)
)
(set_global $logical/I
(if (result i64)
(i64.ne
(i64.const 0)
(select
(i64.const 1)
(i64.const 0)
(i64.eqz
(i64.const 0)
)
(i64.const 0)
(i64.const 1)
)
)
(if
@ -4344,13 +4376,13 @@
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(select
(f32.const 1)
(f32.const 2)
(f32.eq
(f32.const 1)
(f32.const 0)
)
(f32.const 2)
(f32.const 1)
)
)
(if
@ -4363,13 +4395,13 @@
(unreachable)
)
(set_global $logical/f
(if (result f32)
(f32.ne
(select
(f32.const 1)
(f32.const 0)
(f32.eq
(f32.const 0)
(f32.const 0)
)
(f32.const 0)
(f32.const 1)
)
)
(if
@ -4382,13 +4414,13 @@
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(select
(f64.const 1)
(f64.const 2)
(f64.eq
(f64.const 1)
(f64.const 0)
)
(f64.const 2)
(f64.const 1)
)
)
(if
@ -4401,13 +4433,13 @@
(unreachable)
)
(set_global $logical/F
(if (result f64)
(f64.ne
(select
(f64.const 1)
(f64.const 0)
(f64.eq
(f64.const 0)
(f64.const 0)
)
(f64.const 0)
(f64.const 1)
)
)
(if

View File

@ -472,13 +472,13 @@
)
(loop $continue|0
(if
(if (result i32)
(get_local $2)
(select
(i32.rem_u
(get_local $1)
(i32.const 4)
)
(get_local $2)
(get_local $2)
)
(block
(set_local $4

View File

@ -527,13 +527,15 @@
(block $break|0
(loop $continue|0
(if
(if (result i32)
(select
(get_local $2)
(i32.rem_u
(get_local $1)
(i32.const 4)
)
(get_local $2)
(i32.eqz
(get_local $2)
)
)
(block
(block
@ -2335,6 +2337,9 @@
(loop $continue|0
(if
(if (result i32)
(i32.eqz
(get_local $2)
)
(get_local $2)
(i32.eq
(i32.load8_u
@ -2344,7 +2349,6 @@
(get_local $1)
)
)
(get_local $2)
)
(block
(block

View File

@ -160,20 +160,23 @@
(loop $continue|3
(if
(if (result i32)
(tee_local $0
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
(i32.eqz
(tee_local $0
(block (result i32)
(set_local $0
(get_global $while/n)
)
(set_global $while/n
(i32.sub
(get_local $0)
(i32.const 1)
)
)
(get_local $0)
)
(get_local $0)
)
)
(get_local $0)
(block (result i32)
(set_global $while/m
(i32.add
@ -183,7 +186,6 @@
)
(get_global $while/m)
)
(get_local $0)
)
(block
(nop)