diff options
author | Alon Zakai <azakai@google.com> | 2021-07-28 13:57:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-28 13:57:28 -0700 |
commit | bfe73c86b3dc6918334d678ab564e3dcb739a197 (patch) | |
tree | f1ed567f3ee91f74f8c5a17a0374c917e68c89e7 /src | |
parent | 1ed257a587a30885f42f2c1b6170d662e741ae40 (diff) | |
download | binaryen-bfe73c86b3dc6918334d678ab564e3dcb739a197.tar.gz binaryen-bfe73c86b3dc6918334d678ab564e3dcb739a197.tar.bz2 binaryen-bfe73c86b3dc6918334d678ab564e3dcb739a197.zip |
[Wasm GC] Refine return types of tail calling functions in DeadArgumentElimination (#4036)
To do this we need to look at tail calls and not just returns.
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/DeadArgumentElimination.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/passes/DeadArgumentElimination.cpp b/src/passes/DeadArgumentElimination.cpp index f3e3ae98c..601acfc5c 100644 --- a/src/passes/DeadArgumentElimination.cpp +++ b/src/passes/DeadArgumentElimination.cpp @@ -660,9 +660,25 @@ private: } // Scan the body and look at the returns. + auto processReturnType = [&](Type type) { + refinedType = Type::getLeastUpperBound(refinedType, type); + // Return whether we still look ok to do the optimization. If this is + // false then we can stop here. + return refinedType != originalType; + }; for (auto* ret : FindAll<Return>(func->body).list) { - refinedType = Type::getLeastUpperBound(refinedType, ret->value->type); - if (refinedType == originalType) { + if (!processReturnType(ret->value->type)) { + return false; + } + } + for (auto* call : FindAll<Call>(func->body).list) { + if (call->isReturn && + !processReturnType(module->getFunction(call->target)->getResults())) { + return false; + } + } + for (auto* call : FindAll<CallIndirect>(func->body).list) { + if (call->isReturn && !processReturnType(call->sig.results)) { return false; } } |