Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/passes/GUFA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ struct GUFAOptimizer
auto* result = Builder(*getModule()).makeConst(Literal(int32_t(0)));
replaceCurrent(getDroppedChildrenAndAppend(
curr, *getModule(), getPassOptions(), result));
optimized = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pass has an override for replaceCurrent, I wonder if we should have that method set optimized by default so that we don't forget other cases? It seems like after this PR, all usages of replaceCurrent set optimized to true. I don't have a strong opinion, I can imagine there might be cases where we don't want to set it to true unintentionally too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me. @kripken, WDYT?

}
}

Expand All @@ -260,6 +261,7 @@ struct GUFAOptimizer
auto* last = Builder(*getModule()).makeConst(Literal(int32_t(result)));
replaceCurrent(getDroppedChildrenAndAppend(
curr, *getModule(), getPassOptions(), last));
optimized = true;
};

if (!PossibleContents::haveIntersection(refContents, intendedContents)) {
Expand Down
62 changes: 62 additions & 0 deletions test/lit/passes/gufa-cast-all.wast
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,65 @@
)
)


;; Regression test for bug where optimizing expressions containing a Pop could
;; result in the Pop becoming invalidly nested inside a Block (created to
;; preserve side effects), and the optimizer failed to run the nested pop fixup
;; because it didn't mark the function as optimized.
(module
;; CHECK: (type $array (sub (array anyref)))
(type $array (sub (array (ref null any))))
;; CHECK: (type $tag-sig (func (param (ref null $array))))
(type $tag-sig (func (param (ref null $array))))
;; CHECK: (type $2 (func))

;; CHECK: (tag $tag (type $tag-sig) (param (ref null $array)))
(tag $tag (type $tag-sig) (param (ref null $array)))

;; CHECK: (func $test (type $2)
;; CHECK-NEXT: (local $0 (ref null $array))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (try (result (ref i31))
;; CHECK-NEXT: (do
;; CHECK-NEXT: (ref.i31
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (catch $tag
;; CHECK-NEXT: (local.set $0
;; CHECK-NEXT: (pop (ref null $array))
;; CHECK-NEXT: )
;; CHECK-NEXT: (ref.i31
;; CHECK-NEXT: (block (result i32)
;; CHECK-NEXT: (block
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test
(drop
(try (result (ref i31))
(do
;; This doesn't throw, so everything in the catch is unreachable.
(ref.i31 (i32.const 0))
)
(catch $tag
(ref.i31
(ref.eq
(pop (ref null $array))
(ref.i31 (i32.const 0))
)
)
)
)
)
)
)
Loading