Skip to content

Commit

Permalink
Look through fallthrough values in precompute-propagate (#2093)
Browse files Browse the repository at this point in the history
This helps quite a lot on wasm2js.
  • Loading branch information
kripken authored May 10, 2019
1 parent d216f87 commit 4b35f38
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 358 deletions.
4 changes: 3 additions & 1 deletion src/passes/Precompute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <ir/literal-utils.h>
#include <ir/local-graph.h>
#include <ir/manipulation.h>
#include <ir/properties.h>
#include <ir/utils.h>
#include <pass.h>
#include <wasm-builder.h>
Expand Down Expand Up @@ -308,7 +309,8 @@ struct Precompute
if (setValues[set].isConcrete()) {
continue; // already known constant
}
auto value = setValues[set] = precomputeValue(set->value);
auto value = setValues[set] =
precomputeValue(Properties::getFallthrough(set->value));
if (value.isConcrete()) {
for (auto* get : localGraph.setInfluences[set]) {
work.insert(get);
Expand Down
13 changes: 13 additions & 0 deletions test/passes/precompute-propagate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,17 @@
(nop)
(local.get $2)
)
(func $through-fallthrough (; 16 ;) (type $2) (param $x i32) (param $y i32) (result i32)
(local.set $x
(block $block (result i32)
(nop)
(local.tee $y
(i32.const 7)
)
)
)
(return
(i32.const 14)
)
)
)
16 changes: 16 additions & 0 deletions test/passes/precompute-propagate.wast
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,21 @@
)
(local.get $2)
)
(func $through-fallthrough (param $x i32) (param $y i32) (result i32)
(local.set $x
(block (result i32)
(nop)
(local.tee $y
(i32.const 7)
)
)
)
(return
(i32.add
(local.get $x)
(local.get $y)
)
)
)
)

22 changes: 8 additions & 14 deletions test/wasm2js/conversions-modified.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,17 @@ function asmFunc(global, env, buffer) {
}

function legalstub$7($0) {
var $1 = 0, $2 = 0, $3_1 = 0, $4_1 = 0;
$2 = $7($0);
$3_1 = i64toi32_i32$HIGH_BITS;
$4_1 = 32;
$1 = $4_1 & 31;
setTempRet0((32 >>> 0 <= $4_1 >>> 0 ? $3_1 >>> $1 : ((1 << $1) - 1 & $3_1) << 32 - $1 | $2 >>> $1) | 0);
return $2;
var $1 = 0;
$1 = $7($0);
setTempRet0(i64toi32_i32$HIGH_BITS | 0);
return $1;
}

function legalstub$9($0) {
var $1 = 0, $2 = 0, $3_1 = 0, $4_1 = 0;
$2 = $9($0);
$3_1 = i64toi32_i32$HIGH_BITS;
$4_1 = 32;
$1 = $4_1 & 31;
setTempRet0((32 >>> 0 <= $4_1 >>> 0 ? $3_1 >>> $1 : ((1 << $1) - 1 & $3_1) << 32 - $1 | $2 >>> $1) | 0);
return $2;
var $1 = 0;
$1 = $9($0);
setTempRet0(i64toi32_i32$HIGH_BITS | 0);
return $1;
}

function legalstub$12($0, $1) {
Expand Down
4 changes: 2 additions & 2 deletions test/wasm2js/float-ops.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ function asmFunc(global, env, buffer) {

function $47($0) {
$0 = Math_fround($0);
return !((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(4294967296.0)))), Math_fround(4294967296.0))) >>> 0 : ~~Math_fround(Math_ceil(Math_fround(Math_fround($0 - Math_fround(~~$0 >>> 0 >>> 0)) / Math_fround(4294967296.0)))) >>> 0) : 0) | ~~$0 >>> 0) | 0;
return !(~~$0 >>> 0 | (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(4294967296.0)))), Math_fround(4294967296.0))) >>> 0 : ~~Math_fround(Math_ceil(Math_fround(Math_fround($0 - Math_fround(~~$0 >>> 0 >>> 0)) / Math_fround(4294967296.0)))) >>> 0) : 0)) | 0;
}

function $48($0) {
$0 = +$0;
return !((Math_abs($0) >= 1.0 ? ($0 > 0.0 ? ~~Math_min(Math_floor($0 / 4294967296.0), 4294967295.0) >>> 0 : ~~Math_ceil(($0 - +(~~$0 >>> 0 >>> 0)) / 4294967296.0) >>> 0) : 0) | ~~$0 >>> 0) | 0;
return !(~~$0 >>> 0 | (Math_abs($0) >= 1.0 ? ($0 > 0.0 ? ~~Math_min(Math_floor($0 / 4294967296.0), 4294967295.0) >>> 0 : ~~Math_ceil(($0 - +(~~$0 >>> 0 >>> 0)) / 4294967296.0) >>> 0) : 0)) | 0;
}

