Skip to content

Commit 4b35f38

Browse files
authored
Look through fallthrough values in precompute-propagate (#2093)
This helps quite a lot on wasm2js.
1 parent d216f87 commit 4b35f38

14 files changed

+107
-358
lines changed

src/passes/Precompute.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <ir/literal-utils.h>
3131
#include <ir/local-graph.h>
3232
#include <ir/manipulation.h>
33+
#include <ir/properties.h>
3334
#include <ir/utils.h>
3435
#include <pass.h>
3536
#include <wasm-builder.h>
@@ -308,7 +309,8 @@ struct Precompute
308309
if (setValues[set].isConcrete()) {
309310
continue; // already known constant
310311
}
311-
auto value = setValues[set] = precomputeValue(set->value);
312+
auto value = setValues[set] =
313+
precomputeValue(Properties::getFallthrough(set->value));
312314
if (value.isConcrete()) {
313315
for (auto* get : localGraph.setInfluences[set]) {
314316
work.insert(get);

test/passes/precompute-propagate.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,17 @@
241241
(nop)
242242
(local.get $2)
243243
)
244+
(func $through-fallthrough (; 16 ;) (type $2) (param $x i32) (param $y i32) (result i32)
245+
(local.set $x
246+
(block $block (result i32)
247+
(nop)
248+
(local.tee $y
249+
(i32.const 7)
250+
)
251+
)
252+
)
253+
(return
254+
(i32.const 14)
255+
)
256+
)
244257
)

test/passes/precompute-propagate.wast

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,21 @@
154154
)
155155
(local.get $2)
156156
)
157+
(func $through-fallthrough (param $x i32) (param $y i32) (result i32)
158+
(local.set $x
159+
(block (result i32)
160+
(nop)
161+
(local.tee $y
162+
(i32.const 7)
163+
)
164+
)
165+
)
166+
(return
167+
(i32.add
168+
(local.get $x)
169+
(local.get $y)
170+
)
171+
)
172+
)
157173
)
158174

test/wasm2js/conversions-modified.2asm.js.opt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,17 @@ function asmFunc(global, env, buffer) {
142142
}
143143

144144
function legalstub$7($0) {
145-
var $1 = 0, $2 = 0, $3_1 = 0, $4_1 = 0;
146-
$2 = $7($0);
147-
$3_1 = i64toi32_i32$HIGH_BITS;
148-
$4_1 = 32;
149-
$1 = $4_1 & 31;
150-
setTempRet0((32 >>> 0 <= $4_1 >>> 0 ? $3_1 >>> $1 : ((1 << $1) - 1 & $3_1) << 32 - $1 | $2 >>> $1) | 0);
151-
return $2;
145+
var $1 = 0;
146+
$1 = $7($0);
147+
setTempRet0(i64toi32_i32$HIGH_BITS | 0);
148+
return $1;
152149
}
153150

154151
function legalstub$9($0) {
155-
var $1 = 0, $2 = 0, $3_1 = 0, $4_1 = 0;
156-
$2 = $9($0);
157-
$3_1 = i64toi32_i32$HIGH_BITS;
158-
$4_1 = 32;
159-
$1 = $4_1 & 31;
160-
setTempRet0((32 >>> 0 <= $4_1 >>> 0 ? $3_1 >>> $1 : ((1 << $1) - 1 & $3_1) << 32 - $1 | $2 >>> $1) | 0);
161-
return $2;
152+
var $1 = 0;
153+
$1 = $9($0);
154+
setTempRet0(i64toi32_i32$HIGH_BITS | 0);
155+
return $1;
162156
}
163157

