Skip to content

improve pass pipeline #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
53fc4ca
improve pass pipeline
MaxGraey Apr 16, 2020
6776a0b
add post propagate vacuum
MaxGraey Apr 16, 2020
01a401c
reorder vacuum
MaxGraey Apr 16, 2020
b6e4073
revert reordering
MaxGraey Apr 16, 2020
90fa628
try again
MaxGraey Apr 16, 2020
c254fdf
more
MaxGraey Apr 16, 2020
99a78dd
use notee version for early simplify-locals
MaxGraey Apr 16, 2020
ea9910c
add inlining before licm
MaxGraey Apr 16, 2020
5451d29
better
MaxGraey Apr 17, 2020
ffc7072
add vacuum after rse
MaxGraey Apr 17, 2020
045b1a3
move extra inline pass upper (before pick-load-signs)
MaxGraey Apr 17, 2020
e0cd790
move optimize-istruction earlier
MaxGraey Apr 17, 2020
332e5a9
more
MaxGraey Apr 17, 2020
d1e56da
post-finalize unnecessary blocks
MaxGraey Apr 17, 2020
756104a
do optimize-added-constants later
MaxGraey Apr 17, 2020
21f02e3
cleanups
MaxGraey Apr 17, 2020
4aee967
hide optimize-instructions for small opt levels
MaxGraey Apr 17, 2020
0eb474c
add code-folding
MaxGraey Apr 18, 2020
a82b192
move upper
MaxGraey Apr 18, 2020
87e9e79
use early code-folding
MaxGraey Apr 18, 2020
b40f77e
move code folding after flatten
MaxGraey Apr 18, 2020
087372b
add merge-locals
MaxGraey Apr 18, 2020
3d47f2d
actually move it
MaxGraey Apr 18, 2020
3406f9f
add vacuum after propagate pass
MaxGraey Apr 18, 2020
4295c2b
add extra simplify-global-optimizig
MaxGraey Apr 18, 2020
4703c43
move it below
MaxGraey Apr 18, 2020
1af1dd8
add early remove-unused-module-elements
MaxGraey Apr 19, 2020
5370096
add vacuum after simplify-locals-nostructure
MaxGraey Apr 19, 2020
76f7b9b
remove vacuum at the end
MaxGraey Apr 19, 2020
3b9f946
try other approach
MaxGraey Apr 20, 2020
bcd5e8d
Revert "try other approach"
MaxGraey Apr 20, 2020
0a35f61
improve
MaxGraey Apr 21, 2020
86b5f6c
move optimize-instructions before inlining
MaxGraey Apr 21, 2020
a28b0aa
better
MaxGraey Apr 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,20 +694,24 @@ exports.main = function main(argv, options, callback) {

// PassRunner::addDefaultGlobalOptimizationPrePasses
add("duplicate-function-elimination");
add("remove-unused-module-elements"); // differs

// PassRunner::addDefaultFunctionOptimizationPasses
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("ssa-nomerge");
}
if (optimizeLevel >= 3) {
add("simplify-locals-nostructure"); // differs
add("flatten"); // differs
add("simplify-locals-notee-nostructure"); // differs
add("vacuum"); // differs
add("reorder-locals"); // differs
add("code-folding"); // differs
add("flatten");
add("local-cse");
add("reorder-locals"); // differs
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
add("rse");
add("vacuum");
}
if (hasARC) { // differs
if (optimizeLevel < 3) {
Expand All @@ -718,24 +722,18 @@ exports.main = function main(argv, options, callback) {
add("dce");
add("remove-unused-brs");
add("remove-unused-names");
// add("optimize-instructions"); // differs move 2 lines above
add("optimize-instructions");
add("inlining"); // differs
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("pick-load-signs");
add("simplify-globals-optimizing"); // differs
}
add("optimize-instructions"); // differs
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
add("precompute-propagate");
} else {
add("precompute");
}
if (module.getLowMemoryUnused()) {
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("optimize-added-constants-propagate");
} else {
add("optimize-added-constants");
}
}
add("vacuum"); // differs
// this will be done later (1)
// if (optimizeLevel >= 2 || shrinkLevel >= 2) {
// add("code-pushing");
Expand Down Expand Up @@ -776,25 +774,36 @@ exports.main = function main(argv, options, callback) {
// } else {
// add("precompute");
// }
add("optimize-instructions");
if (optimizeLevel >= 3) {
add("optimize-instructions");
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("rse");
}
add("vacuum");
// PassRunner::addDefaultGlobalOptimizationPostPasses
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
add("simplify-globals-optimizing"); // differs
add("dae-optimizing");
}
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("inlining-optimizing");
}
if (module.getLowMemoryUnused()) {
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
add("optimize-added-constants-propagate");
} else {
add("optimize-added-constants");
}
}
// "duplicate-function-elimination" will better done later
// add("duplicate-function-elimination");
add("duplicate-import-elimination");
if (optimizeLevel >= 2 || shrinkLevel >= 2) {
add("simplify-globals-optimizing");
} else {
add("simplify-globals");
add("vacuum"); // differs
}
// moved from (2)
// it works better after globals optimizations like simplify-globals, inlining-optimizing and etc
Expand All @@ -814,28 +823,30 @@ exports.main = function main(argv, options, callback) {
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) { // differs
add("rse");
// rearrange / reduce switch cases again
add("remove-unused-brs");
add("vacuum");

// move some code after early return which potentially could reduce computations
// do this after CFG cleanup (originally it was done before)
// moved from (1)
add("code-pushing");
if (optimizeLevel >= 3) {
// this quite expensive so do this only for highest opt level
add("simplify-globals");
add("vacuum");
// replace indirect calls with direct and inline if possible again.
add("inlining-optimizing");
add("directize");
add("dae-optimizing");
add("precompute-propagate");
add("coalesce-locals");
add("vacuum");
add("merge-locals");
add("coalesce-locals");
add("simplify-locals-nostructure");
add("vacuum");
add("inlining-optimizing");
add("precompute-propagate");
}
add("remove-unused-brs");
add("remove-unused-names");
add("vacuum");
add("optimize-instructions");
add("simplify-globals-optimizing");
}
Expand Down
14 changes: 8 additions & 6 deletions tests/compiler/assert-nonnull.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@
(local $1 i32)
block $folding-inner0
local.get $0
local.tee $1
i32.eqz
br_if $folding-inner0
local.get $0
local.get $1
call $~lib/array/Array<assert-nonnull/Foo | null>#__get
local.tee $0
local.get $0
Expand All @@ -166,9 +167,10 @@
(local $1 i32)
block $folding-inner0
local.get $0
local.tee $1
i32.eqz
br_if $folding-inner0
local.get $0
local.get $1
call $~lib/array/Array<assert-nonnull/Foo | null>#__get
local.tee $0
local.get $0
Expand Down Expand Up @@ -213,8 +215,8 @@
(local $1 i32)
local.get $0
call_indirect (type $none_=>_i32)
local.tee $0
local.get $0
local.tee $1
local.get $1
i32.eqz
if
i32.const 0
Expand All @@ -235,8 +237,8 @@
local.get $0
i32.load offset=4
call_indirect (type $none_=>_i32)
local.tee $0
local.get $0
local.tee $1
local.get $1
i32.eqz
if
i32.const 0
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/builtins.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@
local.set $2
local.get $3
if
local.get $1
local.get $0
i32.load16_u
local.tee $3
local.get $0
local.get $1
i32.load16_u
local.tee $4
i32.ne
if
local.get $4
local.get $3
local.get $4
i32.sub
return
end
Expand Down
15 changes: 2 additions & 13 deletions tests/compiler/comma.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,10 @@
global.set $comma/b
i32.const 2
global.set $comma/a
global.get $comma/a
i32.const 2
global.set $comma/b
global.get $comma/b
global.set $comma/a
global.get $comma/a
i32.const 2
i32.ne
if
i32.const 0
i32.const 1040
i32.const 18
i32.const 1
call $~lib/builtins/abort
unreachable
end
global.set $comma/a
global.get $comma/b
i32.const 2
i32.ne
Expand Down
Loading