File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed
Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -1008,8 +1008,13 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
10081008 // (...)
10091009 // (ref.null bot<X>)
10101010 // )
1011- curr->ref = maybeCast (
1012- curr->ref , Type (curr->getSentType ().getHeapType (), Nullable));
1011+ //
1012+ // A RefCast is added in some cases, but this is still generally
1013+ // worth doing as the BrOnNonNull and the appended null may end up
1014+ // optimized with surrounding code.
1015+ auto * casted =
1016+ maybeCast (curr->ref , curr->getSentType ().with (Nullable));
1017+ curr->ref = casted;
10131018 curr->op = BrOnNonNull;
10141019 curr->castType = Type::none;
10151020 curr->type = Type::none;
Original file line number Diff line number Diff line change 1+ ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
3+ ;; RUN: wasm-opt %s -all --remove-unused-brs -S -o - | filecheck %s
4+
5+ ;; Like "remove-unused-brs-exact.wast", but with exact types in the input so we
6+ ;; cannot have a NO_CD mode.
7+
8+ (module
9+ ;; CHECK: (type $foo (struct))
10+ (type $foo (struct ))
11+
12+ ;; CHECK: (func $br_on_cast_to_non_null (type $1) (param $foo (ref null $foo)) (result (ref (exact $foo)))
13+ ;; CHECK-NEXT: (block $block (result (ref (exact $foo)))
14+ ;; CHECK-NEXT: (drop
15+ ;; CHECK-NEXT: (block (result nullref)
16+ ;; CHECK-NEXT: (br_on_non_null $block
17+ ;; CHECK-NEXT: (ref.cast (ref null (exact $foo))
18+ ;; CHECK-NEXT: (local.get $foo)
19+ ;; CHECK-NEXT: )
20+ ;; CHECK-NEXT: )
21+ ;; CHECK-NEXT: (ref.null none)
22+ ;; CHECK-NEXT: )
23+ ;; CHECK-NEXT: )
24+ ;; CHECK-NEXT: (unreachable)
25+ ;; CHECK-NEXT: )
26+ ;; CHECK-NEXT: )
27+ (func $br_on_cast_to_non_null (param $foo (ref null $foo )) (result (ref (exact $foo )))
28+ ;; We can simplify the br_on_cast to a br_on_non_null plus a cast.
29+ (block $block (result (ref (exact $foo )))
30+ (drop
31+ (br_on_cast $block (ref null $foo ) (ref (exact $foo ))
32+ (local.get $foo )
33+ )
34+ )
35+ (unreachable )
36+ )
37+ )
38+ )
You can’t perform that action at this time.
0 commit comments