diff options
author | Alon Zakai <azakai@google.com> | 2022-09-16 08:55:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-16 08:55:07 -0700 |
commit | 3892b0bbe0aa0e57864e6785e43d33e89d39000b (patch) | |
tree | 4f7d0b968a680d6adb6f54a3a71b7ceacb8d0575 /src | |
parent | 989489020e635d35870b22894a5d129c8c55d640 (diff) | |
download | binaryen-3892b0bbe0aa0e57864e6785e43d33e89d39000b.tar.gz binaryen-3892b0bbe0aa0e57864e6785e43d33e89d39000b.tar.bz2 binaryen-3892b0bbe0aa0e57864e6785e43d33e89d39000b.zip |
Vacuum trivial trys (#5046)
A try whose body throws, and does nothing else, and the try catches that
exception, can be removed.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Vacuum.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 6adab04e9..208e973da 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -365,6 +365,19 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum>> { for (auto* catchBody : curr->catchBodies) { typeUpdater.noteRecursiveRemoval(catchBody); } + return; + } + + // The try's body does throw. However, throwing may be the only thing it + // does, and if the try has a catch-all, then the entire try including + // children may have no effects. Note that this situation can only happen + // if we do have a catch-all, so avoid wasted work by checking that first. + // Also, we can't do this if a result is returned, so check the type. + if (curr->type == Type::none && curr->hasCatchAll() && + !EffectAnalyzer(getPassOptions(), *getModule(), curr) + .hasUnremovableSideEffects()) { + typeUpdater.noteRecursiveRemoval(curr); + ExpressionManipulator::nop(curr); } } |