diff options
author | Alon Zakai <azakai@google.com> | 2023-08-09 10:31:48 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 10:31:48 -0700 |
commit | d0bdf202463323a0b9f3be95fe2c64765a84a4b7 (patch) | |
tree | c4142a82fe8d1fe2451745b5068cadae4e063af9 /src | |
parent | 0fc7b883d373924717ceccf71a6a759c97a8fb08 (diff) | |
download | binaryen-d0bdf202463323a0b9f3be95fe2c64765a84a4b7.tar.gz binaryen-d0bdf202463323a0b9f3be95fe2c64765a84a4b7.tar.bz2 binaryen-d0bdf202463323a0b9f3be95fe2c64765a84a4b7.zip |
LinearExecutionWalker: Optionally connect blocks for Br and BrOn (#5869)
Br and BrOn can consider the code before and after them connected if it might
be reached (which is the case if the Br has a condition, which BrOn always has).
The wasm2js changes may look a little odd as some of them have this:
i64toi32_i32$1 = i64toi32_i32$2;
i64toi32_i32$1 = i64toi32_i32$2;
I looked into that and the reason is that those outputs are not optimized, and
also even in unoptimized wasm2js we do run simplify-locals once (to try to
reduce the downsides of flatten). As a result, this PR makes a difference there,
and that difference can lead to such odd duplicated code after other operations.
However, there are no changes to optimized wasm2js outputs, so there is no
actual problem.
Followup to #5860.
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/linear-execution.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/ir/linear-execution.h b/src/ir/linear-execution.h index b7020f7fb..c6593bd64 100644 --- a/src/ir/linear-execution.h +++ b/src/ir/linear-execution.h @@ -127,9 +127,16 @@ struct LinearExecutionWalker : public PostWalker<SubType, VisitorType> { } case Expression::Id::BreakId: { self->pushTask(SubType::doVisitBreak, currp); - self->pushTask(SubType::doNoteNonLinear, currp); - self->maybePushTask(SubType::scan, &curr->cast<Break>()->condition); - self->maybePushTask(SubType::scan, &curr->cast<Break>()->value); + auto* br = curr->cast<Break>(); + // If there is no condition then we note non-linearity as the code after + // us is unreachable anyhow (we do the same for Switch, Return, etc.). + // If there is a condition, then we note or do not note depending on + // whether we allow adjacent blocks. + if (!br->condition || !self->connectAdjacentBlocks) { + self->pushTask(SubType::doNoteNonLinear, currp); + } + self->maybePushTask(SubType::scan, &br->condition); + self->maybePushTask(SubType::scan, &br->value); break; } case Expression::Id::SwitchId: { @@ -185,7 +192,9 @@ struct LinearExecutionWalker : public PostWalker<SubType, VisitorType> { } case Expression::Id::BrOnId: { self->pushTask(SubType::doVisitBrOn, currp); - self->pushTask(SubType::doNoteNonLinear, currp); + if (!self->connectAdjacentBlocks) { + self->pushTask(SubType::doNoteNonLinear, currp); + } self->pushTask(SubType::scan, &curr->cast<BrOn>()->ref); break; } |