summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-07-22 20:45:47 +0300
committerGitHub <noreply@github.com>2020-07-22 10:45:47 -0700
commita097820b6f0d2bc4d31ace2764f07bfa17c2cad8 (patch)
treeb2396986d287bd71f321a4513342ae4f3523e565 /test
parent86362be31f1ae2d65e03fcc28bbf6526e48242f7 (diff)
downloadbinaryen-a097820b6f0d2bc4d31ace2764f07bfa17c2cad8.tar.gz
binaryen-a097820b6f0d2bc4d31ace2764f07bfa17c2cad8.tar.bz2
binaryen-a097820b6f0d2bc4d31ace2764f07bfa17c2cad8.zip
Optimize select with const arms (#2869)
x ? 1 : 0 => !!x and so forth.
Diffstat (limited to 'test')
-rw-r--r--test/passes/optimize-instructions_all-features.txt168
-rw-r--r--test/passes/optimize-instructions_all-features.wast214
-rw-r--r--test/wasm2js/i64-lowering.2asm.js.opt72
-rw-r--r--test/wasm2js/nested-selects.2asm.js.opt2
4 files changed, 400 insertions, 56 deletions
diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt
index 76c6ffe0a..e08702b91 100644
--- a/test/passes/optimize-instructions_all-features.txt
+++ b/test/passes/optimize-instructions_all-features.txt
@@ -3,8 +3,8 @@
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $none_=>_i32 (func (result i32)))
(type $none_=>_none (func))
- (type $i32_=>_none (func (param i32)))
(type $i32_i64_=>_none (func (param i32 i64)))
+ (type $i32_=>_none (func (param i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(type $none_=>_i64 (func (result i64)))
(type $i64_=>_i64 (func (param i64) (result i64)))
@@ -3228,7 +3228,7 @@
(local.get $x)
)
)
- (func $select-on-const (param $x i32) (param $y i32)
+ (func $select-on-const (param $x i32) (param $y i64)
(drop
(local.get $x)
)
@@ -3264,6 +3264,157 @@
(i32.const 6)
)
)
+ (drop
+ (i32.eqz
+ (i32.eqz
+ (local.get $x)
+ )
+ )
+ )
+ (drop
+ (i32.eqz
+ (local.get $x)
+ )
+ )
+ (drop
+ (i32.ge_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.lt_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.lt_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.gt_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.le_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i32.ge_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i32.eqz
+ (i32.eqz
+ (local.get $x)
+ )
+ )
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i32.eqz
+ (local.get $x)
+ )
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i64.eqz
+ (local.get $y)
+ )
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i32.eqz
+ (i64.eqz
+ (local.get $y)
+ )
+ )
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i64.ge_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i64.lt_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i64.lt_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (i64.extend_i32_u
+ (i64.ge_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i32.const 0)
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ (drop
+ (select
+ (i32.const 2)
+ (local.get $x)
+ (i32.const 2)
+ )
+ )
+ (drop
+ (select
+ (local.get $x)
+ (i32.const 2)
+ (local.get $x)
+ )
+ )
+ (drop
+ (select
+ (local.get $y)
+ (i64.const 0)
+ (i64.eqz
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (local.get $y)
+ (i64.const 2)
+ (i64.eqz
+ (i64.const 2)
+ )
+ )
+ )
)
(func $optimize-boolean (param $x i32)
(drop
@@ -3563,6 +3714,19 @@
(func $if-arms-subtype (result externref)
(ref.null)
)
+ (func $optimize-boolean-context (param $x i32) (param $y i32)
+ (if
+ (local.get $x)
+ (unreachable)
+ )
+ (drop
+ (select
+ (local.get $x)
+ (local.get $y)
+ (local.get $x)
+ )
+ )
+ )
)
(module
(type $none_=>_none (func))
diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast
index c62f0bc42..2790cc9ea 100644
--- a/test/passes/optimize-instructions_all-features.wast
+++ b/test/passes/optimize-instructions_all-features.wast
@@ -3714,7 +3714,7 @@
)
)
)
- (func $select-on-const (param $x i32) (param $y i32)
+ (func $select-on-const (param $x i32) (param $y i64)
(drop
(select
(i32.const 2)
@@ -3765,6 +3765,200 @@
(i32.const 1)
)
)
+ (drop
+ (select
+ (i32.const 1)
+ (i32.const 0)
+ (local.get $x)
+ )
+ )
+ (drop
+ (select
+ (i32.const 0)
+ (i32.const 1)
+ (local.get $x)
+ )
+ )
+ (drop
+ (select
+ (i32.const 0)
+ (i32.const 1)
+ (i32.lt_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i32.const 1)
+ (i32.const 0)
+ (i32.lt_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i32.const 0)
+ (i32.const 1)
+ (i32.ge_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i32.const 1)
+ (i32.const 0)
+ (i32.gt_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i32.const 0)
+ (i32.const 1)
+ (i32.gt_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i32.const 1)
+ (i32.const 0)
+ (i32.ge_s
+ (local.get $x)
+ (i32.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i64.const 1)
+ (i64.const 0)
+ (local.get $x)
+ )
+ )
+ (drop
+ (select
+ (i64.const 0)
+ (i64.const 1)
+ (local.get $x)
+ )
+ )
+ (drop
+ (select
+ (i64.const 1)
+ (i64.const 0)
+ (i64.eqz
+ (local.get $y)
+ )
+ )
+ )
+ (drop
+ (select
+ (i64.const 0)
+ (i64.const 1)
+ (i64.eqz
+ (local.get $y)
+ )
+ )
+ )
+ (drop
+ (select
+ (i64.const 0)
+ (i64.const 1)
+ (i64.lt_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i64.const 1)
+ (i64.const 0)
+ (i64.lt_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i64.const 0)
+ (i64.const 1)
+ (i64.ge_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (i64.const 1)
+ (i64.const 0)
+ (i64.ge_s
+ (local.get $y)
+ (i64.const 0)
+ )
+ )
+ )
+ ;; optimize boolean
+ (drop
+ (select
+ (local.get $x)
+ (i32.const 0)
+ (i32.eqz
+ (i32.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (local.get $x)
+ (i32.const 2)
+ (i32.eqz
+ (i32.const 2)
+ )
+ )
+ )
+ (drop
+ (select
+ (local.get $x)
+ (i32.const 2)
+ (i32.eqz
+ (i32.eqz
+ (local.get $x)
+ )
+ )
+ )
+ )
+ (drop
+ (select
+ (local.get $y)
+ (i64.const 0)
+ (i64.eqz
+ (i64.const 0)
+ )
+ )
+ )
+ (drop
+ (select
+ (local.get $y)
+ (i64.const 2)
+ (i64.eqz
+ (i64.const 2)
+ )
+ )
+ )
)
(func $optimize-boolean (param $x i32)
(drop
@@ -4021,6 +4215,24 @@
(ref.null)
)
)
+ (func $optimize-boolean-context (param $x i32) (param $y i32)
+ ;; 0 - x ==> x
+ (if
+ (i32.sub
+ (i32.const 0)
+ (local.get $x)
+ )
+ (unreachable)
+ )
+ (drop (select
+ (local.get $x)
+ (local.get $y)
+ (i32.sub
+ (i32.const 0)
+ (local.get $x)
+ )
+ ))
+ )
)
(module
(import "env" "memory" (memory $0 (shared 256 256)))
diff --git a/test/wasm2js/i64-lowering.2asm.js.opt b/test/wasm2js/i64-lowering.2asm.js.opt
index e5d955dfd..f4d940863 100644
--- a/test/wasm2js/i64-lowering.2asm.js.opt
+++ b/test/wasm2js/i64-lowering.2asm.js.opt
@@ -20,76 +20,44 @@ function asmFunc(global, env, buffer) {
var abort = env.abort;
var nan = global.NaN;
var infinity = global.Infinity;
- function $3($0, $1, $2, $3_1) {
- $0 = $0 | 0;
- $1 = $1 | 0;
- $2 = $2 | 0;
- $3_1 = $3_1 | 0;
- return (($1 | 0) > ($3_1 | 0) ? 1 : ($1 | 0) >= ($3_1 | 0) ? ($0 >>> 0 < $2 >>> 0 ? 0 : 1) : 0) | 0;
+ function legalstub$1($0, $1, $2, $3) {
+ return ($0 | 0) == ($2 | 0) & ($1 | 0) == ($3 | 0);
}
- function $4($0, $1, $2, $3_1) {
- $0 = $0 | 0;
- $1 = $1 | 0;
- $2 = $2 | 0;
- $3_1 = $3_1 | 0;
- return (($1 | 0) > ($3_1 | 0) ? 1 : ($1 | 0) >= ($3_1 | 0) ? ($0 >>> 0 <= $2 >>> 0 ? 0 : 1) : 0) | 0;
+ function legalstub$2($0, $1, $2, $3) {
+ return ($0 | 0) != ($2 | 0) | ($1 | 0) != ($3 | 0);
}
- function $5($0, $1, $2, $3_1) {
- $0 = $0 | 0;
- $1 = $1 | 0;
- $2 = $2 | 0;
- $3_1 = $3_1 | 0;
- return (($1 | 0) < ($3_1 | 0) ? 1 : ($1 | 0) <= ($3_1 | 0) ? ($0 >>> 0 > $2 >>> 0 ? 0 : 1) : 0) | 0;
+ function legalstub$3($0, $1, $2, $3) {
+ return ($1 | 0) > ($3 | 0) ? 1 : ($1 | 0) >= ($3 | 0) ? $0 >>> 0 >= $2 >>> 0 : 0;
}
- function $6($0, $1, $2, $3_1) {
- $0 = $0 | 0;
- $1 = $1 | 0;
- $2 = $2 | 0;
- $3_1 = $3_1 | 0;
- return (($1 | 0) < ($3_1 | 0) ? 1 : ($1 | 0) <= ($3_1 | 0) ? ($0 >>> 0 >= $2 >>> 0 ? 0 : 1) : 0) | 0;
+ function legalstub$4($0, $1, $2, $3) {
+ return ($1 | 0) > ($3 | 0) ? 1 : ($1 | 0) >= ($3 | 0) ? $0 >>> 0 > $2 >>> 0 : 0;
}
- function legalstub$1($0, $1, $2, $3_1) {
- return ($0 | 0) == ($2 | 0) & ($1 | 0) == ($3_1 | 0);
+ function legalstub$5($0, $1, $2, $3) {
+ return ($1 | 0) < ($3 | 0) ? 1 : ($1 | 0) <= ($3 | 0) ? $0 >>> 0 <= $2 >>> 0 : 0;
}
- function legalstub$2($0, $1, $2, $3_1) {
- return ($0 | 0) != ($2 | 0) | ($1 | 0) != ($3_1 | 0);
+ function legalstub$6($0, $1, $2, $3) {
+ return ($1 | 0) < ($3 | 0) ? 1 : ($1 | 0) <= ($3 | 0) ? $0 >>> 0 < $2 >>> 0 : 0;
}
- function legalstub$3($0, $1, $2, $3_1) {
- return $3($0, $1, $2, $3_1);
+ function legalstub$7($0, $1, $2, $3) {
+ return ($1 | 0) == ($3 | 0) & $0 >>> 0 >= $2 >>> 0 | $1 >>> 0 > $3 >>> 0;
}
- function legalstub$4($0, $1, $2, $3_1) {
- return $4($0, $1, $2, $3_1);
+ function legalstub$8($0, $1, $2, $3) {
+ return ($1 | 0) == ($3 | 0) & $0 >>> 0 > $2 >>> 0 | $1 >>> 0 > $3 >>> 0;
}
- function legalstub$5($0, $1, $2, $3_1) {
- return $5($0, $1, $2, $3_1);
+ function legalstub$9($0, $1, $2, $3) {
+ return ($1 | 0) == ($3 | 0) & $0 >>> 0 <= $2 >>> 0 | $1 >>> 0 < $3 >>> 0;
}
- function legalstub$6($0, $1, $2, $3_1) {
- return $6($0, $1, $2, $3_1);
- }
-
- function legalstub$7($0, $1, $2, $3_1) {
- return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 >= $2 >>> 0 | $1 >>> 0 > $3_1 >>> 0;
- }
-
- function legalstub$8($0, $1, $2, $3_1) {
- return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 > $2 >>> 0 | $1 >>> 0 > $3_1 >>> 0;
- }
-
- function legalstub$9($0, $1, $2, $3_1) {
- return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 <= $2 >>> 0 | $1 >>> 0 < $3_1 >>> 0;
- }
-
- function legalstub$10($0, $1, $2, $3_1) {
- return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 < $2 >>> 0 | $1 >>> 0 < $3_1 >>> 0;
+ function legalstub$10($0, $1, $2, $3) {
+ return ($1 | 0) == ($3 | 0) & $0 >>> 0 < $2 >>> 0 | $1 >>> 0 < $3 >>> 0;
}
var FUNCTION_TABLE = [];
diff --git a/test/wasm2js/nested-selects.2asm.js.opt b/test/wasm2js/nested-selects.2asm.js.opt
index 16d5529cd..9bb06d563 100644
--- a/test/wasm2js/nested-selects.2asm.js.opt
+++ b/test/wasm2js/nested-selects.2asm.js.opt
@@ -22,7 +22,7 @@ function asmFunc(global, env, buffer) {
var infinity = global.Infinity;
function $1($0) {
$0 = $0 | 0;
- return (($0 | 0) < 0 ? -1 : ($0 | 0) > 0 ? 1 : 0) | 0;
+ return (($0 | 0) < 0 ? -1 : ($0 | 0) > 0) | 0;
}
var FUNCTION_TABLE = [];