From 243ac8942e1e0136b8d91242642d9bc825a9cfd9 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 5 Aug 2021 11:03:34 -0700 Subject: [Wasm GC] Constant Field Propagation (#4052) A field in a struct is constant if we can see that in the entire program we only ever write the same constant value to it. For example, imagine a vtable type that we construct with the same funcrefs each time, then (if we have no struct.sets, or if we did, and they had the same value), we could replace a get with that constant value, since it cannot be anything else: (struct.new $T (i32.const 10) (rtt)) ..no other conflicting values.. (struct.get $T 0) => (i32.const 10) If the value is a function reference, then this may allow other passes to turn what was a call_ref into a direct call and perhaps also get inlined, effectively a form of devirtualization. This only works in nominal typing, as we need to know the supertype of each type. (It could work in theory in structural, but we'd need to do hard work to find all the possible supertypes, and it would also become far less effective.) This deletes a trivial test for running -O on GC content. We have many more tests for GC at this point, so that test is not needed, and this PR also optimizes the code into something trivial and uninteresting anyhow. --- test/lit/help/optimization-opts.test | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/lit/help/optimization-opts.test') diff --git a/test/lit/help/optimization-opts.test b/test/lit/help/optimization-opts.test index c6d45332d..d189c6398 100644 --- a/test/lit/help/optimization-opts.test +++ b/test/lit/help/optimization-opts.test @@ -182,6 +182,9 @@ ;; CHECK-NEXT: --avoid-reinterprets Tries to avoid reinterpret ;; CHECK-NEXT: operations via more loads ;; CHECK-NEXT: +;; CHECK-NEXT: --cfp propagate constant struct field +;; CHECK-NEXT: values +;; CHECK-NEXT: ;; CHECK-NEXT: --coalesce-locals reduce # of locals by coalescing ;; CHECK-NEXT: ;; CHECK-NEXT: --coalesce-locals-learning reduce # of locals by coalescing -- cgit v1.2.3