diff options
author | Alon Zakai <azakai@google.com> | 2021-12-02 09:33:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-02 09:33:07 -0800 |
commit | dc432f3c2d3fdd18a0ac936057a76e7483907e99 (patch) | |
tree | dcd4e6416cfb6d5af0ebbdc39205ea6add381b71 /test/lit/passes/asyncify_mod-asyncify-always-and-only-unwind_O.wast | |
parent | 98b1ff3f7ba752dcb0d7b435a97697108c5fe2e9 (diff) | |
download | binaryen-dc432f3c2d3fdd18a0ac936057a76e7483907e99.tar.gz binaryen-dc432f3c2d3fdd18a0ac936057a76e7483907e99.tar.bz2 binaryen-dc432f3c2d3fdd18a0ac936057a76e7483907e99.zip |
SimplifyGlobals: Ignore irrelevant effects in read-only-to-write (#4363)
Previously this pass would see something like this and fail:
if (foo() + global) {
global = 1;
}
The call to foo() has side effects, so we did not optimize. However, in such
a case the side effects are safe: they happen anyhow, regardless of the global
that we are optimizing. That is, "global" is read only to be written, even though
other things also influence the decision to write it. But "global" is not used in a
way that is observable: we can remove it, and nothing will notice (except for
things getting smaller/faster).
In other words, this PR will let us optimize the above example, while it also
needs to avoid optimizing the dangerous cases, like this:
if (foo(global)) {
global = 1;
}
Here "global" flows into a place that notices its value and may use it aside
from deciding to write that global.
A common case where we want to optimize is combined ifs,
if (foo()) {
if (global) {
global = 1;
}
}
which the optimizer turns into
if (foo() & global) {
global = 1;
}
With this PR we can handle those things too.
This lets us optimize out some important globals in j2wasm like the initializer
boolean for the Math object, reducing some total 0.5% of code size.
Diffstat (limited to 'test/lit/passes/asyncify_mod-asyncify-always-and-only-unwind_O.wast')
0 files changed, 0 insertions, 0 deletions