diff options
-rw-r--r-- | tools/js-optimizer.js | 6 | ||||
-rw-r--r-- | tools/test-js-optimizer-t2-output.js | 12 | ||||
-rw-r--r-- | tools/test-js-optimizer-t2.js | 10 |
3 files changed, 25 insertions, 3 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 5bf88a33..a317543d 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -149,7 +149,7 @@ function emptyNode() { // Passes // Dump the AST. Useful for debugging. For example, -// echo "HEAP[(a+b+c)>>2]" | node tools/js-optimizer.js dump +// echo "HEAP[(a+b+c)>>2]" | node tools/js-optimizer.js dumpAst function dumpAst(ast) { printErr(JSON.stringify(ast)); } @@ -354,6 +354,7 @@ function simplifyExpressionsPre(ast) { // HEAP[x >> 2] // very often. We can in some cases do the shift on the variable itself when it is set, // to greatly reduce the number of shift operations. +// XXX x << 24 >> 24 - are we breaking that? only optimize small shifts! function optimizeShifts(ast) { traverseGeneratedFunctions(ast, function(fun) { var funMore = true; @@ -508,7 +509,8 @@ function optimizeShifts(ast) { }); traverse(fun, function(node, type, stack) { // replace name with unshifted name, making everything valid again by balancing the assign changes stack.push(node); - if (node[0] == 'name' && !node[2] && vars[node[1]] && vars[node[1]].primaryShift >= 0 && stack[stack.length-2][0] != 'assign') { + if (node[0] == 'name' && !node[2] && vars[node[1]] && vars[node[1]].primaryShift >= 0 && + (stack[stack.length-2][0] != 'assign' || stack[stack.length-2][2] != node)) { // ignore changing VAR in |VAR = something| node[2] = true; return ['binary', '<<', node, ['num', vars[node[1]].primaryShift]]; } diff --git a/tools/test-js-optimizer-t2-output.js b/tools/test-js-optimizer-t2-output.js index ea4e903e..898d6633 100644 --- a/tools/test-js-optimizer-t2-output.js +++ b/tools/test-js-optimizer-t2-output.js @@ -41,7 +41,7 @@ function shifty($id) { q(HEAP32[($level << 1) + _dwt_norms_real + $orient * 20 + 2]); pause(3); var $wavelet38 = get(38) >> 2; - $k = $a_addr; + $k = $a_addr << 2; q(HEAPF32[(HEAP32[$wavelet38] >> 2) + ($k << 2) + 2]); q(HEAPF32[(HEAP32[$wavelet38] >> 2) + ($k << 2) + 3]); q(HEAPF32[(HEAP32[$wavelet38] >> 2) + ($k << 2) + 100]); @@ -60,5 +60,15 @@ function shifty($id) { q($idx << 3); q(1 << $idx << 1); print(INDENT + "Entering: _main" + "hi"); + pause(7); + var $tp = get("tp") >> 2; + q($tp); + q($tp); + q($tp); + HEAP32[$H400] = $tp << 2; + HEAP32[$tp << 2] = 5; + HEAP32[$tp] = 5; + HEAP32[HEAP[$tp]] = 5; + HEAP32[HEAP[$tp] >> 2] = 5; } // EMSCRIPTEN_GENERATED_FUNCTIONS: ["shifty"] diff --git a/tools/test-js-optimizer-t2.js b/tools/test-js-optimizer-t2.js index 18673bc7..3afdbc3d 100644 --- a/tools/test-js-optimizer-t2.js +++ b/tools/test-js-optimizer-t2.js @@ -68,5 +68,15 @@ function shifty($id) { q($idx << 1 << 2); q(1 << $idx << 1); // Do not turn this into the slower 1 << $idx + 1 (which is identical though) print(INDENT + "Entering: _main" + "hi"); // this order should not be modified + pause(7); + var $tp = get('tp'); + q($tp >> 2); + q($tp >> 2); + q($tp >> 2); + HEAP32[$H400] = $tp; + HEAP32[$tp] = 5; + HEAP32[$tp >> 2] = 5; + HEAP32[HEAP[$tp >> 2]] = 5; + HEAP32[HEAP[$tp >> 2] >> 2] = 5; } // EMSCRIPTEN_GENERATED_FUNCTIONS: ["shifty"] |