summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-07-21 13:12:27 -0700
committerGitHub <noreply@github.com>2023-07-21 13:12:27 -0700
commit84af3482c31bb33595cbb72f30070bc27eab721c (patch)
tree34f71b02d0ab5cc781948668a9cac51bcbb193ef
parent794a7ee41068ffe450bf904de504f2cad36d1f21 (diff)
downloadbinaryen-84af3482c31bb33595cbb72f30070bc27eab721c.tar.gz
binaryen-84af3482c31bb33595cbb72f30070bc27eab721c.tar.bz2
binaryen-84af3482c31bb33595cbb72f30070bc27eab721c.zip
SimplifyLocals: Refinalize after removing redundant tees (#5830)
-rw-r--r--src/passes/SimplifyLocals.cpp3
-rw-r--r--test/lit/passes/simplify-locals-gc.wast24
2 files changed, 27 insertions, 0 deletions
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp
index 07527ee14..a042ba573 100644
--- a/src/passes/SimplifyLocals.cpp
+++ b/src/passes/SimplifyLocals.cpp
@@ -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));
diff --git a/test/lit/passes/simplify-locals-gc.wast b/test/lit/passes/simplify-locals-gc.wast
index 365373c83..6b2b10462 100644
--- a/test/lit/passes/simplify-locals-gc.wast
+++ b/test/lit/passes/simplify-locals-gc.wast
@@ -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)
+ )
+ )
+ )
+ )
+ )
)