summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-22 14:31:04 -0700
committerGitHub <noreply@github.com>2022-08-22 14:31:04 -0700
commit0e0c2d9d45068c450ad5df5de47948532dd12c53 (patch)
treec8e3ee432f06e2f5b814a91466ff43aa305815ad /src
parent38c084ee386e257389d44c6200a403f74432e1af (diff)
downloadbinaryen-0e0c2d9d45068c450ad5df5de47948532dd12c53.tar.gz
binaryen-0e0c2d9d45068c450ad5df5de47948532dd12c53.tar.bz2
binaryen-0e0c2d9d45068c450ad5df5de47948532dd12c53.zip
RemoveUnusedBrs: Remove final block nops in all cases (#4954)
This fixes what looks like it might be a regression in #4943. It's not actually an issue since it just affects wat files, but it did uncover an existing inefficiency. The situation is this: (block .. (br $somewhere) (nop) ) Removing such a nop is always helpful, as the pass might see that that br goes to where control flow is going anyhow, and the nop would confuse it. We used to remove such nops only when the block had a name, which is why wat testcases looks optimal, but we were actually doing the less-efficient thing on real-world code. It was a minor inefficiency, though, as the nop is quickly removed by later passes anyhow. Still, the fix is trivial (to always remove such nops, regardless of a name on the block or not).
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveUnusedBrs.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 3c4723c7f..b867dc4c2 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -203,11 +203,14 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
if (skip > 0) {
flows.resize(size - skip);
}
- // drop a nop at the end of a block, which prevents a value flowing
- while (list.size() > 0 && list.back()->is<Nop>()) {
- list.resize(list.size() - 1);
- self->anotherCycle = true;
- }
+ }
+ // Drop a nop at the end of a block, which prevents a value flowing. Note
+ // that this is worth doing regardless of whether we have a name on this
+ // block or not (which the if right above us checks) - such a nop is
+ // always unneeded and can limit later optimizations.
+ while (list.size() > 0 && list.back()->is<Nop>()) {
+ list.resize(list.size() - 1);
+ self->anotherCycle = true;
}
// A value flowing is only valid if it is a value that the block actually
// flows out. If it is never reached, it does not flow out, and may be