summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm2js.cpp20
-rw-r--r--src/wasm2js.h2
2 files changed, 19 insertions, 3 deletions
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp
index 7ceb63ffc..611b00803 100644
--- a/src/tools/wasm2js.cpp
+++ b/src/tools/wasm2js.cpp
@@ -189,6 +189,10 @@ static void optimizeJS(Ref ast) {
auto getHeapFromAccess = [](Ref node) { return node[1]->getIString(); };
+ auto setHeapOnAccess = [](Ref node, IString heap) {
+ node[1] = ValueBuilder::makeName(heap);
+ };
+
auto isIntegerHeap = [](IString heap) {
return heap == HEAP8 || heap == HEAPU8 || heap == HEAP16 ||
heap == HEAPU16 || heap == HEAP32 || heap == HEAPU32;
@@ -236,6 +240,21 @@ static void optimizeJS(Ref ast) {
else if (isBitwise(node)) {
node[2] = removeOrZero(node[2]);
node[3] = removeOrZero(node[3]);
+ // A load into an & may allow using a simpler heap, e.g. HEAPU8[..] & 1
+ // (a load of a boolean) may be HEAP8[..] & 1. The signed heaps are more
+ // commonly used, so it compresses better, and also they seem to have
+ // better performance (perhaps since HEAPU32 is at risk of not being a
+ // smallint).
+ if (node[1] == AND && isHeapAccess(node[2])) {
+ auto heap = getHeapFromAccess(node[2]);
+ if (isConstantAnd(node, 1)) {
+ if (heap == HEAPU8) {
+ setHeapOnAccess(node[2], HEAP8);
+ } else if (heap == HEAPU16) {
+ setHeapOnAccess(node[2], HEAP16);
+ }
+ }
+ }
}
// +(+x) => +x
else if (isPlus(node)) {
@@ -280,7 +299,6 @@ static void optimizeJS(Ref ast) {
// Remove unnecessary break/continue labels, when referring to the top level.
- // XXX IString invalid("__wasm2js$INVALID_LABEL__");
std::vector<Ref> breakCapturers;
std::vector<Ref> continueCapturers;
std::unordered_map<IString, Ref>
diff --git a/src/wasm2js.h b/src/wasm2js.h
index e721d3d58..30d694f78 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -420,7 +420,6 @@ void Wasm2JSBuilder::addBasics(Ref ast) {
addHeap(HEAP32, INT32ARRAY);
addHeap(HEAPU8, UINT8ARRAY);
addHeap(HEAPU16, UINT16ARRAY);
- addHeap(HEAPU32, UINT32ARRAY);
addHeap(HEAPF32, FLOAT32ARRAY);
addHeap(HEAPF64, FLOAT64ARRAY);
// core asm.js imports
@@ -1687,7 +1686,6 @@ void Wasm2JSBuilder::addMemoryGrowthFuncs(Ref ast, Module* wasm) {
setHeap(HEAP32, INT32ARRAY);
setHeap(HEAPU8, UINT8ARRAY);
setHeap(HEAPU16, UINT16ARRAY);
- setHeap(HEAPU32, UINT32ARRAY);
setHeap(HEAPF32, FLOAT32ARRAY);
setHeap(HEAPF64, FLOAT64ARRAY);