diff options
author | Alon Zakai <azakai@google.com> | 2024-06-27 15:34:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-27 15:34:07 -0700 |
commit | cdf8139a441c27c16eff02ccee65c463500fc00f (patch) | |
tree | 478313c6b1b1d41df76421fd7f52cfe3d76f04f7 /src/passes/passes.h | |
parent | 53712b6d6e93449a6faf18a55e0fb29022f158df (diff) | |
download | binaryen-cdf8139a441c27c16eff02ccee65c463500fc00f.tar.gz binaryen-cdf8139a441c27c16eff02ccee65c463500fc00f.tar.bz2 binaryen-cdf8139a441c27c16eff02ccee65c463500fc00f.zip |
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).
Diffstat (limited to 'src/passes/passes.h')
-rw-r--r-- | src/passes/passes.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/passes/passes.h b/src/passes/passes.h index 02b164279..bd3aabf9f 100644 --- a/src/passes/passes.h +++ b/src/passes/passes.h @@ -32,6 +32,7 @@ Pass* createCodeFoldingPass(); Pass* createCodePushingPass(); Pass* createConstHoistingPass(); Pass* createConstantFieldPropagationPass(); +Pass* createConstantFieldPropagationRefTestPass(); Pass* createDAEPass(); Pass* createDAEOptimizingPass(); Pass* createDataFlowOptsPass(); |