From 99ccc313b2c1d91bbfcee48fe99d70a2867befbc Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 3 Sep 2021 11:00:10 -0700 Subject: Optimize away dominated calls to functions that run only once (#4111) Some functions run only once with this pattern: function foo() { if (foo$ran) return; foo$ran = 1; ... } If that global is not ever set to 0, then the function's payload (after the initial if and return) will never execute more than once. That means we can optimize away dominated calls: foo(); foo(); // we can remove this To do this, we find which globals are "once", which means they can fit in that pattern, as they are never set to 0. If a function looks like the above pattern, and it's global is "once", then the function is "once" as well, and we can perform this optimization. This removes over 8% of static calls in j2cl. --- test/lit/help/optimization-opts.test | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/lit/help') diff --git a/test/lit/help/optimization-opts.test b/test/lit/help/optimization-opts.test index 52695077a..18f8970c2 100644 --- a/test/lit/help/optimization-opts.test +++ b/test/lit/help/optimization-opts.test @@ -348,6 +348,9 @@ ;; CHECK-NEXT: is valid if the C runtime will ;; CHECK-NEXT: never be exited ;; CHECK-NEXT: +;; CHECK-NEXT: --once-reduction reduces calls to code that only +;; CHECK-NEXT: runs once +;; CHECK-NEXT: ;; CHECK-NEXT: --optimize-added-constants optimizes added constants into ;; CHECK-NEXT: load/store offsets ;; CHECK-NEXT: -- cgit v1.2.3