blob: 4e92880b30930ba323f6840b8d76d0df13a722f3 [file] [log] [blame] [edit]
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-opt --nominal --global-refining -all -S -o - | filecheck %s
(module
;; Globals with no assignments aside from their initial values. The first is
;; a null, so we have nothing concrete to improve with (though we could use
;; the type of the null perhaps, TODO). The second is a ref.func which lets
;; us refine.
;; CHECK: (type $foo_t (func_subtype func))
(type $foo_t (func))
;; CHECK: (global $func-null-init (mut funcref) (ref.null $foo_t))
(global $func-null-init (mut funcref) (ref.null $foo_t))
;; CHECK: (global $func-func-init (mut (ref $foo_t)) (ref.func $foo))
(global $func-func-init (mut funcref) (ref.func $foo))
;; CHECK: (func $foo (type $foo_t)
;; CHECK-NEXT: (nop)
;; CHECK-NEXT: )
(func $foo (type $foo_t))
)
(module
;; Globals with later assignments of null. The global with a function in its
;; init will update the null to allow it to refine.
;; CHECK: (type $foo_t (func_subtype func))
(type $foo_t (func))
;; CHECK: (global $func-null-init (mut funcref) (ref.null $foo_t))
(global $func-null-init (mut funcref) (ref.null $foo_t))
;; CHECK: (global $func-func-init (mut (ref null $foo_t)) (ref.func $foo))
(global $func-func-init (mut funcref) (ref.func $foo))
;; CHECK: (func $foo (type $foo_t)
;; CHECK-NEXT: (global.set $func-null-init
;; CHECK-NEXT: (ref.null func)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $func-func-init
;; CHECK-NEXT: (ref.null $foo_t)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $foo (type $foo_t)
(global.set $func-null-init (ref.null func))
(global.set $func-func-init (ref.null $foo_t))
)
)
(module
;; Globals with later assignments of something non-null. Both can be refined,
;; and the one with a non-null initial value can even become non-nullable.
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (global $func-null-init (mut (ref null $none_=>_none)) (ref.null $none_=>_none))
(global $func-null-init (mut funcref) (ref.null func))
;; CHECK: (global $func-func-init (mut (ref $none_=>_none)) (ref.func $foo))
(global $func-func-init (mut funcref) (ref.func $foo))
;; CHECK: (elem declare func $foo)
;; CHECK: (func $foo (type $none_=>_none)
;; CHECK-NEXT: (global.set $func-null-init
;; CHECK-NEXT: (ref.func $foo)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $func-func-init
;; CHECK-NEXT: (ref.func $foo)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $foo
(global.set $func-null-init (ref.func $foo))
(global.set $func-func-init (ref.func $foo))
)
)
(module
;; A global with multiple later assignments. The refined type is more
;; specific than the original, but less than each of the non-null values.
;; CHECK: (type $none_=>_none (func_subtype func))
;; CHECK: (type $struct (struct_subtype data))
(type $struct (struct))
;; CHECK: (type $array (array_subtype i8 data))
(type $array (array i8))
;; CHECK: (global $global (mut eqref) (ref.null eq))
(global $global (mut anyref) (ref.null any))
;; CHECK: (func $foo (type $none_=>_none)
;; CHECK-NEXT: (global.set $global
;; CHECK-NEXT: (i31.new
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $global
;; CHECK-NEXT: (struct.new_default $struct)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $global
;; CHECK-NEXT: (ref.null eq)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $global
;; CHECK-NEXT: (ref.null i31)
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $global
;; CHECK-NEXT: (ref.null $array)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $foo
(global.set $global (i31.new (i32.const 0)))
(global.set $global (struct.new_default $struct))
(global.set $global (ref.null eq))
;; These nulls will be updated.
(global.set $global (ref.null i31))
(global.set $global (ref.null $array))
)
)