Skip to content

Commit 3905550

Browse files
authored
Use Binaryen StackIR at the end of the pipeline (#22218)
Before this PR, if we did -O3 then we ended up doing this: * wasm-opt -O3 * wasm-metadce * wasm-opt --minify-imports-and-exports The first invocation uses StackIR (which is enabled by default in -O3), but then the later invocations "lose" those optimizations, since they read the wasm binary and generate structured BinaryenIR once more. We would need to do StackIR opts again, but even more, we'd need to do work to undo the effects of stackiness, which can lead to more locals and such, see #22196 After this PR, we do this: * wasm-opt -O3 --no-stack-ir * wasm-metadce * wasm-opt --minify-imports-and-exports --optimize-stack-ir The first command is now told to not use StackIR. The second remains unchanged. The last then does StackIR optimizations. This is the same amount of work (we just shuffle around the StackIR opts), so compile times are unaffected, but we gain some code improvements. To see them, see the commit before last which applies the size changes on top of a recent rebase. Many tests improve by small but noticeable amounts, though two wasm2js tests somehow lose by a few bytes, which I think is noise. There is a slight code complexity downside here, but given this avoids corner cases that may be quite annoying (#22196) it seems worthwhile. Also improve our handling of --emit-symbol-map to use llvm-objcopy, which avoids wasm-opt roundtrip issues (this is necessary in this commit as otherwise the improvements of this PR are undone by that roundtrip, which was caught by a test).
1 parent daf5b26 commit 3905550

23 files changed

+99
-55
lines changed

test/code_size/embind_val_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"a.html.gz": 380,
44
"a.js": 7072,
55
"a.js.gz": 2997,
6-
"a.wasm": 11625,
7-
"a.wasm.gz": 5814,
8-
"total": 19249,
9-
"total_gz": 9191
6+
"a.wasm": 11588,
7+
"a.wasm.gz": 5778,
8+
"total": 19212,
9+
"total_gz": 9155
1010
}

test/code_size/hello_webgl2_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"a.html.gz": 328,
44
"a.js": 4521,
55
"a.js.gz": 2312,
6-
"a.wasm": 10427,
7-
"a.wasm.gz": 6719,
8-
"total": 15402,
9-
"total_gz": 9359
6+
"a.wasm": 10399,
7+
"a.wasm.gz": 6695,
8+
"total": 15374,
9+
"total_gz": 9335
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"a.html": 346,
33
"a.html.gz": 262,
4-
"a.js": 22191,
5-
"a.js.gz": 11586,
6-
"total": 22537,
7-
"total_gz": 11848
4+
"a.js": 22193,
5+
"a.js.gz": 11584,
6+
"total": 22539,
7+
"total_gz": 11846
88
}

test/code_size/hello_webgl_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"a.html.gz": 328,
44
"a.js": 4059,
55
"a.js.gz": 2153,
6-
"a.wasm": 10427,
7-
"a.wasm.gz": 6719,
8-
"total": 14940,
9-
"total_gz": 9200
6+
"a.wasm": 10399,
7+
"a.wasm.gz": 6695,
8+
"total": 14912,
9+
"total_gz": 9176
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"a.html": 346,
33
"a.html.gz": 262,
4-
"a.js": 21717,
5-
"a.js.gz": 11425,
6-
"total": 22063,
7-
"total_gz": 11687
4+
"a.js": 21719,
5+
"a.js.gz": 11420,
6+
"total": 22065,
7+
"total_gz": 11682
88
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 12746,
3-
"a.html.gz": 6918,
4-
"total": 12746,
5-
"total_gz": 6918
2+
"a.html": 12694,
3+
"a.html.gz": 6891,
4+
"total": 12694,
5+
"total_gz": 6891
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
51018
1+
50957
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1741
1+
1737
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1732
1+
1728
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1290
1+
1286

0 commit comments

Comments
 (0)