summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-09-30 09:23:06 -0700
committerGitHub <noreply@github.com>2022-09-30 16:23:06 +0000
commitfa3ff32e845ca59113fbdc2044a7dece3da6c2c8 (patch)
tree776c8e0682b76c4004cf3e4f6de4a5c910b86205
parentadedcd2dac789bf5165621c0fd4279ae7327bd3b (diff)
downloadbinaryen-fa3ff32e845ca59113fbdc2044a7dece3da6c2c8.tar.gz
binaryen-fa3ff32e845ca59113fbdc2044a7dece3da6c2c8.tar.bz2
binaryen-fa3ff32e845ca59113fbdc2044a7dece3da6c2c8.zip
Fix handling of unreachable selects in Directize (#5098)
We ignored only unreachable conditions, but we must ignore the arms as well, or else we could error.
-rw-r--r--src/passes/call-utils.h2
-rw-r--r--test/lit/passes/directize_all-features.wast36
2 files changed, 37 insertions, 1 deletions
diff --git a/src/passes/call-utils.h b/src/passes/call-utils.h
index 175946c0e..7f2ebfda3 100644
--- a/src/passes/call-utils.h
+++ b/src/passes/call-utils.h
@@ -76,7 +76,7 @@ convertToDirectCalls(T* curr,
return nullptr;
}
- if (select->condition->type == Type::unreachable) {
+ if (select->type == Type::unreachable) {
// Leave this for DCE.
return nullptr;
}
diff --git a/test/lit/passes/directize_all-features.wast b/test/lit/passes/directize_all-features.wast
index 491a7e064..51e2dab44 100644
--- a/test/lit/passes/directize_all-features.wast
+++ b/test/lit/passes/directize_all-features.wast
@@ -1242,6 +1242,42 @@
)
)
+ ;; CHECK: (func $select-non-nullable-unreachable-arm
+ ;; CHECK-NEXT: (call_indirect $0 (type $F)
+ ;; CHECK-NEXT: (ref.func $select-non-nullable)
+ ;; CHECK-NEXT: (select
+ ;; CHECK-NEXT: (f32.const 3.141590118408203)
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: (i32.const 1)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; IMMUT: (func $select-non-nullable-unreachable-arm
+ ;; IMMUT-NEXT: (call_indirect $0 (type $F)
+ ;; IMMUT-NEXT: (ref.func $select-non-nullable)
+ ;; IMMUT-NEXT: (select
+ ;; IMMUT-NEXT: (f32.const 3.141590118408203)
+ ;; IMMUT-NEXT: (unreachable)
+ ;; IMMUT-NEXT: (i32.const 1)
+ ;; IMMUT-NEXT: )
+ ;; IMMUT-NEXT: )
+ ;; IMMUT-NEXT: )
+ (func $select-non-nullable-unreachable-arm
+ ;; Test we ignore an unreachable arm and don't make any changes at all
+ ;; to the code (in particular, we shouldn't add any vars).
+ (call_indirect (type $F)
+ (ref.func $select-non-nullable)
+ (select
+ ;; Note how the type here is not even an i32, so we must not even try to
+ ;; look into the select's values at all - the select is unreachable and we
+ ;; should give up on optimizing.
+ (f32.const 3.14159)
+ (unreachable)
+ (i32.const 1)
+ )
+ )
+ )
+
;; CHECK: (func $select-non-nullable-unreachable-arg (param $x i32)
;; CHECK-NEXT: (call_indirect $0 (type $F)
;; CHECK-NEXT: (unreachable)