Skip to content
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
11 changes: 6 additions & 5 deletions src/passes/RemoveUnusedBrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,12 +855,13 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {

void visitBrOn(BrOn* curr) {
// Ignore unreachable BrOns which we cannot improve anyhow. Note that
// we must check the ref field manually, as we may be changing types as
// we go here. (Another option would be to use a TypeUpdater here
// instead of calling ReFinalize at the very end, but that would be more
// complex and slower.)
// we must check the ref and desc fields manually, as we may be changing
// types as we go here. (Another option would be to use a TypeUpdater
// here instead of calling ReFinalize at the very end, but that would be
// more complex and slower.)
if (curr->type == Type::unreachable ||
curr->ref->type == Type::unreachable) {
curr->ref->type == Type::unreachable ||
(curr->desc && curr->desc->type == Type::unreachable)) {
return;
}

Expand Down
32 changes: 32 additions & 0 deletions test/lit/passes/remove-unused-brs-desc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -783,4 +783,36 @@
)
)
)

;; CHECK: (func $unreachable-desc (type $17) (param $any anyref) (param $d (ref (exact $super.desc))) (result anyref)
;; CHECK-NEXT: (block $block (result (ref (exact $super.desc)))
;; CHECK-NEXT: (block (result (ref (exact $super.desc)))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.tee $any
;; CHECK-NEXT: (ref.i31
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.get $d)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $unreachable-desc (param $any anyref) (param $d (ref (exact $super.desc))) (result anyref)
;; The inner br_on_cast is optimized into an unconditional br, making the
;; descriptor operand of the outer br_on_cast_desc_eq unreachable before
;; ReFinalize runs.
(block $block (result anyref)
(br_on_cast_desc_eq $block anyref (ref null (exact $super))
(local.tee $any
(ref.i31
(i32.const 0)
)
)
(br_on_cast $block (ref (exact $super.desc)) (ref (exact $super.desc))
(local.get $d)
)
)
)
)
)
Loading