Skip to content

Commit 2666c47

Browse files
committed
simplify some parts
1 parent 1c495c3 commit 2666c47

27 files changed

+961
-916
lines changed

src/module.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,13 +1546,12 @@ export class Module {
15461546
// passes.push("post-assemblyscript");
15471547
// }
15481548
passes.push("optimize-instructions");
1549+
passes.push("remove-unused-brs");
1550+
passes.push("remove-unused-names");
15491551
if (optimizeLevel >= 3 || shrinkLevel >= 1) {
15501552
passes.push("dce");
15511553
passes.push("inlining");
15521554
}
1553-
passes.push("remove-unused-brs");
1554-
passes.push("remove-unused-names");
1555-
passes.push("inlining-optimizing");
15561555
if (optimizeLevel >= 3 || shrinkLevel >= 2) {
15571556
passes.push("precompute-propagate");
15581557
} else {
@@ -1656,7 +1655,7 @@ export class Module {
16561655
passes.push("simplify-locals");
16571656
passes.push("vacuum");
16581657

1659-
passes.push("inlining-optimizing");
1658+
passes.push("inlining");
16601659
passes.push("precompute-propagate");
16611660
passes.push("vacuum");
16621661

tests/compiler/assert-nonnull.optimized.wat

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,16 @@
136136
local.get $0
137137
)
138138
(func $assert-nonnull/testAll (param $0 i32) (result i32)
139-
(local $1 i32)
140139
block $folding-inner0
141140
local.get $0
142141
i32.eqz
143142
br_if $folding-inner0
144143
local.get $0
145144
call $~lib/array/Array<assert-nonnull/Foo|null>#__get
146145
local.tee $0
147-
local.get $0
148146
i32.eqz
149147
br_if $folding-inner0
148+
local.get $0
150149
i32.load
151150
local.tee $0
152151
i32.eqz
@@ -162,17 +161,16 @@
162161
unreachable
163162
)
164163
(func $assert-nonnull/testAll2 (param $0 i32) (result i32)
165-
(local $1 i32)
166164
block $folding-inner0
167165
local.get $0
168166
i32.eqz
169167
br_if $folding-inner0
170168
local.get $0
171169
call $~lib/array/Array<assert-nonnull/Foo|null>#__get
172170
local.tee $0
173-
local.get $0
174171
i32.eqz
175172
br_if $folding-inner0
173+
local.get $0
176174
i32.load
177175
local.tee $0
178176
i32.eqz
@@ -208,12 +206,10 @@
208206
call_indirect (type $none_=>_i32)
209207
)
210208
(func $assert-nonnull/testRet (param $0 i32) (result i32)
211-
(local $1 i32)
212209
local.get $0
213210
i32.load
214211
call_indirect (type $none_=>_i32)
215-
local.tee $1
216-
local.get $1
212+
local.tee $0
217213
i32.eqz
218214
if
219215
i32.const 1040
@@ -223,6 +219,7 @@
223219
call $~lib/builtins/abort
224220
unreachable
225221
end
222+
local.get $0
226223
)
227224
(func $assert-nonnull/testObjFn (param $0 i32) (result i32)
228225
local.get $0
@@ -231,13 +228,11 @@
231228
call_indirect (type $none_=>_i32)
232229
)
233230
(func $assert-nonnull/testObjRet (param $0 i32) (result i32)
234-
(local $1 i32)
235231
local.get $0
236232
i32.load offset=4
237233
i32.load
238234
call_indirect (type $none_=>_i32)
239-
local.tee $1
240-
local.get $1
235+
local.tee $0
241236
i32.eqz
242237
if
243238
i32.const 1040
@@ -247,5 +242,6 @@
247242
call $~lib/builtins/abort
248243
unreachable
249244
end
245+
local.get $0
250246
)
251247
)

tests/compiler/builtins.optimized.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@
107107
local.set $2
108108
local.get $3
109109
if
110-
local.get $0
110+
local.get $1
111111
i32.load16_u
112112
local.tee $3
113-
local.get $1
113+
local.get $0
114114
i32.load16_u
115115
local.tee $4
116116
i32.ne
117117
if
118-
local.get $3
119118
local.get $4
119+
local.get $3
120120
i32.sub
121121
return
122122
end

tests/compiler/class-overloading.optimized.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@
163163
local.set $2
164164
local.get $3
165165
if
166-
local.get $0
166+
local.get $1
167167
i32.load16_u
168168
local.tee $3
169-
local.get $1
169+
local.get $0
170170
i32.load16_u
171171
local.tee $4
172172
i32.ne
173173
if
174-
local.get $3
175174
local.get $4
175+
local.get $3
176176
i32.sub
177177
return
178178
end

tests/compiler/class.optimized.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@
140140
i32.const 0
141141
i32.const 0
142142
call $~lib/rt/stub/__alloc
143-
local.set $1
143+
local.tee $1
144144
local.get $0
145145
i32.load
146+
i32.ne
146147
drop
147148
local.get $0
148149
local.get $1

tests/compiler/field-initialization.optimized.wat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@
193193
local.set $2
194194
local.get $3
195195
if
196-
local.get $0
196+
local.get $1
197197
i32.load16_u
198198
local.tee $3
199-
local.get $1
199+
local.get $0
200200
i32.load16_u
201201
local.tee $4
202202
i32.ne
203203
if
204-
local.get $3
205204
local.get $4
205+
local.get $3
206206
i32.sub
207207
return
208208
end

tests/compiler/function-expression.optimized.wat

Lines changed: 87 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
(data (i32.const 1600) "\08\00\00\00\01\00\00\00\07\00\00\00\08\00\00\00\11")
2727
(table $0 18 funcref)
2828
(elem (i32.const 1) $start:function-expression~anonymous|0 $start:function-expression~anonymous|0 $start:function-expression~someName $start:function-expression~anonymous|2 $start:function-expression~anonymous|3 $start:function-expression~anonymous|4 $start:function-expression~anonymous|5 $start:function-expression~anonymous|3 $start:function-expression~anonymous|4 $start:function-expression~anonymous|5 $start:function-expression~anonymous|2 $function-expression/testGlobal~anonymous|0~anonymous|0 $function-expression/testGlobal~anonymous|0 $function-expression/testGlobal~anonymous|0~anonymous|0 $function-expression/testLocal~anonymous|0 $function-expression/testGlobal~anonymous|0~anonymous|0 $function-expression/testField~anonymous|0)
29+
(global $~lib/rt/stub/offset (mut i32) (i32.const 0))
2930
(export "memory" (memory $0))
3031
(start $~start)
3132
(func $start:function-expression~anonymous|0 (param $0 i32) (result i32)
@@ -69,9 +70,92 @@
6970
(func $function-expression/testField~anonymous|0 (result i32)
7071
i32.const 1584
7172
)
72-
(func $start:function-expression
73+
(func $function-expression/testField
7374
(local $0 i32)
7475
(local $1 i32)
76+
(local $2 i32)
77+
(local $3 i32)
78+
global.get $~lib/rt/stub/offset
79+
i32.const 16
80+
i32.add
81+
local.tee $2
82+
i32.const 16
83+
i32.add
84+
local.tee $0
85+
memory.size
86+
local.tee $3
87+
i32.const 16
88+
i32.shl
89+
local.tee $1
90+
i32.gt_u
91+
if
92+
local.get $3
93+
local.get $0
94+
local.get $1
95+
i32.sub
96+
i32.const 65535
97+
i32.add
98+
i32.const -65536
99+
i32.and
100+
i32.const 16
101+
i32.shr_u
102+
local.tee $1
103+
local.get $3
104+
local.get $1
105+
i32.gt_s
106+
select
107+
memory.grow
108+
i32.const 0
109+
i32.lt_s
110+
if
111+
local.get $1
112+
memory.grow
113+
i32.const 0
114+
i32.lt_s
115+
if
116+
unreachable
117+
end
118+
end
119+
end
120+
local.get $0
121+
global.set $~lib/rt/stub/offset
122+
local.get $2
123+
i32.const 16
124+
i32.sub
125+
local.tee $0
126+
i32.const 16
127+
i32.store
128+
local.get $0
129+
i32.const 1
130+
i32.store offset=4
131+
local.get $0
132+
i32.const 8
133+
i32.store offset=8
134+
local.get $0
135+
i32.const 4
136+
i32.store offset=12
137+
local.get $2
138+
i32.const 1616
139+
i32.store
140+
i32.const 1
141+
local.get $2
142+
i32.load
143+
i32.load
144+
call_indirect (type $none_=>_i32)
145+
i32.load
146+
call_indirect (type $i32_=>_i32)
147+
i32.const 25
148+
i32.ne
149+
if
150+
i32.const 0
151+
i32.const 1072
152+
i32.const 82
153+
i32.const 3
154+
call $~lib/builtins/abort
155+
unreachable
156+
end
157+
)
158+
(func $start:function-expression
75159
i32.const 1
76160
i32.const 1040
77161
i32.load
@@ -229,72 +313,9 @@
229313
call $~lib/builtins/abort
230314
unreachable
231315
end
232-
i32.const 1664
233-
memory.size
234-
local.tee $1
235-
i32.const 16
236-
i32.shl
237-
local.tee $0
238-
i32.gt_u
239-
if
240-
local.get $1
241-
i32.const 67199
242-
local.get $0
243-
i32.sub
244-
i32.const -65536
245-
i32.and
246-
i32.const 16
247-
i32.shr_u
248-
local.tee $0
249-
local.get $1
250-
local.get $0
251-
i32.gt_s
252-
select
253-
memory.grow
254-
i32.const 0
255-
i32.lt_s
256-
if
257-
local.get $0
258-
memory.grow
259-
i32.const 0
260-
i32.lt_s
261-
if
262-
unreachable
263-
end
264-
end
265-
end
266316
i32.const 1632
267-
i32.const 16
268-
i32.store
269-
i32.const 1636
270-
i32.const 1
271-
i32.store
272-
i32.const 1640
273-
i32.const 8
274-
i32.store
275-
i32.const 1644
276-
i32.const 4
277-
i32.store
278-
i32.const 1648
279-
i32.const 1616
280-
i32.store
281-
i32.const 1
282-
i32.const 1648
283-
i32.load
284-
i32.load
285-
call_indirect (type $none_=>_i32)
286-
i32.load
287-
call_indirect (type $i32_=>_i32)
288-
i32.const 25
289-
i32.ne
290-
if
291-
i32.const 0
292-
i32.const 1072
293-
i32.const 82
294-
i32.const 3
295-
call $~lib/builtins/abort
296-
unreachable
297-
end
317+
global.set $~lib/rt/stub/offset
318+
call $function-expression/testField
298319
)
299320
(func $~start
300321
call $start:function-expression

0 commit comments

Comments
 (0)