summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-10-14 13:57:03 -0700
committerGitHub <noreply@github.com>2024-10-14 13:57:03 -0700
commit31b4558f3decc49c5d780083d995d7c094132b77 (patch)
tree4dbc8550256c4a4713ca64ec33d937841eef8aae /test
parent34906bfbc99d31b3e62d2d006af2247d8418ba2f (diff)
downloadbinaryen-31b4558f3decc49c5d780083d995d7c094132b77.tar.gz
binaryen-31b4558f3decc49c5d780083d995d7c094132b77.tar.bz2
binaryen-31b4558f3decc49c5d780083d995d7c094132b77.zip
[WasmGC] OptimizeInstructions: Reorder externalize/internalize operations with ref.as_non_null (#7004)
(any.convert_extern/extern.convert_any (ref.as_non_null ..)) => (ref.as_non_null (any.convert_extern/extern.convert_any ..)) This then allows the RefAsNonNull to be combined with parents in some cases (whereas the reverse allows nothing).
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/optimize-instructions-gc-extern.wast39
1 files changed, 34 insertions, 5 deletions
diff --git a/test/lit/passes/optimize-instructions-gc-extern.wast b/test/lit/passes/optimize-instructions-gc-extern.wast
index 658b2b115..067efb0ec 100644
--- a/test/lit/passes/optimize-instructions-gc-extern.wast
+++ b/test/lit/passes/optimize-instructions-gc-extern.wast
@@ -3,6 +3,9 @@
;; RUN: | filecheck %s
(module
+ ;; CHECK: (type $array (array (mut i8)))
+ (type $array (array (mut i8)))
+
;; CHECK: (func $extern.convert_any (type $0) (param $x anyref) (param $y externref)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (extern.convert_any
@@ -10,8 +13,8 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
- ;; CHECK-NEXT: (extern.convert_any
- ;; CHECK-NEXT: (ref.as_non_null
+ ;; CHECK-NEXT: (ref.as_non_null
+ ;; CHECK-NEXT: (extern.convert_any
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
@@ -22,20 +25,22 @@
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
- ;; CHECK-NEXT: (any.convert_extern
- ;; CHECK-NEXT: (ref.as_non_null
+ ;; CHECK-NEXT: (ref.as_non_null
+ ;; CHECK-NEXT: (any.convert_extern
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
- (func $extern.convert_any (export "ext") (param $x (ref null any)) (param $y (ref null extern))
+ (func $extern.convert_any (param $x (ref null any)) (param $y (ref null extern))
;; We should not change anything here, and also not hit an internal error.
(drop
(extern.convert_any
(local.get $x)
)
)
+ ;; We can reorder the externalize with the ref.as_non_null, which sometimes
+ ;; helps later optimizations, see below.
(drop
(extern.convert_any
(ref.as_non_null
@@ -43,6 +48,7 @@
)
)
)
+ ;; As the above two cases, but for internalize.
(drop
(any.convert_extern
(local.get $y)
@@ -56,4 +62,27 @@
)
)
)
+
+ ;; CHECK: (func $convert.optimize.parent (type $1) (param $ext externref)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (ref.cast (ref $array)
+ ;; CHECK-NEXT: (any.convert_extern
+ ;; CHECK-NEXT: (local.get $ext)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $convert.optimize.parent (param $ext externref)
+ ;; The ref.cast can fold in the ref.as_non_null, after it is moved
+ ;; outside of the any.convert_extern.
+ (drop
+ (ref.cast (ref null $array)
+ (any.convert_extern
+ (ref.as_non_null
+ (local.get $ext)
+ )
+ )
+ )
+ )
+ )
)