summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-23 13:02:52 -0700
committerGitHub <noreply@github.com>2022-08-23 13:02:52 -0700
commit594ff7b9609656edb83187cb4600b23b3f2fde37 (patch)
treec035a76773822331241df3c991d2accc5006f756
parent0ee15961e43e0282b014e4328458e065b6976ba7 (diff)
downloadbinaryen-594ff7b9609656edb83187cb4600b23b3f2fde37.tar.gz
binaryen-594ff7b9609656edb83187cb4600b23b3f2fde37.tar.bz2
binaryen-594ff7b9609656edb83187cb4600b23b3f2fde37.zip
Only look at the relevant parameter in param-utils:removeParameter (#4937)
Followup to #4910.
-rw-r--r--src/passes/param-utils.cpp7
-rw-r--r--test/lit/passes/dae_tnh.wast38
2 files changed, 40 insertions, 5 deletions
diff --git a/src/passes/param-utils.cpp b/src/passes/param-utils.cpp
index 3b0721173..e94ea95b1 100644
--- a/src/passes/param-utils.cpp
+++ b/src/passes/param-utils.cpp
@@ -79,11 +79,8 @@ bool removeParameter(const std::vector<Function*>& funcs,
bool hasUnremovable =
EffectAnalyzer(runner->options, *module, operands[index])
.hasUnremovableSideEffects();
- bool wouldChangeType =
- call->type == Type::unreachable && !call->isReturn &&
- std::any_of(operands.begin(), operands.end(), [](Expression* operand) {
- return operand->type == Type::unreachable;
- });
+ bool wouldChangeType = call->type == Type::unreachable && !call->isReturn &&
+ operands[index]->type == Type::unreachable;
return hasUnremovable || wouldChangeType;
};
bool callParamsAreValid =
diff --git a/test/lit/passes/dae_tnh.wast b/test/lit/passes/dae_tnh.wast
index 2a9fb912d..e8163150d 100644
--- a/test/lit/passes/dae_tnh.wast
+++ b/test/lit/passes/dae_tnh.wast
@@ -80,3 +80,41 @@
(func $target (param i32)
)
)
+
+(module
+ ;; CHECK: (type $i32_=>_none (func (param i32)))
+
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (func $target (param $0 i32)
+ ;; CHECK-NEXT: (local $1 f64)
+ ;; CHECK-NEXT: (local.set $1
+ ;; CHECK-NEXT: (f64.const 4.2)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (local.get $0)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $target (param $used i32) (param $unused f64)
+ ;; One parameter is used, and one is not.
+ (drop
+ (local.get $used)
+ )
+ )
+
+ ;; CHECK: (func $caller
+ ;; CHECK-NEXT: (call $target
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $caller
+ ;; There is an unreachable parameter, and as in the cases above, we can't
+ ;; remove it as it would change the type. But it isn't the param we want to
+ ;; remove here, so we can optimize: we'll remove the other param, and leave
+ ;; the unreachable, and the type does not change.
+ (call $target
+ (unreachable)
+ (f64.const 4.2)
+ )
+ )
+)