summaryrefslogtreecommitdiff
path: root/test/lit/passes/ssa.wast
blob: 0d696f75a0d45b9eb7f895b68dc514b2fe5781d7 (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
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s -all --ssa -S -o - | filecheck %s

(module
 ;; CHECK:      (type $A (struct))
 (type $A (struct ))

 ;; CHECK:      (func $foo (type $1)
 ;; CHECK-NEXT: )
 (func $foo)

 ;; CHECK:      (func $bar (type $2) (param $x (ref func))
 ;; CHECK-NEXT:  (local $1 (ref func))
 ;; CHECK-NEXT:  (local $2 (ref func))
 ;; CHECK-NEXT:  (local.set $1
 ;; CHECK-NEXT:   (ref.func $foo)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT:  (drop
 ;; CHECK-NEXT:   (local.get $1)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT:  (local.set $2
 ;; CHECK-NEXT:   (ref.func $bar)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT:  (drop
 ;; CHECK-NEXT:   (local.get $2)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $bar (param $x (ref func))
  ;; assign a non-nullable parameter multiple times, which causes ssa to create
  ;; new locals so that each is assigned only once
  (local.set $x (ref.func $foo))
  (drop (local.get $x))
  (local.set $x (ref.func $bar))
  (drop (local.get $x))
 )

 ;; CHECK:      (func $refine-to-null (type $3) (result (ref $A))
 ;; CHECK-NEXT:  (local $0 (ref null $A))
 ;; CHECK-NEXT:  (block $label (result (ref none))
 ;; CHECK-NEXT:   (drop
 ;; CHECK-NEXT:    (br_on_cast $label nullref (ref none)
 ;; CHECK-NEXT:     (ref.null none)
 ;; CHECK-NEXT:    )
 ;; CHECK-NEXT:   )
 ;; CHECK-NEXT:   (unreachable)
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $refine-to-null (result (ref $A))
  (local $0 (ref null $A))
  (block $label (result (ref $A))
   (drop
    (br_on_cast $label (ref null $A) (ref $A)
     ;; This will turn into a null, which has a more refined type that affects
     ;; the br_on_cast parent.
     (local.get $0)
    )
   )
   (unreachable)
  )
 )

 ;; CHECK:      (func $null-tuple (type $4) (result funcref)
 ;; CHECK-NEXT:  (local $tuple (tuple i32 funcref))
 ;; CHECK-NEXT:  (tuple.extract 2 1
 ;; CHECK-NEXT:   (tuple.make 2
 ;; CHECK-NEXT:    (i32.const 0)
 ;; CHECK-NEXT:    (ref.null nofunc)
 ;; CHECK-NEXT:   )
 ;; CHECK-NEXT:  )
 ;; CHECK-NEXT: )
 (func $null-tuple (result funcref)
  (local $tuple (tuple i32 funcref))
  (tuple.extract 2 1
   (local.get $tuple)
  )
 )
)