diff options
author | Alon Zakai <azakai@google.com> | 2023-05-01 12:25:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-01 12:25:06 -0700 |
commit | 6fee09ae5734f0e16b7119649ef20818997654a3 (patch) | |
tree | 462779d6f5eaaef33ab684f4812f2d0aa7062e50 | |
parent | e87d3a455580b20fa71abf5fe58b6d62cb41980d (diff) | |
download | binaryen-6fee09ae5734f0e16b7119649ef20818997654a3.tar.gz binaryen-6fee09ae5734f0e16b7119649ef20818997654a3.tar.bz2 binaryen-6fee09ae5734f0e16b7119649ef20818997654a3.zip |
[Wasm GC] Always refinalize in SignatureRefining (#5694)
We used to refine only for result changes, but param changes can
also lead to opportunities.
-rw-r--r-- | src/passes/SignatureRefining.cpp | 11 | ||||
-rw-r--r-- | test/lit/passes/signature-refining.wast | 38 |
2 files changed, 40 insertions, 9 deletions
diff --git a/src/passes/SignatureRefining.cpp b/src/passes/SignatureRefining.cpp index de669dbb2..281214e32 100644 --- a/src/passes/SignatureRefining.cpp +++ b/src/passes/SignatureRefining.cpp @@ -156,8 +156,6 @@ struct SignatureRefining : public Pass { } } - bool refinedResults = false; - // Compute optimal LUBs. std::unordered_set<HeapType> seen; for (auto& func : module->functions) { @@ -225,8 +223,6 @@ struct SignatureRefining : public Pass { newSignatures[type] = Signature(newParams, newResults); if (newResults != func->getResults()) { - refinedResults = true; - // Update the types of calls using the signature. for (auto* call : info.calls) { if (call->type != Type::unreachable) { @@ -288,11 +284,8 @@ struct SignatureRefining : public Pass { // Rewrite the types. GlobalTypeRewriter::updateSignatures(newSignatures, *module); - if (refinedResults) { - // After return types change we need to propagate. - // TODO: we could do this only in relevant functions perhaps - ReFinalize().run(getPassRunner(), module); - } + // TODO: we could do this only in relevant functions perhaps + ReFinalize().run(getPassRunner(), module); } }; diff --git a/test/lit/passes/signature-refining.wast b/test/lit/passes/signature-refining.wast index 11bc84f35..996adf658 100644 --- a/test/lit/passes/signature-refining.wast +++ b/test/lit/passes/signature-refining.wast @@ -850,3 +850,41 @@ ) ) ) + +(module + ;; CHECK: (rec + ;; CHECK-NEXT: (type $ref|$[i8]|_=>_none (func (param (ref $[i8])))) + + ;; CHECK: (type $[i8] (array i8)) + (type $[i8] (array i8)) + + ;; CHECK: (type $none_=>_none (func)) + + ;; CHECK: (func $0 (type $none_=>_none) + ;; CHECK-NEXT: (call $1 + ;; CHECK-NEXT: (array.new_fixed $[i8]) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $0 + (call $1 + (array.new_fixed $[i8]) + ) + ) + + ;; CHECK: (func $1 (type $ref|$[i8]|_=>_none) (param $2 (ref $[i8])) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (ref.cast struct + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $1 (param $2 anyref) + ;; The param will become non-nullable after we refine. We must refinalize + ;; after doing so, so the cast becomes non-nullable as well. + (drop + (ref.cast null struct + (local.get $2) + ) + ) + ) +) ;; TODO |