summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/passes/DeadArgumentElimination.cpp7
-rw-r--r--test/lit/passes/dae_tnh.wast34
2 files changed, 38 insertions, 3 deletions
diff --git a/src/passes/DeadArgumentElimination.cpp b/src/passes/DeadArgumentElimination.cpp
index e95dc3ff9..7ebed7127 100644
--- a/src/passes/DeadArgumentElimination.cpp
+++ b/src/passes/DeadArgumentElimination.cpp
@@ -383,13 +383,14 @@ struct DAE : public Pass {
while (1) {
if (infoMap[name].unusedParams.has(i)) {
// 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).
+ // side effects that we cannot remove (as if we can remove them, we
+ // will simply do that when we remove the parameter). Note: flattening
+ // the IR beforehand can help here.
bool callParamsAreValid =
std::none_of(calls.begin(), calls.end(), [&](Call* call) {
auto* operand = call->operands[i];
return EffectAnalyzer(runner->options, *module, operand)
- .hasSideEffects();
+ .hasUnremovableSideEffects();
});
// The type must be valid for us to handle as a local (since we
// replace the parameter with a local).
diff --git a/test/lit/passes/dae_tnh.wast b/test/lit/passes/dae_tnh.wast
new file mode 100644
index 000000000..fc9270cf3
--- /dev/null
+++ b/test/lit/passes/dae_tnh.wast
@@ -0,0 +1,34 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: foreach %s %t wasm-opt --dae --all-features -tnh -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (type $ref?|$struct|_=>_none (func (param (ref null $struct))))
+
+ ;; CHECK: (type $struct (struct (field i32)))
+ (type $struct (struct_subtype (field i32) data))
+
+ ;; CHECK: (func $target
+ ;; CHECK-NEXT: (local $0 i32)
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: )
+ (func $target (param $x i32)
+ (nop)
+ )
+
+ ;; CHECK: (func $caller (param $ref (ref null $struct))
+ ;; CHECK-NEXT: (call $target)
+ ;; CHECK-NEXT: )
+ (func $caller (param $ref (ref null $struct))
+ (call $target
+ ;; This might trap in theory, but in traps-never-happen mode which is
+ ;; enabled here, we can ignore and remove such side effects, allowing us
+ ;; to optimize away this parameter which is never used.
+ (struct.get $struct 0
+ (local.get $ref)
+ )
+ )
+ )
+)