From cdf8139a441c27c16eff02ccee65c463500fc00f Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 27 Jun 2024 15:34:07 -0700 Subject: ConstantFieldPropagation: Add a variation that picks between 2 values using RefTest (#6692) CFP focuses on finding when a field always contains a constant, and then replaces a struct.get with that constant. If we find there are two constant values, then in some cases we can still optimize, if we have a way to pick between them. All we have is the struct.get and its reference, so we must use a ref.test: (struct.get $T x (..ref..)) => (select (..constant1..) (..constant2..) (ref.test $U (..ref..)) ) This is valid if, of all the subtypes of $T, those that pass the test have constant1 in that field, and those that fail the test have constant2. For example, a simple case is where $T has two subtypes, $T is never created itself, and each of the two subtypes has a different constant value. This is a somewhat risky operation, as ref.test is not necessarily cheap. To mitigate that, this is a new pass, --cfp-reftest that is not run by default, and also we only optimize when we can use a ref.test on what we think will be a final type (because ref.test on a final type can be faster in VMs). --- test/lit/help/wasm2js.test | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/lit/help/wasm2js.test') diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test index 3c1da7ff2..8e305cfb9 100644 --- a/test/lit/help/wasm2js.test +++ b/test/lit/help/wasm2js.test @@ -57,6 +57,9 @@ ;; CHECK-NEXT: --cfp propagate constant struct field ;; CHECK-NEXT: values ;; CHECK-NEXT: +;; CHECK-NEXT: --cfp-reftest propagate constant struct field +;; CHECK-NEXT: values, using ref.test +;; 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