Skip to content

improve inlining thresholds for default optimization #1475

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 4 commits into from
Oct 12, 2020
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
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1496,9 +1496,9 @@ export class Module {
this.setAllowInliningFunctionsWithLoops(optimizeLevel >= 3);
} else {
this.setAlwaysInlineMaxSize(
optimizeLevel == 0 && shrinkLevel >= 0
optimizeLevel <= 1 || shrinkLevel >= 2
? 2
: 4
: 6
);
this.setFlexibleInlineMaxSize(65);
this.setOneCallerInlineMaxSize(80);
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
)
)
54 changes: 26 additions & 28 deletions tests/compiler/binary.optimized.wat
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
(module
(type $none_=>_none (func))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $f32_=>_f32 (func (param f32) (result f32)))
(type $f64_=>_f64 (func (param f64) (result f64)))
(memory $0 0)
(global $binary/i (mut i32) (i32.const 0))
(global $binary/I (mut i64) (i64.const 0))
Expand Down Expand Up @@ -42,23 +40,9 @@
end
local.get $2
)
(func $~lib/math/NativeMathf.mod (param $0 f32) (result f32)
local.get $0
local.get $0
f32.trunc
f32.sub
local.get $0
f32.copysign
)
(func $~lib/math/NativeMath.mod (param $0 f64) (result f64)
local.get $0
local.get $0
f64.trunc
f64.sub
local.get $0
f64.copysign
)
(func $start:binary
(local $0 f32)
(local $1 f64)
global.get $binary/i
call $~lib/math/ipow32
drop
Expand Down Expand Up @@ -174,9 +158,6 @@
i64.const 0
global.set $binary/I
global.get $binary/f
call $~lib/math/NativeMathf.mod
drop
global.get $binary/f
f32.const 1
f32.add
global.set $binary/f
Expand All @@ -185,7 +166,12 @@
f32.sub
global.set $binary/f
global.get $binary/f
call $~lib/math/NativeMathf.mod
local.tee $0
local.get $0
f32.trunc
f32.sub
local.get $0
f32.copysign
global.set $binary/f
global.get $binary/f
f32.const 1
Expand All @@ -196,12 +182,14 @@
f32.sub
global.set $binary/f
global.get $binary/f
call $~lib/math/NativeMathf.mod
local.tee $0
local.get $0
f32.trunc
f32.sub
local.get $0
f32.copysign
global.set $binary/f
global.get $binary/F
call $~lib/math/NativeMath.mod
drop
global.get $binary/F
f64.const 1
f64.add
global.set $binary/F
Expand All @@ -210,7 +198,12 @@
f64.sub
global.set $binary/F
global.get $binary/F
call $~lib/math/NativeMath.mod
local.tee $1
local.get $1
f64.trunc
f64.sub
local.get $1
f64.copysign
global.set $binary/F
global.get $binary/F
f64.const 1
Expand All @@ -221,7 +214,12 @@
f64.sub
global.set $binary/F
global.get $binary/F
call $~lib/math/NativeMath.mod
local.tee $1
local.get $1
f64.trunc
f64.sub
local.get $1
f64.copysign
global.set $binary/F
)
(func $~start
Expand Down
22 changes: 11 additions & 11 deletions tests/compiler/builtins.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(type $none_=>_none (func))
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_f64_f64_f64_f64_f64_=>_none (func (param i32 i32 f64 f64 f64 f64 f64)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
Expand Down Expand Up @@ -49,14 +49,6 @@
local.get $1
i32.add
)
(func $~lib/string/String#get:length (param $0 i32) (result i32)
local.get $0
i32.const 16
i32.sub
i32.load offset=12
i32.const 1
i32.shr_u
)
(func $~lib/util/string/compareImpl (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
Expand Down Expand Up @@ -150,10 +142,18 @@
select
br_if $folding-inner0
local.get $0
call $~lib/string/String#get:length
i32.const 16
i32.sub
i32.load offset=12
i32.const 1
i32.shr_u
local.tee $2
local.get $1
call $~lib/string/String#get:length
i32.const 16
i32.sub
i32.load offset=12
i32.const 1
i32.shr_u
i32.ne
br_if $folding-inner0
local.get $0
Expand Down
26 changes: 3 additions & 23 deletions tests/compiler/call-optional.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
(global $~argumentsLength (mut i32) (i32.const 0))
(export "memory" (memory $0))
(start $~start)
(func $call-optional/opt (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
local.get $2
local.get $0
local.get $1
i32.add
i32.add
)
(func $call-optional/opt@varargs (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
block $2of2
block $1of2
Expand All @@ -36,10 +29,11 @@
i32.const -2
local.set $2
end
local.get $2
local.get $0
local.get $1
local.get $2
call $call-optional/opt
i32.add
i32.add
)
(func $start:call-optional
i32.const 1
Expand Down Expand Up @@ -72,20 +66,6 @@
call $~lib/builtins/abort
unreachable
end
i32.const 3
i32.const 4
i32.const 5
call $call-optional/opt
i32.const 12
i32.ne
if
i32.const 0
i32.const 1040
i32.const 6
i32.const 1
call $~lib/builtins/abort
unreachable
end
i32.const 1
global.set $~argumentsLength
i32.const 3
Expand Down
4 changes: 2 additions & 2 deletions tests/compiler/class-implements.optimized.wat
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
(func $~start
i32.const 1088
global.set $~lib/rt/stub/offset
i32.const 0
call $class-implements/A#constructor
i32.const 3
call $~lib/rt/stub/__alloc
drop
i32.const 5
call $~lib/rt/stub/__alloc
Expand Down
44 changes: 21 additions & 23 deletions tests/compiler/class-overloading.optimized.wat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
Expand Down Expand Up @@ -105,14 +105,6 @@
call $~lib/rt/stub/__alloc
end
)
(func $~lib/string/String#get:length (param $0 i32) (result i32)
local.get $0
i32.const 16
i32.sub
i32.load offset=12
i32.const 1
i32.shr_u
)
(func $~lib/util/string/compareImpl (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
(local $3 i32)
(local $4 i32)
Expand Down Expand Up @@ -206,10 +198,18 @@
select
br_if $folding-inner0
local.get $0
call $~lib/string/String#get:length
i32.const 16
i32.sub
i32.load offset=12
i32.const 1
i32.shr_u
local.tee $2
local.get $1
call $~lib/string/String#get:length
i32.const 16
i32.sub
i32.load offset=12
i32.const 1
i32.shr_u
i32.ne
br_if $folding-inner0
local.get $0
Expand Down Expand Up @@ -239,25 +239,22 @@
i32.const 1184
global.set $class-overloading/which
)
(func $class-overloading/D#constructor (param $0 i32) (result i32)
(func $class-overloading/E#constructor (param $0 i32) (result i32)
local.get $0
if (result i32)
local.get $0
else
i32.const 6
i32.eqz
if
i32.const 7
call $~lib/rt/stub/__alloc
local.set $0
end
call $class-overloading/B#constructor
)
(func $class-overloading/E#constructor (param $0 i32) (result i32)
local.get $0
if (result i32)
local.get $0
else
i32.const 7
i32.const 6
call $~lib/rt/stub/__alloc
end
call $class-overloading/D#constructor
call $class-overloading/B#constructor
)
(func $start:class-overloading
i32.const 1296
Expand Down Expand Up @@ -392,8 +389,9 @@
call $~lib/builtins/abort
unreachable
end
i32.const 0
call $class-overloading/D#constructor
i32.const 6
call $~lib/rt/stub/__alloc
call $class-overloading/B#constructor
global.set $class-overloading/a
i32.const 1040
global.set $class-overloading/which
Expand Down
Loading