Skip to content

Slightly improve pass pipeline #1498

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 10 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
11 changes: 5 additions & 6 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1548,12 +1548,11 @@ export class Module {
passes.push("optimize-instructions");
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
passes.push("dce");
passes.push("inlining");
}
passes.push("remove-unused-brs");
passes.push("remove-unused-names");
passes.push("inlining-optimizing");
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
passes.push("inlining");
passes.push("precompute-propagate");
} else {
passes.push("precompute");
Expand Down Expand Up @@ -1581,9 +1580,6 @@ export class Module {
passes.push("merge-locals");
}
passes.push("vacuum");
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
passes.push("code-folding");
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("simplify-globals-optimizing");
}
Expand Down Expand Up @@ -1622,6 +1618,9 @@ export class Module {
passes.push("simplify-globals");
passes.push("vacuum");
}
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
passes.push("code-folding");
}
// precompute works best after global optimizations
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("precompute-propagate");
Expand Down Expand Up @@ -1656,7 +1655,7 @@ export class Module {
passes.push("simplify-locals");
passes.push("vacuum");

passes.push("inlining-optimizing");
passes.push("inlining");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: What's the different between inlining and inlining-optimizing? Is the latter unnecessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems inlining-optimizing also apply constant propagation but only for specific part or something like this

passes.push("precompute-propagate");
passes.push("vacuum");

Expand Down
16 changes: 8 additions & 8 deletions tests/compiler/assert-nonnull.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,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 @@ -165,9 +166,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 @@ -208,12 +210,10 @@
call_indirect (type $none_=>_i32)
)
(func $assert-nonnull/testRet (param $0 i32) (result i32)
(local $1 i32)
local.get $0
i32.load
call_indirect (type $none_=>_i32)
local.tee $1
local.get $1
local.tee $0
i32.eqz
if
i32.const 1040
Expand All @@ -223,6 +223,7 @@
call $~lib/builtins/abort
unreachable
end
local.get $0
)
(func $assert-nonnull/testObjFn (param $0 i32) (result i32)
local.get $0
Expand All @@ -231,13 +232,11 @@
call_indirect (type $none_=>_i32)
)
(func $assert-nonnull/testObjRet (param $0 i32) (result i32)
(local $1 i32)
local.get $0
i32.load offset=4
i32.load
call_indirect (type $none_=>_i32)
local.tee $1
local.get $1
local.tee $0
i32.eqz
if
i32.const 1040
Expand All @@ -247,5 +246,6 @@
call $~lib/builtins/abort
unreachable
end
local.get $0
)
)
18 changes: 9 additions & 9 deletions tests/compiler/infer-array.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -291,31 +291,31 @@
i32.const 16
local.get $2
call $~lib/rt/stub/__alloc
local.set $2
local.tee $2
local.get $0
local.get $1
i32.shl
local.tee $4
local.tee $1
local.set $5
local.get $4
local.get $1
i32.const 0
call $~lib/rt/stub/__alloc
local.set $1
local.set $4
local.get $3
if
local.get $1
local.get $4
local.get $3
local.get $5
call $~lib/memory/memory.copy
end
local.get $2
local.get $1
local.get $4
local.tee $3
i32.store
local.get $2
local.get $1
local.get $3
i32.store offset=4
local.get $2
local.get $4
local.get $1
i32.store offset=8
local.get $2
local.get $0
Expand Down
17 changes: 7 additions & 10 deletions tests/compiler/infer-generic.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,22 @@
(local $1 i32)
(local $2 i32)
(local $3 i32)
(local $4 i32)
i32.const 1132
i32.load
local.set $1
local.set $2
loop $for-loop|0
local.get $1
local.get $0
local.get $2
i32.const 1132
i32.load
local.tee $2
i32.lt_s
local.set $3
local.get $0
local.get $1
local.tee $3
local.get $2
local.get $3
i32.lt_s
select
i32.lt_s
if
local.get $4
local.get $1
i32.const 1124
i32.load
local.get $0
Expand All @@ -66,7 +63,7 @@
i32.const 1152
i32.load
call_indirect (type $i32_f32_i32_i32_=>_i32)
local.set $4
local.set $1
local.get $0
i32.const 1
i32.add
Expand Down
Loading