diff options
author | Alon Zakai <azakai@google.com> | 2021-03-29 11:33:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-29 11:33:52 -0700 |
commit | 1a6efdb4233a077bc6e5e8a340baf5672bb5bced (patch) | |
tree | f814f47930fe8a2312cd23848ea63ff7e13bb9dc /test/wasm2js | |
parent | 9c1d69f6596b76fe83bff17709b92f8cc2054a31 (diff) | |
download | binaryen-1a6efdb4233a077bc6e5e8a340baf5672bb5bced.tar.gz binaryen-1a6efdb4233a077bc6e5e8a340baf5672bb5bced.tar.bz2 binaryen-1a6efdb4233a077bc6e5e8a340baf5672bb5bced.zip |
Inlining: Always inline single-use functions (#3730)
This implements emscripten-core/emscripten#13744
Inlining functions with a single use allows us to remove the function afterward.
That looks highly beneficial, shrinking every single benchmark in emscripten's
benchmark suite, by an average of 2% on the macrobenchmarks and 3.5% on
all of them. Speed also improves, although mostly on the microbenchmarks so
that might be less realistic.
There may be a slight downside to startup time due to emitting larger functions,
but given the baseline compilers in VMs these days it seems worth it, as the
delay would be just to get to the upper tier. On the benchmark suite the risk
seems low.
See more details in the PR above.
Diffstat (limited to 'test/wasm2js')
-rw-r--r-- | test/wasm2js/conversions-modified.2asm.js.opt | 22 | ||||
-rw-r--r-- | test/wasm2js/i64-add-sub.2asm.js.opt | 22 | ||||
-rw-r--r-- | test/wasm2js/i64-ctz.2asm.js.opt | 70 | ||||
-rw-r--r-- | test/wasm2js/i64-rotate.2asm.js.opt | 148 | ||||
-rw-r--r-- | test/wasm2js/i64-shifts.2asm.js.opt | 50 | ||||
-rw-r--r-- | test/wasm2js/reinterpret.2asm.js.opt | 14 | ||||
-rw-r--r-- | test/wasm2js/stack-modified.2asm.js.opt | 57 | ||||
-rw-r--r-- | test/wasm2js/unaligned.2asm.js.opt | 20 | ||||
-rw-r--r-- | test/wasm2js/unary-ops.2asm.js.opt | 113 |
9 files changed, 213 insertions, 303 deletions
diff --git a/test/wasm2js/conversions-modified.2asm.js.opt b/test/wasm2js/conversions-modified.2asm.js.opt index 499b78c5b..26480d72b 100644 --- a/test/wasm2js/conversions-modified.2asm.js.opt +++ b/test/wasm2js/conversions-modified.2asm.js.opt @@ -66,18 +66,6 @@ function asmFunc(env) { return ~~$0 >>> 0 | 0; } - function $7($0) { - $0 = Math_fround($0); - i64toi32_i32$HIGH_BITS = Math_fround(Math_abs($0)) >= Math_fround(1.0) ? ($0 > Math_fround(0.0) ? ~~Math_fround(Math_min(Math_fround(Math_floor(Math_fround($0 * Math_fround(2.3283064365386963e-10)))), Math_fround(4294967296.0))) >>> 0 : ~~Math_fround(Math_ceil(Math_fround(Math_fround($0 - Math_fround(~~$0 >>> 0 >>> 0)) * Math_fround(2.3283064365386963e-10)))) >>> 0) : 0; - return ~~$0 >>> 0 | 0; - } - - function $9($0) { - $0 = +$0; - i64toi32_i32$HIGH_BITS = Math_abs($0) >= 1.0 ? ($0 > 0.0 ? ~~Math_min(Math_floor($0 * 2.3283064365386963e-10), 4294967295.0) >>> 0 : ~~Math_ceil(($0 - +(~~$0 >>> 0 >>> 0)) * 2.3283064365386963e-10) >>> 0) : 0; - return ~~$0 >>> 0 | 0; - } - function $11($0) { $0 = $0 | 0; return Math_fround(Math_fround($0 | 0)); @@ -135,17 +123,15 @@ function asmFunc(env) { } function legalstub$7($0) { - var $1 = 0; - $1 = $7($0); + i64toi32_i32$HIGH_BITS = Math_fround(Math_abs($0)) >= Math_fround(1.0) ? ($0 > Math_fround(0.0) ? ~~Math_fround(Math_min(Math_fround(Math_floor(Math_fround($0 * Math_fround(2.3283064365386963e-10)))), Math_fround(4294967296.0))) >>> 0 : ~~Math_fround(Math_ceil(Math_fround(Math_fround($0 - Math_fround(~~$0 >>> 0 >>> 0)) * Math_fround(2.3283064365386963e-10)))) >>> 0) : 0; setTempRet0(i64toi32_i32$HIGH_BITS | 0); - return $1; + return ~~$0 >>> 0; } function legalstub$9($0) { - var $1 = 0; - $1 = $9($0); + i64toi32_i32$HIGH_BITS = Math_abs($0) >= 1.0 ? ($0 > 0.0 ? ~~Math_min(Math_floor($0 * 2.3283064365386963e-10), 4294967295.0) >>> 0 : ~~Math_ceil(($0 - +(~~$0 >>> 0 >>> 0)) * 2.3283064365386963e-10) >>> 0) : 0; setTempRet0(i64toi32_i32$HIGH_BITS | 0); - return $1; + return ~~$0 >>> 0; } function legalstub$12($0, $1) { diff --git a/test/wasm2js/i64-add-sub.2asm.js.opt b/test/wasm2js/i64-add-sub.2asm.js.opt index ccbcf0126..62f464829 100644 --- a/test/wasm2js/i64-add-sub.2asm.js.opt +++ b/test/wasm2js/i64-add-sub.2asm.js.opt @@ -13,25 +13,15 @@ function asmFunc(env) { var abort = env.abort; var nan = NaN; var infinity = Infinity; - function $1($0, $1_1, $2, $3, $4, $5) { - $0 = $0 | 0; - $1_1 = $1_1 | 0; - $2 = $2 | 0; - $3 = $3 | 0; - $4 = $4 | 0; - $5 = $5 | 0; - $1_1 = $1_1 + $3 | 0; + function legalstub$1($0, $1, $2, $3, $4, $5) { + $1 = $1 + $3 | 0; $0 = $0 + $2 | 0; - $1_1 = $2 >>> 0 > $0 >>> 0 ? $1_1 + 1 | 0 : $1_1; - return ($0 | 0) == ($4 | 0) & ($1_1 | 0) == ($5 | 0); + $1 = $2 >>> 0 > $0 >>> 0 ? $1 + 1 | 0 : $1; + return ($0 | 0) == ($4 | 0) & ($1 | 0) == ($5 | 0); } - function legalstub$1($0, $1_1, $2, $3, $4, $5) { - return $1($0, $1_1, $2, $3, $4, $5); - } - - function legalstub$2($0, $1_1, $2, $3, $4, $5) { - return ($4 | 0) == ($0 - $2 | 0) & ($5 | 0) == ($1_1 - (($0 >>> 0 < $2 >>> 0) + $3 | 0) | 0); + function legalstub$2($0, $1, $2, $3, $4, $5) { + return ($4 | 0) == ($0 - $2 | 0) & ($5 | 0) == ($1 - (($0 >>> 0 < $2 >>> 0) + $3 | 0) | 0); } return { diff --git a/test/wasm2js/i64-ctz.2asm.js.opt b/test/wasm2js/i64-ctz.2asm.js.opt index 5fe370d39..fc2e030b9 100644 --- a/test/wasm2js/i64-ctz.2asm.js.opt +++ b/test/wasm2js/i64-ctz.2asm.js.opt @@ -17,52 +17,48 @@ function asmFunc(env) { var setTempRet0 = env.setTempRet0; var i64toi32_i32$HIGH_BITS = 0; function legalstub$popcnt64($0, $1) { - $0 = __wasm_popcnt_i64($0, $1); + var $2 = 0, $3 = 0, $4 = 0, $5 = 0; + $2 = $1; + while (1) { + $1 = $3; + $5 = $4; + if ($0 | $2) { + $1 = $0; + $0 = $0 - 1 & $0; + $2 = $2 - ($1 >>> 0 < 1) & $2; + $3 = $3 + 1 | 0; + $4 = $3 >>> 0 < 1 ? $4 + 1 | 0 : $4; + continue; + } + break; + }; + i64toi32_i32$HIGH_BITS = $5; + $0 = $1; setTempRet0(i64toi32_i32$HIGH_BITS | 0); return $0; } function legalstub$ctz64($0, $1) { - $0 = __wasm_ctz_i64($0, $1); - setTempRet0(i64toi32_i32$HIGH_BITS | 0); - return $0; - } - - function __wasm_ctz_i64($0, $1) { - var $2 = 0, $3 = 0; - if ($0 | $1) { - $2 = $1 - 1 | 0; - $3 = $0 - 1 | 0; - $2 = ($3 | 0) != -1 ? $2 + 1 | 0 : $2; - $3 = Math_clz32($0 ^ $3) + 32 | 0; - $0 = Math_clz32($1 ^ $2); - $0 = ($0 | 0) == 32 ? $3 : $0; - $1 = 63 - $0 | 0; - i64toi32_i32$HIGH_BITS = 0 - ($0 >>> 0 > 63) | 0; - return $1; - } - i64toi32_i32$HIGH_BITS = 0; - return 64; - } - - function __wasm_popcnt_i64($0, $1) { var $2 = 0, $3 = 0, $4 = 0, $5 = 0; - while (1) { - $5 = $4; - $2 = $3; + __inlined_func$__wasm_ctz_i64 : { if ($0 | $1) { - $2 = $0; - $0 = $2 - 1 & $2; - $1 = $1 - ($2 >>> 0 < 1) & $1; - $2 = $4 + 1 | 0; - $3 = $2 >>> 0 < 1 ? $3 + 1 | 0 : $3; + $2 = $1 - 1 | 0; + $3 = $2 + 1 | 0; $4 = $2; - continue; + $2 = $0 - 1 | 0; + $5 = Math_clz32($0 ^ $2) + 32 | 0; + $0 = Math_clz32($1 ^ (($2 | 0) != -1 ? $3 : $4)); + $0 = ($0 | 0) == 32 ? $5 : $0; + $1 = 63 - $0 | 0; + i64toi32_i32$HIGH_BITS = 0 - ($0 >>> 0 > 63) | 0; + $0 = $1; + break __inlined_func$__wasm_ctz_i64; } - break; - }; - i64toi32_i32$HIGH_BITS = $2; - return $5; + i64toi32_i32$HIGH_BITS = 0; + $0 = 64; + } + setTempRet0(i64toi32_i32$HIGH_BITS | 0); + return $0; } return { diff --git a/test/wasm2js/i64-rotate.2asm.js.opt b/test/wasm2js/i64-rotate.2asm.js.opt index b74f97053..ecffd160a 100644 --- a/test/wasm2js/i64-rotate.2asm.js.opt +++ b/test/wasm2js/i64-rotate.2asm.js.opt @@ -15,104 +15,100 @@ function asmFunc(env) { var infinity = Infinity; var i64toi32_i32$HIGH_BITS = 0; function legalstub$1($0, $1, $2, $3, $4, $5) { - return (__wasm_rotl_i64($0, $1, $2) | 0) == ($4 | 0) & ($5 | 0) == (i64toi32_i32$HIGH_BITS | 0); - } - - function legalstub$2($0, $1, $2, $3, $4, $5) { - return (__wasm_rotr_i64($0, $1, $2) | 0) == ($4 | 0) & ($5 | 0) == (i64toi32_i32$HIGH_BITS | 0); - } - - function __wasm_rotl_i64($0, $1, $2) { - var $3 = 0, $4 = 0, $5 = 0, $6 = 0; - $6 = $2 & 63; - $5 = $6; - $3 = $5 & 31; - if ($5 >>> 0 >= 32) { - $3 = -1 >>> $3 | 0 + var $6 = 0, $7 = 0, $8 = 0; + $3 = $0; + $8 = $2 & 63; + $6 = $8; + $0 = $6 & 31; + if ($6 >>> 0 >= 32) { + $0 = -1 >>> $0 | 0 } else { - $4 = -1 >>> $3 | 0; - $3 = (1 << $3) - 1 << 32 - $3 | -1 >>> $3; + $7 = -1 >>> $0 | 0; + $0 = (1 << $0) - 1 << 32 - $0 | -1 >>> $0; } - $5 = $3 & $0; - $3 = $1 & $4; - $4 = $6 & 31; - if ($6 >>> 0 >= 32) { - $3 = $5 << $4; - $6 = 0; + $6 = $0 & $3; + $0 = $1 & $7; + $7 = $8 & 31; + if ($8 >>> 0 >= 32) { + $0 = $6 << $7; + $8 = 0; } else { - $3 = (1 << $4) - 1 & $5 >>> 32 - $4 | $3 << $4; - $6 = $5 << $4; + $0 = (1 << $7) - 1 & $6 >>> 32 - $7 | $0 << $7; + $8 = $6 << $7; } - $5 = $3; - $4 = 0 - $2 & 63; - $3 = $4; - $2 = $3 & 31; - if ($3 >>> 0 >= 32) { - $3 = -1 << $2; + $7 = $0; + $6 = 0 - $2 & 63; + $0 = $6; + $2 = $0 & 31; + if ($0 >>> 0 >= 32) { + $0 = -1 << $2; $2 = 0; } else { - $3 = (1 << $2) - 1 & -1 >>> 32 - $2 | -1 << $2; + $0 = (1 << $2) - 1 & -1 >>> 32 - $2 | -1 << $2; $2 = -1 << $2; } - $0 = $2 & $0; - $3 = $1 & $3; - $1 = $4 & 31; - if ($4 >>> 0 >= 32) { + $3 = $2 & $3; + $1 = $0 & $1; + $0 = $6 & 31; + if ($6 >>> 0 >= 32) { $2 = 0; - $0 = $3 >>> $1 | 0; + $0 = $1 >>> $0 | 0; } else { - $2 = $3 >>> $1 | 0; - $0 = ((1 << $1) - 1 & $3) << 32 - $1 | $0 >>> $1; + $2 = $1 >>> $0 | 0; + $0 = ((1 << $0) - 1 & $1) << 32 - $0 | $3 >>> $0; } - $0 = $0 | $6; - i64toi32_i32$HIGH_BITS = $2 | $5; - return $0; + $0 = $0 | $8; + i64toi32_i32$HIGH_BITS = $2 | $7; + return ($0 | 0) == ($4 | 0) & ($5 | 0) == (i64toi32_i32$HIGH_BITS | 0); } - function __wasm_rotr_i64($0, $1, $2) { - var $3 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0; - $6 = $2 & 63; - $3 = $6 & 31; - if ($6 >>> 0 >= 32) { - $4 = -1 << $3; - $7 = 0; + function legalstub$2($0, $1, $2, $3, $4, $5) { + var $6 = 0, $7 = 0, $8 = 0, $9 = 0; + $3 = $0; + $8 = $2 & 63; + $0 = $8; + $6 = $0 & 31; + if ($0 >>> 0 >= 32) { + $0 = -1 << $6; + $6 = 0; } else { - $4 = (1 << $3) - 1 & -1 >>> 32 - $3 | -1 << $3; - $7 = -1 << $3; + $0 = (1 << $6) - 1 & -1 >>> 32 - $6 | -1 << $6; + $6 = -1 << $6; } - $7 = $7 & $0; - $3 = $1 & $4; - $5 = $6 & 31; - if ($6 >>> 0 >= 32) { - $4 = 0; - $6 = $3 >>> $5 | 0; + $9 = $6 & $3; + $7 = $0 & $1; + $6 = $8 & 31; + if ($8 >>> 0 >= 32) { + $0 = 0; + $8 = $7 >>> $6 | 0; } else { - $4 = $3 >>> $5 | 0; - $6 = ((1 << $5) - 1 & $3) << 32 - $5 | $7 >>> $5; + $0 = $7 >>> $6 | 0; + $8 = ((1 << $6) - 1 & $7) << 32 - $6 | $9 >>> $6; } - $7 = $4; - $3 = 0 - $2 & 63; - $5 = $3 & 31; - if ($3 >>> 0 >= 32) { - $4 = 0; - $2 = -1 >>> $5 | 0; + $6 = $0; + $7 = 0 - $2 & 63; + $0 = $7; + $2 = $0 & 31; + if ($0 >>> 0 >= 32) { + $0 = 0; + $2 = -1 >>> $2 | 0; } else { - $4 = -1 >>> $5 | 0; - $2 = (1 << $5) - 1 << 32 - $5 | -1 >>> $5; + $0 = -1 >>> $2 | 0; + $2 = (1 << $2) - 1 << 32 - $2 | -1 >>> $2; } - $0 = $2 & $0; - $1 = $1 & $4; - $4 = $3 & 31; - if ($3 >>> 0 >= 32) { - $2 = $0 << $4; + $2 = $2 & $3; + $1 = $0 & $1; + $0 = $7 & 31; + if ($7 >>> 0 >= 32) { + $1 = $2 << $0; $0 = 0; } else { - $2 = (1 << $4) - 1 & $0 >>> 32 - $4 | $1 << $4; - $0 = $0 << $4; + $1 = (1 << $0) - 1 & $2 >>> 32 - $0 | $1 << $0; + $0 = $2 << $0; } - $0 = $0 | $6; - i64toi32_i32$HIGH_BITS = $2 | $7; - return $0; + $0 = $0 | $8; + i64toi32_i32$HIGH_BITS = $1 | $6; + return ($0 | 0) == ($4 | 0) & ($5 | 0) == (i64toi32_i32$HIGH_BITS | 0); } return { diff --git a/test/wasm2js/i64-shifts.2asm.js.opt b/test/wasm2js/i64-shifts.2asm.js.opt index 488263496..3bc6cac10 100644 --- a/test/wasm2js/i64-shifts.2asm.js.opt +++ b/test/wasm2js/i64-shifts.2asm.js.opt @@ -13,48 +13,28 @@ function asmFunc(env) { var abort = env.abort; var nan = NaN; var infinity = Infinity; - function $1($0, $1_1, $2_1, $3, $4) { - $0 = $0 | 0; - $1_1 = $1_1 | 0; - $2_1 = $2_1 | 0; - $3 = $3 | 0; - $4 = $4 | 0; - var $5 = 0; - $5 = $2_1 & 31; - if (($2_1 & 63) >>> 0 >= 32) { - $1_1 = $0 << $5; + function legalstub$1($0, $1, $2, $3, $4, $5) { + $3 = $2 & 31; + if (($2 & 63) >>> 0 >= 32) { + $1 = $0 << $3; $0 = 0; } else { - $1_1 = (1 << $5) - 1 & $0 >>> 32 - $5 | $1_1 << $5; - $0 = $0 << $5; + $1 = (1 << $3) - 1 & $0 >>> 32 - $3 | $1 << $3; + $0 = $0 << $3; } - return ($0 | 0) == ($3 | 0) & ($1_1 | 0) == ($4 | 0); + return ($0 | 0) == ($4 | 0) & ($1 | 0) == ($5 | 0); } - function $2($0, $1_1, $2_1, $3, $4) { - $0 = $0 | 0; - $1_1 = $1_1 | 0; - $2_1 = $2_1 | 0; - $3 = $3 | 0; - $4 = $4 | 0; - var $5 = 0; - $5 = $2_1 & 31; - if (($2_1 & 63) >>> 0 >= 32) { - $2_1 = $1_1 >> 31; - $0 = $1_1 >> $5; + function legalstub$2($0, $1, $2, $3, $4, $5) { + $3 = $2 & 31; + if (($2 & 63) >>> 0 >= 32) { + $2 = $1 >> 31; + $0 = $1 >> $3; } else { - $2_1 = $1_1 >> $5; - $0 = ((1 << $5) - 1 & $1_1) << 32 - $5 | $0 >>> $5; + $2 = $1 >> $3; + $0 = ((1 << $3) - 1 & $1) << 32 - $3 | $0 >>> $3; } - return ($0 | 0) == ($3 | 0) & ($2_1 | 0) == ($4 | 0); - } - - function legalstub$1($0, $1_1, $2_1, $3, $4, $5) { - return $1($0, $1_1, $2_1, $4, $5); - } - - function legalstub$2($0, $1_1, $2_1, $3, $4, $5) { - return $2($0, $1_1, $2_1, $4, $5); + return ($0 | 0) == ($4 | 0) & ($2 | 0) == ($5 | 0); } return { diff --git a/test/wasm2js/reinterpret.2asm.js.opt b/test/wasm2js/reinterpret.2asm.js.opt index ffb64c1fa..cc5d4e984 100644 --- a/test/wasm2js/reinterpret.2asm.js.opt +++ b/test/wasm2js/reinterpret.2asm.js.opt @@ -48,19 +48,13 @@ function asmFunc(env) { return ((wasm2js_scratch_store_f32((wasm2js_scratch_store_i32(2, $0), wasm2js_scratch_load_f32())), wasm2js_scratch_load_i32(2)) | 0) == ($0 | 0) | 0; } - function $2($0, $1_1) { - $0 = $0 | 0; - $1_1 = $1_1 | 0; - var $2_1 = 0; + function legalstub$2($0, $1_1) { + var $2 = 0; wasm2js_scratch_store_i32(0, $0 | 0); wasm2js_scratch_store_i32(1, $1_1 | 0); wasm2js_scratch_store_f64(+wasm2js_scratch_load_f64()); - $2_1 = wasm2js_scratch_load_i32(1) | 0; - return (wasm2js_scratch_load_i32(0) | 0) == ($0 | 0) & ($1_1 | 0) == ($2_1 | 0); - } - - function legalstub$2($0, $1_1) { - return $2($0, $1_1); + $2 = wasm2js_scratch_load_i32(1) | 0; + return (wasm2js_scratch_load_i32(0) | 0) == ($0 | 0) & ($1_1 | 0) == ($2 | 0); } return { diff --git a/test/wasm2js/stack-modified.2asm.js.opt b/test/wasm2js/stack-modified.2asm.js.opt index 60758cce0..f08671743 100644 --- a/test/wasm2js/stack-modified.2asm.js.opt +++ b/test/wasm2js/stack-modified.2asm.js.opt @@ -16,47 +16,34 @@ function asmFunc(env) { var infinity = Infinity; var setTempRet0 = env.setTempRet0; var i64toi32_i32$HIGH_BITS = 0; - function $0($0_1, $1) { - $0_1 = $0_1 | 0; - $1 = $1 | 0; - var $2 = 0, $3 = 0, $4 = 0; - $2 = $1; - $3 = 1; + function legalstub$0($0, $1) { + var $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0; + $4 = $1; + $2 = 1; while (1) { - if ($0_1 | $2) { - $3 = _ZN17compiler_builtins3int3mul3Mul3mul17h070e9a1c69faec5bE($0_1, $2, $3, $4); - $4 = i64toi32_i32$HIGH_BITS; - $1 = $0_1; - $0_1 = $0_1 - 1 | 0; - $2 = $2 - ($1 >>> 0 < 1) | 0; + if ($0 | $4) { + $1 = $2 >>> 16 | 0; + $3 = $0 >>> 16 | 0; + $9 = Math_imul($1, $3); + $5 = $2 & 65535; + $6 = $0 & 65535; + $7 = Math_imul($5, $6); + $3 = ($7 >>> 16 | 0) + Math_imul($3, $5) | 0; + $1 = ($3 & 65535) + Math_imul($1, $6) | 0; + i64toi32_i32$HIGH_BITS = (Math_imul($2, $4) + $9 | 0) + Math_imul($0, $8) + ($3 >>> 16) + ($1 >>> 16) | 0; + $2 = $7 & 65535 | $1 << 16; + $8 = i64toi32_i32$HIGH_BITS; + $1 = $0; + $0 = $1 - 1 | 0; + $4 = $4 - ($1 >>> 0 < 1) | 0; continue; } break; }; - i64toi32_i32$HIGH_BITS = $4; - return $3 | 0; - } - - function legalstub$0($0_1, $1) { - $0_1 = $0($0_1, $1); + i64toi32_i32$HIGH_BITS = $8; + $0 = $2; setTempRet0(i64toi32_i32$HIGH_BITS | 0); - return $0_1; - } - - function _ZN17compiler_builtins3int3mul3Mul3mul17h070e9a1c69faec5bE($0_1, $1, $2, $3) { - var $4 = 0, $5 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0; - $4 = $2 >>> 16 | 0; - $5 = $0_1 >>> 16 | 0; - $9 = Math_imul($4, $5); - $6 = $2 & 65535; - $7 = $0_1 & 65535; - $8 = Math_imul($6, $7); - $5 = ($8 >>> 16 | 0) + Math_imul($5, $6) | 0; - $4 = ($5 & 65535) + Math_imul($4, $7) | 0; - $0_1 = (Math_imul($1, $2) + $9 | 0) + Math_imul($0_1, $3) + ($5 >>> 16) + ($4 >>> 16) | 0; - $1 = $8 & 65535 | $4 << 16; - i64toi32_i32$HIGH_BITS = $0_1; - return $1; + return $0; } return { diff --git a/test/wasm2js/unaligned.2asm.js.opt b/test/wasm2js/unaligned.2asm.js.opt index e5005fef5..1f0fd6f4c 100644 --- a/test/wasm2js/unaligned.2asm.js.opt +++ b/test/wasm2js/unaligned.2asm.js.opt @@ -56,11 +56,6 @@ function asmFunc(env) { return HEAPU8[0] | HEAPU8[1] << 8 | (HEAPU8[2] << 16 | HEAPU8[3] << 24); } - function $1() { - i64toi32_i32$HIGH_BITS = HEAPU8[4] | HEAPU8[5] << 8 | (HEAPU8[6] << 16 | HEAPU8[7] << 24); - return HEAPU8[0] | HEAPU8[1] << 8 | (HEAPU8[2] << 16 | HEAPU8[3] << 24); - } - function $2() { return Math_fround((wasm2js_scratch_store_i32(2, HEAPU8[0] | HEAPU8[1] << 8 | (HEAPU8[2] << 16 | HEAPU8[3] << 24)), wasm2js_scratch_load_f32())); } @@ -92,14 +87,14 @@ function asmFunc(env) { } function $7() { - var $0_1 = 0, $1_1 = 0; + var $0_1 = 0, $1 = 0; wasm2js_scratch_store_f64(0.0); $0_1 = wasm2js_scratch_load_i32(1) | 0; - $1_1 = wasm2js_scratch_load_i32(0) | 0; - HEAP8[0] = $1_1; - HEAP8[1] = $1_1 >>> 8; - HEAP8[2] = $1_1 >>> 16; - HEAP8[3] = $1_1 >>> 24; + $1 = wasm2js_scratch_load_i32(0) | 0; + HEAP8[0] = $1; + HEAP8[1] = $1 >>> 8; + HEAP8[2] = $1 >>> 16; + HEAP8[3] = $1 >>> 24; HEAP8[4] = $0_1; HEAP8[5] = $0_1 >>> 8; HEAP8[6] = $0_1 >>> 16; @@ -108,7 +103,8 @@ function asmFunc(env) { function legalstub$1() { var $0_1 = 0; - $0_1 = $1(); + i64toi32_i32$HIGH_BITS = HEAPU8[4] | HEAPU8[5] << 8 | (HEAPU8[6] << 16 | HEAPU8[7] << 24); + $0_1 = HEAPU8[0] | HEAPU8[1] << 8 | (HEAPU8[2] << 16 | HEAPU8[3] << 24); setTempRet0(i64toi32_i32$HIGH_BITS | 0); return $0_1; } diff --git a/test/wasm2js/unary-ops.2asm.js.opt b/test/wasm2js/unary-ops.2asm.js.opt index cb37b0099..027c9164d 100644 --- a/test/wasm2js/unary-ops.2asm.js.opt +++ b/test/wasm2js/unary-ops.2asm.js.opt @@ -16,7 +16,17 @@ function asmFunc(env) { var i64toi32_i32$HIGH_BITS = 0; function $1($0) { $0 = $0 | 0; - return __wasm_popcnt_i32($0) | 0; + var $1_1 = 0, $2 = 0; + while (1) { + $2 = $1_1; + if ($0) { + $0 = $0 - 1 & $0; + $1_1 = $1_1 + 1 | 0; + continue; + } + break; + }; + return $2 | 0; } function $6($0) { @@ -34,19 +44,25 @@ function asmFunc(env) { return $0 | 0; } - function $8($0, $1_1, $2, $3) { - $0 = $0 | 0; - $1_1 = $1_1 | 0; - $2 = $2 | 0; - $3 = $3 | 0; - var $4 = 0; - $4 = Math_clz32($0) + 32 | 0; - $0 = Math_clz32($1_1); - return !$3 & ($2 | 0) == ((($0 | 0) == 32 ? $4 : $0) | 0); - } - function legalstub$2($0, $1_1, $2, $3) { - return (__wasm_popcnt_i64($0, $1_1) | 0) == ($2 | 0) & ($3 | 0) == (i64toi32_i32$HIGH_BITS | 0); + var $4 = 0, $5 = 0, $6_1 = 0, $7_1 = 0; + $7_1 = $2; + $4 = $1_1; + while (1) { + $2 = $5; + $1_1 = $6_1; + if ($0 | $4) { + $1_1 = $0; + $0 = $1_1 - 1 & $1_1; + $4 = $4 - ($1_1 >>> 0 < 1) & $4; + $5 = $5 + 1 | 0; + $6_1 = $5 >>> 0 < 1 ? $6_1 + 1 | 0 : $6_1; + continue; + } + break; + }; + i64toi32_i32$HIGH_BITS = $1_1; + return ($2 | 0) == ($7_1 | 0) & ($3 | 0) == (i64toi32_i32$HIGH_BITS | 0); } function legalstub$3($0, $1_1, $2) { @@ -62,62 +78,31 @@ function asmFunc(env) { } function legalstub$8($0, $1_1, $2, $3) { - return $8($0, $1_1, $2, $3); + var $4 = 0; + $4 = Math_clz32($0) + 32 | 0; + $0 = Math_clz32($1_1); + return !$3 & ($2 | 0) == ((($0 | 0) == 32 ? $4 : $0) | 0); } function legalstub$9($0, $1_1, $2, $3) { - return (__wasm_ctz_i64($0, $1_1) | 0) == ($2 | 0) & ($3 | 0) == (i64toi32_i32$HIGH_BITS | 0); - } - - function __wasm_ctz_i64($0, $1_1) { - var $2 = 0, $3 = 0; - if ($0 | $1_1) { - $2 = $1_1 - 1 | 0; - $3 = $0 - 1 | 0; - $2 = ($3 | 0) != -1 ? $2 + 1 | 0 : $2; - $3 = Math_clz32($0 ^ $3) + 32 | 0; - $0 = Math_clz32($1_1 ^ $2); - $0 = ($0 | 0) == 32 ? $3 : $0; - $1_1 = 63 - $0 | 0; - i64toi32_i32$HIGH_BITS = 0 - ($0 >>> 0 > 63) | 0; - return $1_1; - } - i64toi32_i32$HIGH_BITS = 0; - return 64; - } - - function __wasm_popcnt_i32($0) { - var $1_1 = 0, $2 = 0; - while (1) { - $2 = $1_1; - if ($0) { - $0 = $0 - 1 & $0; - $1_1 = $1_1 + 1 | 0; - continue; - } - break; - }; - return $2; - } - - function __wasm_popcnt_i64($0, $1_1) { - var $2 = 0, $3 = 0, $4 = 0, $5 = 0; - while (1) { - $5 = $4; - $2 = $3; + var $4 = 0, $5 = 0, $6_1 = 0, $7_1 = 0; + __inlined_func$__wasm_ctz_i64 : { if ($0 | $1_1) { - $2 = $0; - $0 = $2 - 1 & $2; - $1_1 = $1_1 - ($2 >>> 0 < 1) & $1_1; - $2 = $4 + 1 | 0; - $3 = $2 >>> 0 < 1 ? $3 + 1 | 0 : $3; - $4 = $2; - continue; + $4 = $1_1 - 1 | 0; + $5 = $4 + 1 | 0; + $6_1 = $4; + $4 = $0 - 1 | 0; + $7_1 = Math_clz32($0 ^ $4) + 32 | 0; + $0 = Math_clz32($1_1 ^ (($4 | 0) != -1 ? $5 : $6_1)); + $0 = ($0 | 0) == 32 ? $7_1 : $0; + $1_1 = 63 - $0 | 0; + i64toi32_i32$HIGH_BITS = 0 - ($0 >>> 0 > 63) | 0; + break __inlined_func$__wasm_ctz_i64; } - break; - }; - i64toi32_i32$HIGH_BITS = $2; - return $5; + i64toi32_i32$HIGH_BITS = 0; + $1_1 = 64; + } + return ($1_1 | 0) == ($2 | 0) & ($3 | 0) == (i64toi32_i32$HIGH_BITS | 0); } return { |