164158
function legalstub$12($0, $1) {

test/wasm2js/float-ops.2asm.js.opt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ function asmFunc(global, env, buffer) {
246246

247247
function $47($0) {
248248
$0 = Math_fround($0);
249-
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;
249+
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;
250250
}
251251

252252
function $48($0) {
253253
$0 = +$0;
254-
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;
254+
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;
255255
}
256256

257257
function legalstub$43($0, $1_1) {

test/wasm2js/get-set-local.2asm.js.opt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ function asmFunc(global, env, buffer) {
2121
var nan = global.NaN;
2222
var infinity = global.Infinity;
2323
function legalstub$1($0, $1, $2) {
24-
var $3 = 0;
25-
$3 = $1;
26-
$1 = $2;
27-
$2 = $3 | 0;
28-
return !$1 & ($0 | 0) == ($2 | 0);
24+
return !$2 & ($0 | 0) == ($1 | 0);
2925
}
3026

3127
var FUNCTION_TABLE = [];

test/wasm2js/i64-add-sub.2asm.js.opt

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,48 +36,11 @@ function asmFunc(global, env, buffer) {
3636
}
3737

3838
function legalstub$1($0, $1_1, $2, $3, $4, $5) {
39-
var $6 = 0, $7 = 0;
40-
$7 = $0;
41-
$6 = 32;
42-
$0 = $6 & 31;
43-
if (32 >>> 0 <= $6 >>> 0) {
44-
$6 = $1_1 << $0;
45-
$0 = 0;
46-
} else {
47-
$6 = (1 << $0) - 1 & $1_1 >>> 32 - $0;
48-
$0 = $1_1 << $0;
49-
}
50-
$7 = $7 | $0;
51-
$1_1 = 32;
52-
$0 = $1_1 & 31;
53-
if (32 >>> 0 <= $1_1 >>> 0) {
54-
$1_1 = $3 << $0;
55-
$0 = 0;
56-
} else {
57-
$1_1 = (1 << $0) - 1 & $3 >>> 32 - $0;
58-
$0 = $3 << $0;
59-
}
60-
$3 = $0 | $2;
61-
$2 = $1_1;
62-
$1_1 = 32;
63-
$0 = $1_1 & 31;
64-
if (32 >>> 0 <= $1_1 >>> 0) {
65-
$1_1 = $5 << $0;
66-
$0 = 0;
67-
} else {
68-
$1_1 = (1 << $0) - 1 & $5 >>> 32 - $0;
69-
$0 = $5 << $0;
70-
}
71-
return $1($7, $6, $3, $2, $0 | $4, $1_1);
39+
return $1($0, $1_1, $2, $3, $4, $5);
7240
}
7341

7442
function legalstub$2($0, $1_1, $2, $3, $4, $5) {
75-
var $6 = 0;
76-
$6 = $0;
77-
$0 = $1_1;
78-
$1_1 = $3;
79-
$3 = $2;
80-
return ($4 | 0) == ($6 - $3 | 0) & ($5 | 0) == ($0 - (($6 >>> 0 < $3 >>> 0) + $1_1 | 0) | 0);
43+
return ($4 | 0) == ($0 - $2 | 0) & ($5 | 0) == ($1_1 - (($0 >>> 0 < $2 >>> 0) + $3 | 0) | 0);
8144
}
8245

8346
var FUNCTION_TABLE = [];

test/wasm2js/i64-ctz.2asm.js.opt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,18 @@ function asmFunc(global, env, buffer) {
3636
}
3737

3838
function __wasm_ctz_i64($0, $1) {
39-
var $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0;
39+
var $2 = 0, $3 = 0;
4040
if ($0 | $1) {
41-
$4 = 63;
42-
$6 = $4;
4341
$3 = $1 + -1 | 0;
44-
$2 = -1;
45-
$5 = $2 + $0 | 0;
46-
if ($5 >>> 0 < $2 >>> 0) {
42+
$2 = $0 + -1 | 0;
43+
if ($2 >>> 0 < -1 >>> 0) {
4744
$3 = $3 + 1 | 0
4845
}
49-
$2 = Math_clz32($0 ^ $5) + 32 | 0;
46+
$2 = Math_clz32($0 ^ $2) + 32 | 0;
5047
$0 = Math_clz32($1 ^ $3);
5148
$0 = ($0 | 0) == (32 | 0) ? $2 : $0;
52-
$1 = $6 - $0 | 0;
53-
i64toi32_i32$HIGH_BITS = 0 - ($4 >>> 0 < $0 >>> 0) | 0;
49+
$1 = 63 - $0 | 0;
50+
i64toi32_i32$HIGH_BITS = 0 - (63 >>> 0 < $0 >>> 0) | 0;
5451
return $1;
5552
}
5653
i64toi32_i32$HIGH_BITS = 0;
@@ -60,24 +57,23 @@ function asmFunc(global, env, buffer) {
6057
function __wasm_popcnt_i64($0, $1) {
6158
var $2 = 0, $3 = 0, $4 = 0, $5 = 0;
6259
label$2 : while (1) {
63-
$3 = $4;
64-
$2 = $5;
60+
$5 = $3;
61+
$2 = $4;
6562
if ($0 | $1) {
6663
$2 = $0;
67-
$3 = 1;
68-
$0 = $2 - $3 & $2;
69-
$1 = $1 - ($2 >>> 0 < $3 >>> 0) & $1;
70-
$2 = 1 + $4 | 0;
71-
if ($2 >>> 0 < $3 >>> 0) {
72-
$5 = $5 + 1 | 0
64+
$0 = $2 - 1 & $2;
65+
$1 = $1 - ($2 >>> 0 < 1 >>> 0) & $1;
66+
$2 = $3 + 1 | 0;
67+
if ($2 >>> 0 < 1 >>> 0) {
68+
$4 = $4 + 1 | 0
7369
}
74-
$4 = $2;
70+
$3 = $2;
7571
continue;
7672
}
7773
break;
7874
};
7975
i64toi32_i32$HIGH_BITS = $2;
80-
return $3;
76+
return $5;
8177
}
8278

8379
var FUNCTION_TABLE = [];

test/wasm2js/i64-lowering.2asm.js.opt

Lines changed: 8 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -61,135 +61,35 @@ function asmFunc(global, env, buffer) {
6161
}
6262

6363
function legalstub$3($0, $1, $2, $3_1) {
64-
var $4_1 = 0, $5_1 = 0;
65-
$5_1 = $0;
66-
$4_1 = 32;
67-
$0 = $4_1 & 31;
68-
if (32 >>> 0 <= $4_1 >>> 0) {
69-
$4_1 = $1 << $0;
70-
$0 = 0;
71-
} else {
72-
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
73-
$0 = $1 << $0;
74-
}
75-
$5_1 = $5_1 | $0;
76-
$1 = 32;
77-
$0 = $1 & 31;
78-
if (32 >>> 0 <= $1 >>> 0) {
79-
$1 = $3_1 << $0;
80-
$0 = 0;
81-
} else {
82-
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
83-
$0 = $3_1 << $0;
84-
}
85-
return $3($5_1, $4_1, $0 | $2, $1);
64+
return $3($0, $1, $2, $3_1);
8665
}
8766

8867
function legalstub$4($0, $1, $2, $3_1) {
89-
var $4_1 = 0, $5_1 = 0;
90-
$5_1 = $0;
91-
$4_1 = 32;
92-
$0 = $4_1 & 31;
93-
if (32 >>> 0 <= $4_1 >>> 0) {
94-
$4_1 = $1 << $0;
95-
$0 = 0;
96-
} else {
97-
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
98-
$0 = $1 << $0;
99-
}
100-
$5_1 = $5_1 | $0;
101-
$1 = 32;
102-
$0 = $1 & 31;
103-
if (32 >>> 0 <= $1 >>> 0) {
104-
$1 = $3_1 << $0;
105-
$0 = 0;
106-
} else {
107-
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
108-
$0 = $3_1 << $0;
109-
}
110-
return $4($5_1, $4_1, $0 | $2, $1);
68+
return $4($0, $1, $2, $3_1);
11169
}
11270

11371
function legalstub$5($0, $1, $2, $3_1) {
114-
var $4_1 = 0, $5_1 = 0;
115-
$5_1 = $0;
116-
$4_1 = 32;
117-
$0 = $4_1 & 31;
118-
if (32 >>> 0 <= $4_1 >>> 0) {
119-
$4_1 = $1 << $0;
120-
$0 = 0;
121-
} else {
122-
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
123-
$0 = $1 << $0;
124-
}
125-
$5_1 = $5_1 | $0;
126-
$1 = 32;
127-
$0 = $1 & 31;
128-
if (32 >>> 0 <= $1 >>> 0) {
129-
$1 = $3_1 << $0;
130-
$0 = 0;
131-
} else {
132-
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
133-
$0 = $3_1 << $0;
134-
}
135-
return $5($5_1, $4_1, $0 | $2, $1);
72+
return $5($0, $1, $2, $3_1);
13673
}
13774

13875
function legalstub$6($0, $1, $2, $3_1) {
139-
var $4_1 = 0, $5_1 = 0;
140-
$5_1 = $0;
141-
$4_1 = 32;
142-
$0 = $4_1 & 31;
143-
if (32 >>> 0 <= $4_1 >>> 0) {
144-
$4_1 = $1 << $0;
145-
$0 = 0;
146-
} else {
147-
$4_1 = (1 << $0) - 1 & $1 >>> 32 - $0;
148-
$0 = $1 << $0;
149-
}
150-
$5_1 = $5_1 | $0;
151-
$1 = 32;
152-
$0 = $1 & 31;
153-
if (32 >>> 0 <= $1 >>> 0) {
154-
$1 = $3_1 << $0;
155-
$0 = 0;
156-
} else {
157-
$1 = (1 << $0) - 1 & $3_1 >>> 32 - $0;
158-
$0 = $3_1 << $0;
159-
}
160-
return $6($5_1, $4_1, $0 | $2, $1);
76+
return $6($0, $1, $2, $3_1);
16177
}
16278

16379
function legalstub$7($0, $1, $2, $3_1) {
164-
var $4_1 = 0;
165-
$4_1 = $0;
166-
$0 = $1;
167-
$1 = $3_1;
168-
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 >= $2 >>> 0 | $0 >>> 0 > $1 >>> 0;
80+
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 >= $2 >>> 0 | $1 >>> 0 > $3_1 >>> 0;
16981
}
17082

17183
function legalstub$8($0, $1, $2, $3_1) {
172-
var $4_1 = 0;
173-
$4_1 = $0;
174-
$0 = $1;
175-
$1 = $3_1;
176-
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 > $2 >>> 0 | $0 >>> 0 > $1 >>> 0;
84+
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 > $2 >>> 0 | $1 >>> 0 > $3_1 >>> 0;
17785
}
17886

17987
function legalstub$9($0, $1, $2, $3_1) {
180-
var $4_1 = 0;
181-
$4_1 = $0;
182-
$0 = $1;
183-
$1 = $3_1;
184-
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 <= $2 >>> 0 | $0 >>> 0 < $1 >>> 0;
88+
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 <= $2 >>> 0 | $1 >>> 0 < $3_1 >>> 0;
18589
}
18690

18791
function legalstub$10($0, $1, $2, $3_1) {
188-
var $4_1 = 0;
189-
$4_1 = $0;
190-
$0 = $1;
191-
$1 = $3_1;
192-
return ($0 | 0) == ($1 | 0) & $4_1 >>> 0 < $2 >>> 0 | $0 >>> 0 < $1 >>> 0;
92+
return ($1 | 0) == ($3_1 | 0) & $0 >>> 0 < $2 >>> 0 | $1 >>> 0 < $3_1 >>> 0;
19393
}
19494

19595
var FUNCTION_TABLE = [];

0 commit comments

Comments
 (0)