summaryrefslogtreecommitdiff
path: root/test/lit/passes/simplify-globals-dominance.wast
blob: dddcaa98306f9b6df3c960723c817280e44b7501 (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
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: foreach %s %t wasm-opt --simplify-globals -all -S -o - | filecheck %s

(module
  ;; CHECK:      (type $0 (func))

  ;; CHECK:      (global $global (mut i32) (i32.const 0))
  (global $global (mut i32) (i32.const 0))

  ;; CHECK:      (func $test (type $0)
  ;; CHECK-NEXT:  (global.set $global
  ;; CHECK-NEXT:   (i32.const 10)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (if
  ;; CHECK-NEXT:   (i32.const 0)
  ;; CHECK-NEXT:   (then
  ;; CHECK-NEXT:    (drop
  ;; CHECK-NEXT:     (i32.const 10)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:    (call $test)
  ;; CHECK-NEXT:    (drop
  ;; CHECK-NEXT:     (global.get $global)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:   (else
  ;; CHECK-NEXT:    (drop
  ;; CHECK-NEXT:     (global.get $global)
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test
    (global.set $global
      (i32.const 10)
    )
    (if
      (i32.const 0)
      (then
        (block
          ;; This is dominated by the set, so we can apply 10 here.
          (drop
            (global.get $global)
          )
          (call $test)
          ;; This is after a call, so we do nothing (we are still dominated by the
          ;; global.set, but the call might set the global to another value).
          (drop
            (global.get $global)
          )
        )
      )
      ;; This is dominated by the set, but we do not optimize it yet. TODO
      (else
        (drop
          (global.get $global)
        )
      )
    )
  )
)