From eb83c4257976f9536b98df43e8f2242a102b3ce4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 16 Sep 2021 20:03:37 -0700 Subject: Partial inlining via function splitting (#4152) This PR helps with functions like this: function foo(x) { if (x) { .. lots of work here .. } } If "lots of work" is large enough, then we won't inline such a function. However, we may end up calling into the function only to get a false on that if and immediately exit. So it is useful to partially inline this function, basically by creating a split of it into a condition part that is inlineable function foo$inlineable(x) { if (x) { foo$outlined(); } } and an outlined part that is not inlineable: function foo$outlined(x) { .. lots of work here .. } We can then inline the inlineable part. That means that a call like foo(param); turns into if (param) { foo$outlined(); } In other words, we end up replacing a call and then a check with a check and then a call. Any time that the condition is false, this will be a speedup. The cost here is increased size, as we duplicate the condition into the callsites. For that reason, only do this when heavily optimizing for size. This is a 10% speedup on j2cl. This helps two types of functions there: Java class inits, which often look like "have I been initialized before? if not, do all this work", and also assertion methods which look like "if the input is null, throw an exception". --- scripts/fuzz_opt.py | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py index 73de5d8e2..abc6225ee 100755 --- a/scripts/fuzz_opt.py +++ b/scripts/fuzz_opt.py @@ -176,6 +176,7 @@ IMPORTANT_INITIAL_CONTENTS = [ os.path.join('lit', 'passes', 'optimize-instructions-bulk-memory.wast'), os.path.join('lit', 'passes', 'optimize-instructions-ignore-traps.wast'), os.path.join('lit', 'passes', 'optimize-instructions-gc.wast'), + os.path.join('lit', 'passes', 'inlining_splitting.wast'), ] IMPORTANT_INITIAL_CONTENTS = [os.path.join(shared.get_test_dir('.'), t) for t in IMPORTANT_INITIAL_CONTENTS] -- cgit v1.2.3