Skip to content

Commit

Permalink
SimplifyLocals: Refinalize after removing redundant tees (WebAssembly…
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken authored Jul 21, 2023
1 parent 794a7ee commit 84af348
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/passes/SimplifyLocals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,9 @@ struct SimplifyLocals
// This is an unnecessary copy!
if (removeEquivalentSets) {
if (curr->isTee()) {
if (curr->value->type != curr->type) {
refinalize = true;
}
this->replaceCurrent(curr->value);
} else {
this->replaceCurrent(Builder(*module).makeDrop(curr->value));
Expand Down
24 changes: 24 additions & 0 deletions test/lit/passes/simplify-locals-gc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,28 @@
)
)
)

;; CHECK: (func $redundant-tee-finalize (type $anyref_=>_none) (param $x anyref)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (ref.cast any
;; CHECK-NEXT: (ref.cast any
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $redundant-tee-finalize (param $x anyref)
;; The tee in the middle will be removed, as it copies a local to itself.
;; After doing so, the outer cast should become non-nullable as we
;; refinalize.
(drop
(ref.cast null any
(local.tee $x
(ref.cast any
(local.get $x)
)
)
)
)
)
)

0 comments on commit 84af348

Please sign in to comment.