summaryrefslogtreecommitdiff
path: root/test/passes/precompute-propagate.wast
blob: 5cdc720ba4a034a13d8530c6b6ead68323f40e31 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
(module
  (func $basic (param $p i32)
    (local $x i32)
    (set_local $x (i32.const 10))
    (call $basic (i32.add (get_local $x) (get_local $x)))
  )
  (func $split (param $p i32)
    (local $x i32)
    (if (i32.const 1)
      (set_local $x (i32.const 10))
    )
    (call $basic (i32.add (get_local $x) (get_local $x)))
  )
  (func $split-but-join (param $p i32)
    (local $x i32)
    (if (i32.const 1)
      (set_local $x (i32.const 10))
      (set_local $x (i32.const 10))
    )
    (call $basic (i32.add (get_local $x) (get_local $x)))
  )
  (func $split-but-join-different (param $p i32)
    (local $x i32)
    (if (i32.const 1)
      (set_local $x (i32.const 10))
      (set_local $x (i32.const 20))
    )
    (call $basic (i32.add (get_local $x) (get_local $x)))
  )
  (func $split-but-join-different-b (param $p i32)
    (local $x i32)
    (if (i32.const 1)
      (set_local $x (i32.const 10))
      (set_local $x (get_local $p))
    )
    (call $basic (i32.add (get_local $x) (get_local $x)))
  )
  (func $split-but-join-init0 (param $p i32)
    (local $x i32)
    (if (i32.const 1)
      (set_local $x (i32.const 0))
    )
    (call $basic (i32.add (get_local $x) (get_local $x)))
  )
  (func $later (param $p i32)
    (local $x i32)
    (set_local $x (i32.const 10))
    (call $basic (i32.add (get_local $x) (get_local $x)))
    (set_local $x (i32.const 22))
    (call $basic (i32.add (get_local $x) (get_local $x)))
    (set_local $x (i32.const 39))
  )
  (func $later2 (param $p i32) (result i32)
    (local $x i32)
    (set_local $x (i32.const 10))
    (set_local $x (i32.add (get_local $x) (get_local $x)))
    (get_local $x)
  )
  (func $two-ways-but-identical (param $p i32) (result i32)
    (local $x i32)
    (local $y i32)
    (set_local $x (i32.const 10))
    (if (i32.const 1)
      (set_local $y (i32.const 11))
      (set_local $y (i32.add (get_local $x) (i32.const 1)))
    )
    (set_local $y (i32.add (get_local $x) (get_local $y)))
    (get_local $y)
  )
  (func $two-ways-but-almost-identical (param $p i32) (result i32)
    (local $x i32)
    (local $y i32)
    (set_local $x (i32.const 10))
    (if (i32.const 1)
      (set_local $y (i32.const 12)) ;; 12, not 11...
      (set_local $y (i32.add (get_local $x) (i32.const 1)))
    )
    (set_local $y (i32.add (get_local $x) (get_local $y)))
    (get_local $y)
  )
  (func $deadloop (param $p i32) (result i32)
    (local $x i32)
    (local $y i32)
    (loop $loop ;; we look like we depend on the other, but we don't actually
      (set_local $x (if (result i32) (i32.const 1) (i32.const 0) (get_local $y)))
      (set_local $y (if (result i32) (i32.const 1) (i32.const 0) (get_local $x)))
      (br $loop)
    )
  )
  (func $deadloop2 (param $p i32)
    (local $x i32)
    (local $y i32)
    (loop $loop ;; we look like we depend on the other, but we don't actually
      (set_local $x (if (result i32) (i32.const 1) (i32.const 0) (get_local $y)))
      (set_local $y (if (result i32) (i32.const 1) (i32.const 0) (get_local $x)))
      (call $deadloop2 (get_local $x))
      (call $deadloop2 (get_local $y))
      (br $loop)
    )
  )
  (func $deadloop3 (param $p i32)
    (local $x i32)
    (local $y i32)
    (loop $loop ;; we look like we depend on the other, but we don't actually
      (set_local $x (if (result i32) (i32.const 1) (i32.const 0) (get_local $x)))
      (set_local $y (if (result i32) (i32.const 1) (i32.const 0) (get_local $y)))
      (call $deadloop2 (get_local $x))
      (call $deadloop2 (get_local $y))
      (br $loop)
    )
  )
  (func $through-tee (param $x i32) (param $y i32) (result i32)
    (set_local $x
      (tee_local $y
        (i32.const 7)
      )
    )
    (return
      (i32.add
        (get_local $x)
        (get_local $y)
      )
    )
  )
  (func $through-tee-more (param $x i32) (param $y i32) (result i32)
    (set_local $x
      (i32.eqz
        (tee_local $y
          (i32.const 7)
        )
      )
    )
    (return
      (i32.add
        (get_local $x)
        (get_local $y)
      )
    )
  )
  (func $multipass (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
   (local $3 i32)
   (if
    (get_local $3)
    (set_local $3 ;; this set is completely removed, allowing later opts
     (i32.const 24)
    )
   )
   (if
    (get_local $3)
    (set_local $2
     (i32.const 0)
    )
   )
   (get_local $2)
  )
)