function legalstub$43($0, $1_1) {
Expand Down
6 changes: 1 addition & 5 deletions test/wasm2js/get-set-local.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ function asmFunc(global, env, buffer) {
var nan = global.NaN;
var infinity = global.Infinity;
function legalstub$1($0, $1, $2) {
var $3 = 0;
$3 = $1;
$1 = $2;
$2 = $3 | 0;
return !$1 & ($0 | 0) == ($2 | 0);
return !$2 & ($0 | 0) == ($1 | 0);
}

var FUNCTION_TABLE = [];
Expand Down
41 changes: 2 additions & 39 deletions test/wasm2js/i64-add-sub.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -36,48 +36,11 @@ function asmFunc(global, env, buffer) {
}

function legalstub$1($0, $1_1, $2, $3, $4, $5) {
var $6 = 0, $7 = 0;
$7 = $0;
$6 = 32;
$0 = $6 & 31;
if (32 >>> 0 <= $6 >>> 0) {
$6 = $1_1 << $0;
$0 = 0;
} else {
$6 = (1 << $0) - 1 & $1_1 >>> 32 - $0;
$0 = $1_1 << $0;
}
$7 = $7 | $0;
$1_1 = 32;
$0 = $1_1 & 31;
if (32 >>> 0 <= $1_1 >>> 0) {
$1_1 = $3 << $0;
$0 = 0;
} else {
$1_1 = (1 << $0) - 1 & $3 >>> 32 - $0;
$0 = $3 << $0;
}
$3 = $0 | $2;
$2 = $1_1;
$1_1 = 32;
$0 = $1_1 & 31;
if (32 >>> 0 <= $1_1 >>> 0) {
$1_1 = $5 << $0;
$0 = 0;
} else {
$1_1 = (1 << $0) - 1 & $5 >>> 32 - $0;
$0 = $5 << $0;
}
return $1($7, $6, $3, $2, $0 | $4, $1_1);
return $1($0, $1_1, $2, $3, $4, $5);
}

function legalstub$2($0, $1_1, $2, $3, $4, $5) {
var $6 = 0;
$6 = $0;
$0 = $1_1;
$1_1 = $3;
$3 = $2;
return ($4 | 0) == ($6 - $3 | 0) & ($5 | 0) == ($0 - (($6 >>> 0 < $3 >>> 0) + $1_1 | 0) | 0);
return ($4 | 0) == ($0 - $2 | 0) & ($5 | 0) == ($1_1 - (($0 >>> 0 < $2 >>> 0) + $3 | 0) | 0);
}

var FUNCTION_TABLE = [];
Expand Down
34 changes: 15 additions & 19 deletions test/wasm2js/i64-ctz.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,18 @@ function asmFunc(global, env, buffer) {
}

function __wasm_ctz_i64($0, $1) {
var $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0;
var $2 = 0, $3 = 0;
if ($0 | $1) {
$4 = 63;
$6 = $4;
$3 = $1 + -1 | 0;
$2 = -1;
$5 = $2 + $0 | 0;
if ($5 >>> 0 < $2 >>> 0) {
$2 = $0 + -1 | 0;
if ($2 >>> 0 < -1 >>> 0) {
$3 = $3 + 1 | 0
}
$2 = Math_clz32($0 ^ $5) + 32 | 0;
$2 = Math_clz32($0 ^ $2) + 32 | 0;
$0 = Math_clz32($1 ^ $3);
$0 = ($0 | 0) == (32 | 0) ? $2 : $0;
$1 = $6 - $0 | 0;
i64toi32_i32$HIGH_BITS = 0 - ($4 >>> 0 < $0 >>> 0) | 0;
$1 = 63 - $0 | 0;
i64toi32_i32$HIGH_BITS = 0 - (63 >>> 0 < $0 >>> 0) | 0;
return $1;
}
i64toi32_i32$HIGH_BITS = 0;
Expand All @@ -60,24 +57,23 @@ function asmFunc(global, env, buffer) {
function __wasm_popcnt_i64($0, $1) {
var $2 = 0, $3 = 0, $4 = 0, $5 = 0;
label$2 : while (1) {
$3 = $4;
$2 = $5;
$5 = $3;
$2 = $4;
if ($0 | $1) {
$2 = $0;
$3 = 1;
$0 = $2 - $3 & $2;
$1 = $1 - ($2 >>> 0 < $3 >>> 0) & $1;
$2 = 1 + $4 | 0;
if ($2 >>> 0 < $3 >>> 0) {
$5 = $5 + 1 | 0
$0 = $2 - 1 & $2;
$1 = $1 - ($2 >>> 0 < 1 >>> 0) & $1;
$2 = $3 + 1 | 0;
if ($2 >>> 0 < 1 >>> 0) {
$4 = $4 + 1 | 0
}
$4 = $2;
$3 = $2;
continue;
}
break;
};
i64toi32_i32$HIGH_BITS = $2;
return $3;
return $5;
}

var FUNCTION_TABLE = [];
Expand Down
116 changes: 8 additions & 108 deletions test/wasm2js/i64-lowering.2asm.js.opt
Original file line number Diff line number Diff line change
Expand Up @@ -61,135 +61,35 @@ function asmFunc(global, env, buffer) {
}

function legalstub$3($0, $1, $2, $3_1) {
var $4_1 = 0, $5_1 = 0;
$5_1 = $0;
$4_1 = 32;
$0 = $4_1 & 31;
if (32 >>> 0 <= $4_1 >>> 0) {
$4_1 = $1 << $0;
$0 = 0;
} else {
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
$0 = $1 << $0;
}
$5_1 = $5_1 | $0;
$1 = 32;
$0 = $1 & 31;
if (32 >>> 0 <= $1 >>> 0) {
$1 = $3_1 << $0;
$0 = 0;
} else {
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
$0 = $3_1 << $0;
}
return $3($5_1, $4_1, $0 | $2, $1);
return $3($0, $1, $2, $3_1);
}

function legalstub$4($0, $1, $2, $3_1) {
var $4_1 = 0, $5_1 = 0;
$5_1 = $0;
$4_1 = 32;
$0 = $4_1 & 31;
if (32 >>> 0 <= $4_1 >>> 0) {
$4_1 = $1 << $0;
$0 = 0;
} else {
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
$0 = $1 << $0;
}
$5_1 = $5_1 | $0;
$1 = 32;
$0 = $1 & 31;
if (32 >>> 0 <= $1 >>> 0) {
$1 = $3_1 << $0;
$0 = 0;
} else {
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
$0 = $3_1 << $0;
}
return $4($5_1, $4_1, $0 | $2, $1);
return $4($0, $1, $2, $3_1);
}

function legalstub$5($0, $1, $2, $3_1) {
var $4_1 = 0, $5_1 = 0;
$5_1 = $0;
$4_1 = 32;
$0 = $4_1 & 31;
if (32 >>> 0 <= $4_1 >>> 0) {
$4_1 = $1 << $0;
$0 = 0;
} else {
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
$0 = $1 << $0;
}
$5_1 = $5_1 | $0;
$1 = 32;
$0 = $1 & 31;
if (32 >>> 0 <= $1 >>> 0) {
$1 = $3_1 << $0;
$0 = 0;
} else {
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
$0 = $3_1 << $0;
}
return $5($5_1, $4_1, $0 | $2, $1);
return $5($0, $1, $2, $3_1);
}

function legalstub$6($0, $1, $2, $3_1) {
var $4_1 = 0, $5_1 = 0;
$5_1 = $0;
$4_1 = 32;
$0 = $4_1 & 31;
if (32 >>> 0 <= $4_1 >>> 0) {
$4_1 = $1 << $0;
$0 = 0;
} else {
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
$0 = $1 << $0;
}
$5_1 = $5_1 | $0;
$1 = 32;
$0 = $1 & 31;
if (32 >>> 0 <= $1 >>> 0) {
$1 = $3_1 << $0;
$0 = 0;
} else {
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
$0 = $3_1 << $0;
}
return $6($5_1, $4_1, $0 | $2, $1);
return $6($0, $1, $2, $3_1);
}

function legalstub$7($0, $1, $2, $3_1) {
var $4_1 = 0;
$4_1 = $0;
$0 = $1;
$1 = $3_1;
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 >= $2 >>> 0 | $0 >>> 0 > $1 >>> 0;
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 >= $2 >>> 0 | $1 >>> 0 > $3_1 >>> 0;
}

function legalstub$8($0, $1, $2, $3_1) {
var $4_1 = 0;
$4_1 = $0;
$0 = $1;
$1 = $3_1;
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 > $2 >>> 0 | $0 >>> 0 > $1 >>> 0;
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 > $2 >>> 0 | $1 >>> 0 > $3_1 >>> 0;
}

function legalstub$9($0, $1, $2, $3_1) {
var $4_1 = 0;
$4_1 = $0;
$0 = $1;
$1 = $3_1;
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 <= $2 >>> 0 | $0 >>> 0 < $1 >>> 0;
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 <= $2 >>> 0 | $1 >>> 0 < $3_1 >>> 0;
}

function legalstub$10($0, $1, $2, $3_1) {
var $4_1 = 0;
$4_1 = $0;
$0 = $1;
$1 = $3_1;
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 < $2 >>> 0 | $0 >>> 0 < $1 >>> 0;
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 < $2 >>> 0 | $1 >>> 0 < $3_1 >>> 0;
}

var FUNCTION_TABLE = [];
Expand Down
Loading

0 comments on commit 4b35f38

Please sign in to comment.