Skip to content

Commit 3d48e55

Browse files
committed
Reduce number of unreachable instructions
1 parent 2dbfcb3 commit 3d48e55

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed

src/compiler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9230,7 +9230,7 @@ export class Compiler extends DiagnosticEmitter {
92309230
const getArg = (i: i32): ExpressionRef => module.local_get(i, Type.i32.toNativeType());
92319231
// Condition to switch on
92329232
const first = relooper.addBlockWithSwitch(module.nop(), getArg(0));
9233-
const zero = relooper.addBlock(module.drop(module.i32(0)));
9233+
const zero = relooper.addBlock(module.nop());
92349234

92359235
for (let index: i32 = 0; index < iFuncs.length; index++) {
92369236
const [funcID, classes] = iFuncs[index];
@@ -9246,15 +9246,15 @@ export class Compiler extends DiagnosticEmitter {
92469246
const condition = module.binary(BinaryOp.EqI32, getArg(1), module.i32(classID));
92479247
relooper.addBranch(innerBlock, methodCase, condition);
92489248
}
9249-
relooper.addBranch(innerBlock, zero, 0, module.unreachable());
9249+
relooper.addBranch(innerBlock, zero);
92509250
}
9251-
relooper.addBranchForSwitch(first, zero, [], module.unreachable());
9251+
relooper.addBranchForSwitch(first, zero, []);
92529252

92539253
var typeRef = this.ensureFunctionType([Type.u32, Type.u32], Type.u32, null);
92549254

92559255
const body = module.block(
92569256
null,
9257-
[relooper.renderAndDispose(first, 0), module.i32(0)],
9257+
[relooper.renderAndDispose(first, 0), module.unreachable(), module.i32(0)],
92589258
Type.u32.toNativeType()
92599259
);
92609260
const hardCoded = this.module.i32(1);

tests/compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ tests.forEach(filename => {
135135
var cmd = [
136136
filename,
137137
"--baseDir", basedir,
138-
// "--validate",
138+
"--validate",
139139
"--measure",
140140
"--debug",
141141
"--textFile" // -> stdout

tests/compiler/interface.optimized.wat

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@
163163
i32.add
164164
)
165165
(func $~virtual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32)
166-
block $switch$1$default
166+
block $block$2$break
167167
block $switch$1$case$6
168168
block $switch$1$case$3
169169
local.get $0
170-
br_table $switch$1$case$3 $switch$1$case$6 $switch$1$default
170+
br_table $switch$1$case$3 $switch$1$case$6 $block$2$break
171171
end
172172
local.get $1
173173
i32.const 3
@@ -178,14 +178,10 @@
178178
else
179179
local.get $1
180180
i32.const 4
181-
i32.eq
182-
if
183-
i32.const 2
184-
return
185-
else
186-
unreachable
187-
end
188-
unreachable
181+
i32.ne
182+
br_if $block$2$break
183+
i32.const 2
184+
return
189185
end
190186
unreachable
191187
end
@@ -202,12 +198,8 @@
202198
if
203199
i32.const 4
204200
return
205-
else
206-
unreachable
207201
end
208-
unreachable
209202
end
210-
unreachable
211203
end
212204
unreachable
213205
)

tests/compiler/interface.untouched.wat

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
i32.const 2
289289
return
290290
else
291-
unreachable
291+
br $block$2$break
292292
end
293293
unreachable
294294
end
@@ -308,17 +308,15 @@
308308
i32.const 4
309309
return
310310
else
311-
unreachable
311+
br $block$2$break
312312
end
313313
unreachable
314314
end
315315
unreachable
316316
end
317-
unreachable
317+
br $block$2$break
318318
end
319-
i32.const 0
320-
drop
321-
i32.const 0
319+
unreachable
322320
)
323321
(func $null (; 17 ;) (type $FUNCSIG$v)
324322
)

0 commit comments

Comments
 (0)