summaryrefslogtreecommitdiff
path: root/test/lit/passes/global-refining.wast
blob: 633d88e5f8112156c702d94f12b9faadf7fbf8d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
;; 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 $none_=>_none (func_subtype func))

  ;; CHECK:      (global $func-null-init (mut anyref) (ref.null func))
  (global $func-null-init (mut anyref) (ref.null func))
  ;; CHECK:      (global $func-func-init (mut (ref $none_=>_none)) (ref.func $foo))
  (global $func-func-init (mut anyref) (ref.func $foo))
  ;; CHECK:      (func $foo (type $none_=>_none)
  ;; CHECK-NEXT:  (nop)
  ;; CHECK-NEXT: )
  (func $foo)
)

(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 $none_=>_none (func_subtype func))

  ;; CHECK:      (global $func-null-init (mut anyref) (ref.null func))
  (global $func-null-init (mut anyref) (ref.null func))
  ;; CHECK:      (global $func-func-init (mut (ref null $none_=>_none)) (ref.func $foo))
  (global $func-func-init (mut anyref) (ref.func $foo))

  ;; CHECK:      (func $foo (type $none_=>_none)
  ;; CHECK-NEXT:  (global.set $func-null-init
  ;; CHECK-NEXT:   (ref.null any)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (global.set $func-func-init
  ;; CHECK-NEXT:   (ref.null $none_=>_none)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $foo
   (global.set $func-null-init (ref.null any))
   (global.set $func-func-init (ref.null any))
  )
)

(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 anyref) (ref.null func))
  ;; CHECK:      (global $func-func-init (mut (ref $none_=>_none)) (ref.func $foo))
  (global $func-func-init (mut anyref) (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 $i32_=>_none (func_subtype (param i32) func))

  ;; CHECK:      (global $global (mut funcref) (ref.null func))
  (global $global (mut anyref) (ref.null any))

  ;; CHECK:      (elem declare func $bar $foo)

  ;; CHECK:      (func $foo (type $none_=>_none)
  ;; CHECK-NEXT:  (global.set $global
  ;; CHECK-NEXT:   (ref.func $foo)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (global.set $global
  ;; CHECK-NEXT:   (ref.func $bar)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (global.set $global
  ;; CHECK-NEXT:   (ref.null func)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (global.set $global
  ;; CHECK-NEXT:   (ref.null func)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (global.set $global
  ;; CHECK-NEXT:   (ref.null func)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $foo
   (global.set $global (ref.func $foo))
   (global.set $global (ref.func $bar))
   (global.set $global (ref.null func))
   ;; These nulls will be updated.
   (global.set $global (ref.null eq))
   (global.set $global (ref.null data))
  )

  ;; CHECK:      (func $bar (type $i32_=>_none) (param $x i32)
  ;; CHECK-NEXT:  (nop)
  ;; CHECK-NEXT: )
  (func $bar (param $x i32)
    ;; A function with a different signature, whose reference is also assigned
    ;; to the global.
  )
)