summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-30 10:25:50 -0700
committerGitHub <noreply@github.com>2021-03-30 10:25:50 -0700
commitcdac6b123b1231859dc0dfbcb88dfabe005855e3 (patch)
treece4fd0b980f07defcc310cd99bb14f11be3f2eb0
parenta3ea08bd0588099225b5f2b1fb7e6f0ad49dddcb (diff)
downloadbinaryen-cdac6b123b1231859dc0dfbcb88dfabe005855e3.tar.gz
binaryen-cdac6b123b1231859dc0dfbcb88dfabe005855e3.tar.bz2
binaryen-cdac6b123b1231859dc0dfbcb88dfabe005855e3.zip
Fix DeadArgumentElimination pass on non-nullable locals (#3751)
In this case, there is a natural place to fix things up right after removing a parameter (which is where a local gets added). Doing it there avoids doing work on all functions unnecessarily. Note that we could do something even simpler here than calling the generic code: the parameter was not used, so the new local is not used, and we could just change the type of the local or not add it at all. Those would be slightly more code though, and add complexity to the parameter removal method itself.
-rw-r--r--src/passes/DeadArgumentElimination.cpp2
-rw-r--r--test/passes/dae_all-features.txt10
-rw-r--r--test/passes/dae_all-features.wast11
3 files changed, 23 insertions, 0 deletions
diff --git a/src/passes/DeadArgumentElimination.cpp b/src/passes/DeadArgumentElimination.cpp
index 975b291b0..59337f75d 100644
--- a/src/passes/DeadArgumentElimination.cpp
+++ b/src/passes/DeadArgumentElimination.cpp
@@ -41,6 +41,7 @@
#include "ir/effects.h"
#include "ir/element-utils.h"
#include "ir/module-utils.h"
+#include "ir/type-updating.h"
#include "pass.h"
#include "passes/opt-utils.h"
#include "support/sorted_vector.h"
@@ -382,6 +383,7 @@ struct DAE : public Pass {
// Wonderful, nothing stands in our way! Do it.
// TODO: parallelize this?
removeParameter(func, i, calls);
+ TypeUpdating::handleNonNullableLocals(func, *module);
changed.insert(func);
}
}
diff --git a/test/passes/dae_all-features.txt b/test/passes/dae_all-features.txt
index ea439bc9e..773701396 100644
--- a/test/passes/dae_all-features.txt
+++ b/test/passes/dae_all-features.txt
@@ -312,3 +312,13 @@
)
)
)
+(module
+ (type $none_=>_none (func))
+ (func $0
+ (local $0 (ref null i31))
+ (nop)
+ )
+ (func $1
+ (call $0)
+ )
+)
diff --git a/test/passes/dae_all-features.wast b/test/passes/dae_all-features.wast
index 55e935f3b..67244cc23 100644
--- a/test/passes/dae_all-features.wast
+++ b/test/passes/dae_all-features.wast
@@ -193,3 +193,14 @@
)
)
)
+(module
+ ;; a removable non-nullable parameter
+ (func $0 (param $x i31ref)
+ (nop)
+ )
+ (func $1
+ (call $0
+ (i31.new (i32.const 0))
+ )
+ )
+)