summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-22 16:48:57 -0700
committerGitHub <noreply@github.com>2021-03-22 16:48:57 -0700
commit5ef255154172504385a8218f9712a48d98a47689 (patch)
tree6c15e2fdcfd739e83fb23aab225935b37b617175
parent418804035056bcd133ff5e292bf645d5d26d8d0d (diff)
downloadbinaryen-5ef255154172504385a8218f9712a48d98a47689.tar.gz
binaryen-5ef255154172504385a8218f9712a48d98a47689.tar.bz2
binaryen-5ef255154172504385a8218f9712a48d98a47689.zip
Use the type in selectification in RemoveUnusedBrs (#3716)
We have the if's type, and when replacing it with a select, can use that type. This could be more efficient. It also avoids a current crash after the removal of LUBs, but it's worth doing regardless of that.
-rw-r--r--src/passes/RemoveUnusedBrs.cpp2
-rw-r--r--test/passes/remove-unused-brs_all-features.txt17
-rw-r--r--test/passes/remove-unused-brs_all-features.wast16
3 files changed, 34 insertions, 1 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index 5d236211b..eaf681a08 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -993,7 +993,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> {
return nullptr;
}
return Builder(*getModule())
- .makeSelect(iff->condition, iff->ifTrue, iff->ifFalse);
+ .makeSelect(iff->condition, iff->ifTrue, iff->ifFalse, iff->type);
}
void visitLocalSet(LocalSet* curr) {
diff --git a/test/passes/remove-unused-brs_all-features.txt b/test/passes/remove-unused-brs_all-features.txt
index 3365ebb75..f8308c65f 100644
--- a/test/passes/remove-unused-brs_all-features.txt
+++ b/test/passes/remove-unused-brs_all-features.txt
@@ -1,8 +1,12 @@
(module
(type $struct (struct (field (ref null $vector))))
(type $vector (array (mut i32)))
+ (type $i32_=>_none (func (param i32)))
+ (type $none_=>_i32 (func (result i32)))
(type $none_=>_f64 (func (result f64)))
+ (type $i32_=>_funcref (func (param i32) (result funcref)))
(type $none_=>_ref?|$struct| (func (result (ref null $struct))))
+ (elem declare func $i32_=>_none $none_=>_i32)
(func $foo (result (ref null $struct))
(if (result (ref null $struct))
(i32.const 1)
@@ -33,4 +37,17 @@
)
)
)
+ (func $none_=>_i32 (result i32)
+ (unreachable)
+ )
+ (func $i32_=>_none (param $0 i32)
+ (nop)
+ )
+ (func $selectify (param $x i32) (result funcref)
+ (select (result funcref)
+ (ref.func $none_=>_i32)
+ (ref.func $i32_=>_none)
+ (local.get $x)
+ )
+ )
)
diff --git a/test/passes/remove-unused-brs_all-features.wast b/test/passes/remove-unused-brs_all-features.wast
index 3703bb9f2..1da00291d 100644
--- a/test/passes/remove-unused-brs_all-features.wast
+++ b/test/passes/remove-unused-brs_all-features.wast
@@ -16,6 +16,7 @@
(ref.null $struct)
)
)
+
(func $test-prefinalize (result f64)
(loop $loop (result f64)
(block $block (result f64)
@@ -37,4 +38,19 @@
)
)
)
+
+ (func $none_=>_i32 (result i32)
+ (unreachable)
+ )
+ (func $i32_=>_none (param i32)
+ )
+ (func $selectify (param $x i32) (result funcref)
+ ;; this if has arms with different function types, for which funcref is the
+ ;; LUB
+ (if (result funcref)
+ (local.get $x)
+ (ref.func $none_=>_i32)
+ (ref.func $i32_=>_none)
+ )
+ )
)