summaryrefslogtreecommitdiff
path: root/test/lit/passes/simplify-locals-tnh.wast
blob: 21f4863c849011f22a9035e3af11b76ed9a7090e (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
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s --simplify-locals --traps-never-happen -all -S -o - | filecheck %s --check-prefix TNH
;; RUN: wasm-opt %s --simplify-locals                      -all -S -o - | filecheck %s --check-prefix NO_TNH


(module
  (memory 1 1)

  ;; TNH:      (global $glob (mut i32) (i32.const 0))
  ;; NO_TNH:      (global $glob (mut i32) (i32.const 0))
  (global $glob (mut i32) (i32.const 0))

  ;; TNH:      (func $optimize-past-global.set (type $0) (result i32)
  ;; TNH-NEXT:  (local $temp i32)
  ;; TNH-NEXT:  (nop)
  ;; TNH-NEXT:  (global.set $glob
  ;; TNH-NEXT:   (i32.const 1)
  ;; TNH-NEXT:  )
  ;; TNH-NEXT:  (i32.load
  ;; TNH-NEXT:   (i32.const 0)
  ;; TNH-NEXT:  )
  ;; TNH-NEXT: )
  ;; NO_TNH:      (func $optimize-past-global.set (type $0) (result i32)
  ;; NO_TNH-NEXT:  (local $temp i32)
  ;; NO_TNH-NEXT:  (local.set $temp
  ;; NO_TNH-NEXT:   (i32.load
  ;; NO_TNH-NEXT:    (i32.const 0)
  ;; NO_TNH-NEXT:   )
  ;; NO_TNH-NEXT:  )
  ;; NO_TNH-NEXT:  (global.set $glob
  ;; NO_TNH-NEXT:   (i32.const 1)
  ;; NO_TNH-NEXT:  )
  ;; NO_TNH-NEXT:  (local.get $temp)
  ;; NO_TNH-NEXT: )
  (func $optimize-past-global.set (result i32)
    (local $temp i32)
    ;; This load might trap, and so normally we can't move it past a global.set,
    ;; which has a global effect that could be noticed. However, in TNH mode we
    ;; can assume it doesn't trap and push it forward.
    (local.set $temp
      (i32.load
        (i32.const 0)
      )
    )
    (global.set $glob
      (i32.const 1)
    )
    (local.get $temp)
  )

  ;; TNH:      (func $no-optimize-past-return (type $0) (result i32)
  ;; TNH-NEXT:  (local $temp i32)
  ;; TNH-NEXT:  (local.set $temp
  ;; TNH-NEXT:   (i32.load
  ;; TNH-NEXT:    (i32.const 0)
  ;; TNH-NEXT:   )
  ;; TNH-NEXT:  )
  ;; TNH-NEXT:  (if
  ;; TNH-NEXT:   (i32.const 0)
  ;; TNH-NEXT:   (then
  ;; TNH-NEXT:    (return
  ;; TNH-NEXT:     (i32.const 1)
  ;; TNH-NEXT:    )
  ;; TNH-NEXT:   )
  ;; TNH-NEXT:  )
  ;; TNH-NEXT:  (local.get $temp)
  ;; TNH-NEXT: )
  ;; NO_TNH:      (func $no-optimize-past-return (type $0) (result i32)
  ;; NO_TNH-NEXT:  (local $temp i32)
  ;; NO_TNH-NEXT:  (local.set $temp
  ;; NO_TNH-NEXT:   (i32.load
  ;; NO_TNH-NEXT:    (i32.const 0)
  ;; NO_TNH-NEXT:   )
  ;; NO_TNH-NEXT:  )
  ;; NO_TNH-NEXT:  (if
  ;; NO_TNH-NEXT:   (i32.const 0)
  ;; NO_TNH-NEXT:   (then
  ;; NO_TNH-NEXT:    (return
  ;; NO_TNH-NEXT:     (i32.const 1)
  ;; NO_TNH-NEXT:    )
  ;; NO_TNH-NEXT:   )
  ;; NO_TNH-NEXT:  )
  ;; NO_TNH-NEXT:  (local.get $temp)
  ;; NO_TNH-NEXT: )
  (func $no-optimize-past-return (result i32)
    (local $temp i32)
    ;; As above, but now the thing in the middle may transfer control flow. We
    ;; can in principle optimize here (moving a trap to possibly not happen
    ;; later is fine, in TNH mode), but SimplifyLocals only works in a single
    ;; basic block so we don't atm.
    (local.set $temp
      (i32.load
        (i32.const 0)
      )
    )
    (if
      (i32.const 0)
      (then
        (return
          (i32.const 1)
        )
      )
    )
    (local.get $temp)
  )
)