Skip to content

RemoveUnusedBrs: Remove final block nops in all cases #4954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/passes/RemoveUnusedBrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions test/passes/remove-unused-brs_enable-multivalue.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
(drop
(i32.const 0)
)
(nop)
)
)
)
Expand All @@ -46,7 +45,6 @@
(drop
(i32.const 0)
)
(nop)
)
)
)
Expand All @@ -58,7 +56,6 @@
(drop
(i32.const 0)
)
(nop)
)
)
)
Expand Down Expand Up @@ -140,7 +137,6 @@
(drop
(i32.const 1)
)
(nop)
)
)
)
Expand All @@ -152,7 +148,6 @@
(drop
(i32.const 2)
)
(nop)
)
)
)
Expand Down Expand Up @@ -231,7 +226,6 @@
(drop
(i32.const 0)
)
(nop)
)
)
)
Expand Down Expand Up @@ -385,15 +379,13 @@
(drop
(i32.const 1)
)
(nop)
)
)
(block $a20
(block
(drop
(i32.const 2)
)
(nop)
)
)
)
Expand Down Expand Up @@ -526,7 +518,6 @@
(block $out49
(block
(call $loops)
(nop)
)
)
(br $in48)
Expand Down Expand Up @@ -997,7 +988,6 @@
(br_if $shape$6$continue
(local.get $0)
)
(nop)
)
)
)
Expand Down Expand Up @@ -1790,7 +1780,6 @@
(drop
(i32.const 0)
)
(nop)
)
)
)
Expand Down Expand Up @@ -2326,8 +2315,6 @@
(i32.const 0)
(block $label$3
(block
(nop)
(nop)
)
)
(return
Expand Down