summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-03-14 10:23:37 -0700
committerGitHub <noreply@github.com>2024-03-14 10:23:37 -0700
commit7bd37d404e679407c283a90c4d13f770c6067229 (patch)
tree54ec4b8519020053e4073cac34f7e91e25ca48c7 /test
parent08e47de21223c3605edd71347e6b8b24b4187294 (diff)
downloadbinaryen-7bd37d404e679407c283a90c4d13f770c6067229.tar.gz
binaryen-7bd37d404e679407c283a90c4d13f770c6067229.tar.bz2
binaryen-7bd37d404e679407c283a90c4d13f770c6067229.zip
[NFC] Refactor ChildLocalizer to handle unreachable code better (#6394)
This is NFC in the current users, but is necessary functionality for a later PR. ChildLocalizer moves children into locals as needed. It used to stop when it saw the first unreachable. After this change we move such unreachable children out of the parent as well, making this more uniform: all interacting effects are moved out, and all that is left nested in the parent can be moved around and removed as desired. Also add a getReplacement helper that makes using this easier. This cannot be tested comprehensively with the current user as that user will not call this code path on an unreachable parent at all, so this just adds what can be tested. The later PR will have tests for all corner cases.
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/gto-removals.wast46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/lit/passes/gto-removals.wast b/test/lit/passes/gto-removals.wast
index d49ab1201..ad406bbda 100644
--- a/test/lit/passes/gto-removals.wast
+++ b/test/lit/passes/gto-removals.wast
@@ -925,3 +925,49 @@
(unreachable)
)
)
+
+(module
+ ;; CHECK: (rec
+ ;; CHECK-NEXT: (type $struct (sub (struct )))
+ (type $struct (sub (struct (field anyref) (field i32) (field f32) (field f64))))
+
+ ;; CHECK: (type $1 (func (result (ref $struct))))
+
+ ;; CHECK: (func $func (type $1) (result (ref $struct))
+ ;; CHECK-NEXT: (local $0 (ref $struct))
+ ;; CHECK-NEXT: (local $1 f64)
+ ;; CHECK-NEXT: (local.set $0
+ ;; CHECK-NEXT: (call $func)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (local.set $1
+ ;; CHECK-NEXT: (block (result f64)
+ ;; CHECK-NEXT: (if
+ ;; CHECK-NEXT: (i32.const 0)
+ ;; CHECK-NEXT: (then
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (f64.const 30)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (struct.new_default $struct)
+ ;; CHECK-NEXT: )
+ (func $func (result (ref $struct))
+ ;; The fields can be removed here, but the effects must be preserved before
+ ;; the struct.new. The consts in the middle can vanish entirely.
+ (struct.new $struct
+ (call $func)
+ (i32.const 10)
+ (f32.const 20)
+ (block (result f64)
+ (if
+ (i32.const 0)
+ (then
+ (unreachable)
+ )
+ )
+ (f64.const 30)
+ )
+ )
+ )
+)