summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-04-21 19:54:56 -0700
committerGitHub <noreply@github.com>2021-04-21 19:54:56 -0700
commit0379e8b42daa116336f2688d02eeebed2240a99c (patch)
tree584a078f3c99c355581cdb31cc492a4f07ac99ec
parent0e0147dd18a3875bde24f418b23230d454942c4a (diff)
downloadbinaryen-0379e8b42daa116336f2688d02eeebed2240a99c.tar.gz
binaryen-0379e8b42daa116336f2688d02eeebed2240a99c.tar.bz2
binaryen-0379e8b42daa116336f2688d02eeebed2240a99c.zip
[Wasm GC] Skip DeadArgumentElimination of an RTT parameter (#3834)
We could more carefully see when a local is not needed there, but atm we always add one, and that doesn't work for something nondefaultable.
-rw-r--r--src/passes/DeadArgumentElimination.cpp10
-rw-r--r--test/lit/passes/dae-gc.wast20
2 files changed, 28 insertions, 2 deletions
diff --git a/src/passes/DeadArgumentElimination.cpp b/src/passes/DeadArgumentElimination.cpp
index 37aaace37..33ca81dc7 100644
--- a/src/passes/DeadArgumentElimination.cpp
+++ b/src/passes/DeadArgumentElimination.cpp
@@ -373,13 +373,19 @@ struct DAE : public Pass {
// Great, it's not used. Check if none of the calls has a param with
// side effects, as that would prevent us removing them (flattening
// should have been done earlier).
- bool canRemove =
+ bool callParamsAreValid =
std::none_of(calls.begin(), calls.end(), [&](Call* call) {
auto* operand = call->operands[i];
return EffectAnalyzer(runner->options, module->features, operand)
.hasSideEffects();
});
- if (canRemove) {
+ // The type must be valid for us to handle as a local (since we
+ // replace the parameter with a local).
+ // TODO: if there are no references at all, we can avoid creating a
+ // local
+ bool typeIsValid =
+ TypeUpdating::canHandleAsLocal(func->getLocalType(i));
+ if (callParamsAreValid && typeIsValid) {
// Wonderful, nothing stands in our way! Do it.
// TODO: parallelize this?
removeParameter(func, i, calls);
diff --git a/test/lit/passes/dae-gc.wast b/test/lit/passes/dae-gc.wast
index 87e480cc8..fe4b346ea 100644
--- a/test/lit/passes/dae-gc.wast
+++ b/test/lit/passes/dae-gc.wast
@@ -2,6 +2,8 @@
;; RUN: wasm-opt %s -all --dae -S -o - | filecheck %s
(module
+ (type ${} (struct))
+
;; CHECK: (func $foo
;; CHECK-NEXT: (call $bar)
;; CHECK-NEXT: )
@@ -46,4 +48,22 @@
(unreachable)
)
)
+ ;; a function that gets an rtt that is never used. we cannot create a local for
+ ;; that parameter, as it is not defaultable, so do not remove the parameter.
+ ;; CHECK: (func $get-rtt (param $0 (rtt ${}))
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: )
+ (func $get-rtt (param $0 (rtt ${}))
+ (nop)
+ )
+ ;; CHECK: (func $send-rtt
+ ;; CHECK-NEXT: (call $get-rtt
+ ;; CHECK-NEXT: (rtt.canon ${})
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $send-rtt
+ (call $get-rtt
+ (rtt.canon ${})
+ )
+ )
)