Skip to content

Refactor pass pipeline for better precompute globals #2154

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 3 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2306,17 +2306,18 @@ export class Module {
if (optimizeLevel >= 2) {
passes.push("once-reduction");
passes.push("inlining");
passes.push("simplify-globals-optimizing");
}
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
passes.push("rse");
passes.push("vacuum");
passes.push("ssa-nomerge");
passes.push("simplify-globals-optimizing");
passes.push("local-cse");
passes.push("remove-unused-brs");
passes.push("remove-unused-names");
passes.push("merge-blocks");
passes.push("precompute-propagate");
passes.push("simplify-globals-optimizing");
}
if (optimizeLevel >= 3) {
passes.push("simplify-locals-nostructure");
Expand All @@ -2339,13 +2340,12 @@ export class Module {
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
passes.push("inlining");
passes.push("precompute-propagate");
passes.push("simplify-globals-optimizing");
} else {
passes.push("precompute");
}
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("pick-load-signs");
passes.push("simplify-globals-optimizing");
passes.push("simplify-globals-optimizing");
}
passes.push("simplify-locals-notee-nostructure");
passes.push("vacuum");
Expand Down Expand Up @@ -2412,6 +2412,7 @@ export class Module {
if (optimizeLevel >= 2 || shrinkLevel >= 1) {
passes.push("precompute-propagate");
passes.push("simplify-globals-optimizing");
passes.push("simplify-globals-optimizing");
} else {
passes.push("precompute");
}
Expand Down
83 changes: 44 additions & 39 deletions tests/compiler/call-super.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -595,12 +595,12 @@
(local $0 i32)
(local $1 i32)
memory.size
local.tee $0
local.tee $1
i32.const 0
i32.le_s
if (result i32)
i32.const 1
local.get $0
local.get $1
i32.sub
memory.grow
i32.const 0
Expand All @@ -618,26 +618,26 @@
i32.const 0
i32.store
loop $for-loop|0
local.get $1
local.get $0
i32.const 23
i32.lt_u
if
local.get $1
local.get $0
i32.const 2
i32.shl
i32.const 17984
i32.add
i32.const 0
i32.store offset=4
i32.const 0
local.set $0
local.set $1
loop $for-loop|1
local.get $0
local.get $1
i32.const 16
i32.lt_u
if
local.get $0
local.get $1
local.get $0
i32.const 4
i32.shl
i32.add
Expand All @@ -647,17 +647,17 @@
i32.add
i32.const 0
i32.store offset=96
local.get $0
local.get $1
i32.const 1
i32.add
local.set $0
local.set $1
br $for-loop|1
end
end
local.get $1
local.get $0
i32.const 1
i32.add
local.set $1
local.set $0
br $for-loop|0
end
end
Expand Down Expand Up @@ -1666,7 +1666,7 @@
i32.const 2
i32.store offset=4
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__stack_pointer
local.tee $2
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
Expand Down Expand Up @@ -1706,6 +1706,7 @@
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $2
local.get $0
i32.store
local.get $0
Expand Down Expand Up @@ -1804,7 +1805,7 @@
i32.const 2
i32.store offset=4
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__stack_pointer
local.tee $2
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
Expand Down Expand Up @@ -1832,6 +1833,7 @@
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $2
local.get $0
i32.store
local.get $0
Expand Down Expand Up @@ -1927,7 +1929,7 @@
local.tee $0
i32.store
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__stack_pointer
local.tee $2
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
Expand Down Expand Up @@ -1967,6 +1969,7 @@
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $2
local.get $0
i32.store
local.get $0
Expand Down Expand Up @@ -2038,7 +2041,7 @@
local.tee $0
i32.store
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__stack_pointer
local.tee $2
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
Expand Down Expand Up @@ -2066,6 +2069,7 @@
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $2
local.get $0
i32.store
local.get $0
Expand Down Expand Up @@ -2137,7 +2141,7 @@
local.tee $0
i32.store
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__stack_pointer
local.tee $2
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
Expand Down Expand Up @@ -2165,6 +2169,7 @@
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
local.get $2
local.get $0
i32.store
local.get $0
Expand Down Expand Up @@ -2223,19 +2228,19 @@
local.get $0
i32.const 20
i32.sub
local.tee $0
local.tee $1
i32.load offset=4
i32.const 3
i32.and
i32.eq
if
global.get $~lib/rt/itcms/iter
local.get $0
local.get $1
i32.eq
if
local.get $0
local.get $1
i32.load offset=8
local.tee $1
local.tee $0
i32.eqz
if
i32.const 0
Expand All @@ -2245,22 +2250,22 @@
call $~lib/builtins/abort
unreachable
end
local.get $1
local.get $0
global.set $~lib/rt/itcms/iter
end
block $__inlined_func$~lib/rt/itcms/Object#unlink
local.get $0
local.get $1
i32.load offset=4
i32.const -4
i32.and
local.tee $1
local.tee $0
i32.eqz
if
i32.const 0
local.get $0
local.get $1
i32.const 17980
i32.lt_u
local.get $0
local.get $1
i32.load offset=8
select
i32.eqz
Expand All @@ -2274,7 +2279,7 @@
end
br $__inlined_func$~lib/rt/itcms/Object#unlink
end
local.get $0
local.get $1
i32.load offset=8
local.tee $2
i32.eqz
Expand All @@ -2286,31 +2291,31 @@
call $~lib/builtins/abort
unreachable
end
local.get $1
local.get $0
local.get $2
i32.store offset=8
local.get $2
local.get $2
i32.load offset=4
i32.const 3
i32.and
local.get $1
local.get $0
i32.or
i32.store offset=4
end
global.get $~lib/rt/itcms/toSpace
local.set $2
local.get $0
local.get $1
i32.load offset=12
local.tee $1
local.tee $0
i32.const 1
i32.le_u
if (result i32)
i32.const 1
else
i32.const 1488
i32.load
local.get $1
local.get $0
i32.lt_u
if
i32.const 1296
Expand All @@ -2320,7 +2325,7 @@
call $~lib/builtins/abort
unreachable
end
local.get $1
local.get $0
i32.const 3
i32.shl
i32.const 1492
Expand All @@ -2338,25 +2343,25 @@
local.set $3
local.get $2
i32.load offset=8
local.set $1
local.get $0
local.set $0
local.get $1
local.get $2
local.get $3
i32.or
i32.store offset=4
local.get $0
local.get $1
local.get $0
i32.store offset=8
local.get $1
local.get $1
local.get $0
local.get $0
i32.load offset=4
i32.const 3
i32.and
local.get $0
local.get $1
i32.or
i32.store offset=4
local.get $2
local.get $0
local.get $1
i32.store offset=8
global.get $~lib/rt/itcms/visitCount
i32.const 1
Expand Down
Loading