summaryrefslogtreecommitdiff
path: root/test/lit/passes/stack-ir-dce.wast
blob: 24afb48401c14167ef99362eaf1f80e754285d40 (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
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.

;; RUN: wasm-opt %s --generate-stack-ir --optimize-stack-ir -all --print-stack-ir | filecheck %s
;; Also verify we roundtrip the output here properly.
;; RUN: wasm-opt %s --generate-stack-ir --optimize-stack-ir -all --roundtrip --print | filecheck %s --check-prefix=ROUNDTRIP

(module
  ;; CHECK:      (func $drop-unreachable (type $0) (result i32)
  ;; CHECK-NEXT:  call $drop-unreachable
  ;; CHECK-NEXT:  unreachable
  ;; CHECK-NEXT: )
  ;; ROUNDTRIP:      (func $drop-unreachable (type $0) (result i32)
  ;; ROUNDTRIP-NEXT:  (drop
  ;; ROUNDTRIP-NEXT:   (call $drop-unreachable)
  ;; ROUNDTRIP-NEXT:  )
  ;; ROUNDTRIP-NEXT:  (unreachable)
  ;; ROUNDTRIP-NEXT: )
  (func $drop-unreachable (result i32)
    ;; This drop can be removed.
    (drop
      (call $drop-unreachable)
    )
    (unreachable)
  )

  ;; CHECK:      (func $unreachable (type $0) (result i32)
  ;; CHECK-NEXT:  unreachable
  ;; CHECK-NEXT: )
  ;; ROUNDTRIP:      (func $unreachable (type $0) (result i32)
  ;; ROUNDTRIP-NEXT:  (unreachable)
  ;; ROUNDTRIP-NEXT: )
  (func $unreachable (result i32)
    ;; An unreachable with nothing before it. Check we do not error here.
    (unreachable)
  )

  ;; CHECK:      (func $unreachable-non-drop (type $1)
  ;; CHECK-NEXT:  call $unreachable-non-drop
  ;; CHECK-NEXT:  unreachable
  ;; CHECK-NEXT: )
  ;; ROUNDTRIP:      (func $unreachable-non-drop (type $1)
  ;; ROUNDTRIP-NEXT:  (call $unreachable-non-drop)
  ;; ROUNDTRIP-NEXT:  (unreachable)
  ;; ROUNDTRIP-NEXT: )
  (func $unreachable-non-drop
    ;; An unreachable with something other than a drop before it. Check we do
    ;; not error here.
    (call $unreachable-non-drop)
    (unreachable)
  )

  ;; CHECK:      (func $many-drop-unreachable (type $0) (result i32)
  ;; CHECK-NEXT:  i32.const 1
  ;; CHECK-NEXT:  if (result i32)
  ;; CHECK-NEXT:   call $drop-unreachable
  ;; CHECK-NEXT:   unreachable
  ;; CHECK-NEXT:  else
  ;; CHECK-NEXT:   call $drop-unreachable
  ;; CHECK-NEXT:   unreachable
  ;; CHECK-NEXT:  end
  ;; CHECK-NEXT:  drop
  ;; CHECK-NEXT:  call $drop-unreachable
  ;; CHECK-NEXT:  unreachable
  ;; CHECK-NEXT: )
  ;; ROUNDTRIP:      (func $many-drop-unreachable (type $0) (result i32)
  ;; ROUNDTRIP-NEXT:  (drop
  ;; ROUNDTRIP-NEXT:   (if (result i32)
  ;; ROUNDTRIP-NEXT:    (i32.const 1)
  ;; ROUNDTRIP-NEXT:    (then
  ;; ROUNDTRIP-NEXT:     (drop
  ;; ROUNDTRIP-NEXT:      (call $drop-unreachable)
  ;; ROUNDTRIP-NEXT:     )
  ;; ROUNDTRIP-NEXT:     (unreachable)
  ;; ROUNDTRIP-NEXT:    )
  ;; ROUNDTRIP-NEXT:    (else
  ;; ROUNDTRIP-NEXT:     (drop
  ;; ROUNDTRIP-NEXT:      (call $drop-unreachable)
  ;; ROUNDTRIP-NEXT:     )
  ;; ROUNDTRIP-NEXT:     (unreachable)
  ;; ROUNDTRIP-NEXT:    )
  ;; ROUNDTRIP-NEXT:   )
  ;; ROUNDTRIP-NEXT:  )
  ;; ROUNDTRIP-NEXT:  (drop
  ;; ROUNDTRIP-NEXT:   (call $drop-unreachable)
  ;; ROUNDTRIP-NEXT:  )
  ;; ROUNDTRIP-NEXT:  (unreachable)
  ;; ROUNDTRIP-NEXT: )
  (func $many-drop-unreachable (result i32)
    ;; Two drop-unreachables in an if. The drop on the if can remain, but all
    ;; others are removable.
    (drop
      (if (result i32)
        (i32.const 1)
        (then
          (drop
            (call $drop-unreachable)
          )
          (unreachable)
        )
        (else
          (drop
            (call $drop-unreachable)
          )
          (unreachable)
        )
      )
    )
    ;;  Two more outside the if.
    (drop
      (call $drop-unreachable)
    )
    (unreachable)
    (drop
      (call $drop-unreachable)
    )
    (unreachable)
  )
)