summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-04-25 10:35:22 -0700
committerGitHub <noreply@github.com>2019-04-25 10:35:22 -0700
commitef6020cd5fbf9af61e7fdc17a5c787fc733f793d (patch)
tree4fa531d168f304f050c73abb549a3de079f8a05d /src
parent09945884f7461135286357d14f993f9b5c5a329b (diff)
downloadbinaryen-ef6020cd5fbf9af61e7fdc17a5c787fc733f793d.tar.gz
binaryen-ef6020cd5fbf9af61e7fdc17a5c787fc733f793d.tar.bz2
binaryen-ef6020cd5fbf9af61e7fdc17a5c787fc733f793d.zip
wasm2js: optimize loops and eqz (#2051)
Diffstat (limited to 'src')
-rw-r--r--src/wasm2js.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h
index 84c65b189..fdfa77b84 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -823,9 +823,14 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func, bool standalo
Ref visitLoop(Loop* curr) {
Name asmLabel = curr->name;
continueLabels.insert(asmLabel);
- Ref body = blockify(visit(curr->body, result));
- flattenAppend(body, ValueBuilder::makeBreak(fromName(asmLabel, NameScope::Label)));
- Ref ret = ValueBuilder::makeDo(body, ValueBuilder::makeInt(1));
+ Ref body = visit(curr->body, result);
+ // if we can reach the end of the block, we must leave the while (1) loop
+ if (curr->body->type != unreachable) {
+ assert(curr->body->type == none); // flat IR
+ body = blockify(body);
+ flattenAppend(body, ValueBuilder::makeBreak(fromName(asmLabel, NameScope::Label)));
+ }
+ Ref ret = ValueBuilder::makeWhile(ValueBuilder::makeInt(1), body);
return ValueBuilder::makeLabel(fromName(asmLabel, NameScope::Label), ret);
}
@@ -1207,10 +1212,8 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func, bool standalo
<< std::endl;
WASM_UNREACHABLE();
case EqZInt32:
- return ValueBuilder::makeBinary(
- makeAsmCoercion(visit(curr->value,
- EXPRESSION_RESULT), ASM_INT), EQ,
- makeAsmCoercion(ValueBuilder::makeInt(0), ASM_INT));
+ // XXX !x does change the type to bool, which is correct, but may be slower?
+ return ValueBuilder::makeUnary(L_NOT, visit(curr->value, EXPRESSION_RESULT));
case ReinterpretFloat32: {
ABI::wasm2js::ensureScratchMemoryHelpers(module, ABI::wasm2js::SCRATCH_STORE_F32);
ABI::wasm2js::ensureScratchMemoryHelpers(module, ABI::wasm2js::SCRATCH_LOAD_I32);