Skip to content

Commit 528fc7d

Browse files
surmaMaxGraey
andcommitted
Use Eqz instead
Co-authored-by: Max Graey <[email protected]>
1 parent 8ec6c96 commit 528fc7d

File tree

2 files changed

+24
-46
lines changed

2 files changed

+24
-46
lines changed

src/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9944,8 +9944,8 @@ export class Compiler extends DiagnosticEmitter {
99449944
// Needs to be true when the ref is _not_ null.
99459945
// Therefore: 1 - <ref.is_null>
99469946
return type.size == 64
9947-
? module.binary(BinaryOp.SubI64, module.i64(1), module.ref_is(RefIsOp.RefIsNull, expr))
9948-
: module.binary(BinaryOp.SubI32, module.i32(1), module.ref_is(RefIsOp.RefIsNull, expr));
9947+
? module.unary(UnaryOp.EqzI64, module.ref_is(RefIsOp.RefIsNull, expr))
9948+
: module.unary(UnaryOp.EqzI32, module.ref_is(RefIsOp.RefIsNull, expr));
99499949

99509950
}
99519951
default: {

tests/compiler/features/reference-types.untouched.wat

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
(func $features/reference-types/testLocal<funcref>
3838
(local $0 funcref)
3939
(local $1 funcref)
40-
i32.const 1
4140
local.get $0
4241
ref.is_null
43-
i32.sub
42+
i32.eqz
4443
i32.eqz
4544
i32.eqz
4645
if
@@ -53,10 +52,9 @@
5352
end
5453
ref.null func
5554
local.set $0
56-
i32.const 1
5755
local.get $0
5856
ref.is_null
59-
i32.sub
57+
i32.eqz
6058
i32.eqz
6159
i32.eqz
6260
if
@@ -69,10 +67,9 @@
6967
end
7068
ref.null func
7169
local.set $1
72-
i32.const 1
7370
local.get $1
7471
ref.is_null
75-
i32.sub
72+
i32.eqz
7673
i32.eqz
7774
i32.eqz
7875
if
@@ -87,10 +84,9 @@
8784
(func $features/reference-types/testLocal<externref>
8885
(local $0 externref)
8986
(local $1 externref)
90-
i32.const 1
9187
local.get $0
9288
ref.is_null
93-
i32.sub
89+
i32.eqz
9490
i32.eqz
9591
i32.eqz
9692
if
@@ -103,10 +99,9 @@
10399
end
104100
ref.null extern
105101
local.set $0
106-
i32.const 1
107102
local.get $0
108103
ref.is_null
109-
i32.sub
104+
i32.eqz
110105
i32.eqz
111106
i32.eqz
112107
if
@@ -119,10 +114,9 @@
119114
end
120115
ref.null extern
121116
local.set $1
122-
i32.const 1
123117
local.get $1
124118
ref.is_null
125-
i32.sub
119+
i32.eqz
126120
i32.eqz
127121
i32.eqz
128122
if
@@ -137,10 +131,9 @@
137131
(func $features/reference-types/testLocal<anyref>
138132
(local $0 anyref)
139133
(local $1 anyref)
140-
i32.const 1
141134
local.get $0
142135
ref.is_null
143-
i32.sub
136+
i32.eqz
144137
i32.eqz
145138
i32.eqz
146139
if
@@ -153,10 +146,9 @@
153146
end
154147
ref.null any
155148
local.set $0
156-
i32.const 1
157149
local.get $0
158150
ref.is_null
159-
i32.sub
151+
i32.eqz
160152
i32.eqz
161153
i32.eqz
162154
if
@@ -169,10 +161,9 @@
169161
end
170162
ref.null any
171163
local.set $1
172-
i32.const 1
173164
local.get $1
174165
ref.is_null
175-
i32.sub
166+
i32.eqz
176167
i32.eqz
177168
i32.eqz
178169
if
@@ -211,10 +202,9 @@
211202
global.get $features/reference-types/someKey
212203
call $~lib/bindings/Reflect/get
213204
call $~lib/bindings/console/log
214-
i32.const 1
215205
call $features/reference-types/somethingReal
216206
ref.is_null
217-
i32.sub
207+
i32.eqz
218208
i32.eqz
219209
if
220210
i32.const 0
@@ -228,10 +218,9 @@
228218
unreachable
229219
end
230220
end
231-
i32.const 1
232221
call $features/reference-types/somethingNull
233222
ref.is_null
234-
i32.sub
223+
i32.eqz
235224
i32.eqz
236225
if
237226
nop
@@ -247,10 +236,9 @@
247236
unreachable
248237
end
249238
end
250-
i32.const 1
251239
call $features/reference-types/somethingReal
252240
ref.is_null
253-
i32.sub
241+
i32.eqz
254242
if
255243
nop
256244
else
@@ -265,10 +253,9 @@
265253
unreachable
266254
end
267255
end
268-
i32.const 1
269256
call $features/reference-types/somethingNull
270257
ref.is_null
271-
i32.sub
258+
i32.eqz
272259
if
273260
i32.const 0
274261
i32.eqz
@@ -281,10 +268,9 @@
281268
unreachable
282269
end
283270
end
284-
i32.const 1
285271
global.get $features/reference-types/funcGlobal
286272
ref.is_null
287-
i32.sub
273+
i32.eqz
288274
i32.eqz
289275
i32.eqz
290276
if
@@ -297,10 +283,9 @@
297283
end
298284
ref.null func
299285
global.set $features/reference-types/funcGlobal
300-
i32.const 1
301286
global.get $features/reference-types/funcGlobal
302287
ref.is_null
303-
i32.sub
288+
i32.eqz
304289
i32.eqz
305290
i32.eqz
306291
if
@@ -313,10 +298,9 @@
313298
end
314299
ref.null func
315300
global.set $features/reference-types/funcGlobalInit
316-
i32.const 1
317301
global.get $features/reference-types/funcGlobalInit
318302
ref.is_null
319-
i32.sub
303+
i32.eqz
320304
i32.eqz
321305
i32.eqz
322306
if
@@ -327,10 +311,9 @@
327311
call $~lib/builtins/abort
328312
unreachable
329313
end
330-
i32.const 1
331314
global.get $features/reference-types/externGlobal
332315
ref.is_null
333-
i32.sub
316+
i32.eqz
334317
i32.eqz
335318
i32.eqz
336319
if
@@ -343,10 +326,9 @@
343326
end
344327
ref.null extern
345328
global.set $features/reference-types/externGlobal
346-
i32.const 1
347329
global.get $features/reference-types/externGlobal
348330
ref.is_null
349-
i32.sub
331+
i32.eqz
350332
i32.eqz
351333
i32.eqz
352334
if
@@ -359,10 +341,9 @@
359341
end
360342
ref.null extern
361343
global.set $features/reference-types/externGlobalInit
362-
i32.const 1
363344
global.get $features/reference-types/externGlobalInit
364345
ref.is_null
365-
i32.sub
346+
i32.eqz
366347
i32.eqz
367348
i32.eqz
368349
if
@@ -373,10 +354,9 @@
373354
call $~lib/builtins/abort
374355
unreachable
375356
end
376-
i32.const 1
377357
global.get $features/reference-types/anyGlobal
378358
ref.is_null
379-
i32.sub
359+
i32.eqz
380360
i32.eqz
381361
i32.eqz
382362
if
@@ -389,10 +369,9 @@
389369
end
390370
ref.null any
391371
global.set $features/reference-types/anyGlobal
392-
i32.const 1
393372
global.get $features/reference-types/anyGlobal
394373
ref.is_null
395-
i32.sub
374+
i32.eqz
396375
i32.eqz
397376
i32.eqz
398377
if
@@ -405,10 +384,9 @@
405384
end
406385
ref.null any
407386
global.set $features/reference-types/anyGlobalInit
408-
i32.const 1
409387
global.get $features/reference-types/anyGlobalInit
410388
ref.is_null
411-
i32.sub
389+
i32.eqz
412390
i32.eqz
413391
i32.eqz
414392
if

0 commit comments

Comments
 (0)