summaryrefslogtreecommitdiff
path: root/src/passes/pass.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-09-14 14:21:25 -0700
committerGitHub <noreply@github.com>2023-09-14 14:21:25 -0700
commit3e8a9dacf6c65c29054094ce9f1d34ae8480df65 (patch)
tree928b04d774c2540a6a4c170d6013d5b60663c447 /src/passes/pass.cpp
parentf774effa54c6a40448487033a28a47caa3394f61 (diff)
downloadbinaryen-3e8a9dacf6c65c29054094ce9f1d34ae8480df65.tar.gz
binaryen-3e8a9dacf6c65c29054094ce9f1d34ae8480df65.tar.bz2
binaryen-3e8a9dacf6c65c29054094ce9f1d34ae8480df65.zip
Add a simple tuple optimization pass (#5937)
In some cases tuples are obviously not needed, such as when they are only used in local operations and make/extract. Such tuples are not used as return values or in control flow structures, so we might as well lower them to individual locals per lane, which other passes can optimize a lot better. I believe LLVM does the same with its own tuples: it lowers them as much as possible, leaving only necessary ones. Fixes #5923
Diffstat (limited to 'src/passes/pass.cpp')
-rw-r--r--src/passes/pass.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index 0d47cd78e..15e8c1f26 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -480,6 +480,9 @@ void PassRegistry::registerPasses() {
registerPass("trap-mode-js",
"replace trapping operations with js semantics",
createTrapModeJS);
+ registerPass("tuple-optimization",
+ "optimize trivial tuples away",
+ createTupleOptimizationPass);
registerPass("type-merging",
"merge types to their supertypes where possible",
createTypeMergingPass);
@@ -558,6 +561,12 @@ void PassRunner::addDefaultFunctionOptimizationPasses() {
if (options.optimizeLevel >= 2 || options.shrinkLevel >= 2) {
addIfNoDWARFIssues("code-pushing");
}
+ if (wasm->features.hasMultivalue()) {
+ // Optimize tuples before local opts (as splitting tuples can help local
+ // opts), but also not too early, as we want to be after
+ // optimize-instructions at least (which can remove tuple-related things).
+ addIfNoDWARFIssues("tuple-optimization");
+ }
// don't create if/block return values yet, as coalesce can remove copies that
// that could inhibit
addIfNoDWARFIssues("simplify-locals-nostructure");