diff options
-rw-r--r-- | tools/js-optimizer.js | 12 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre-output.js | 2 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre.js | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 834c99e3..48ab5a1f 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -540,12 +540,20 @@ function simplifyExpressionsPre(ast) { }); } - function addFinalReturns(ast) { + function asmOpts(ast) { + // 1. Add final returns when necessary + // 2. Remove unneeded coercions on function calls that have no targets (eliminator removed it) traverseGeneratedFunctions(ast, function(fun) { var returnType = null; traverse(fun, function(node, type) { if (type == 'return' && node[1]) { returnType = detectAsmCoercion(node[1]); + } else if (type == 'stat') { + var inner = node[1]; + if ((inner[0] == 'binary' && inner[1] in ASSOCIATIVE_BINARIES && inner[2][0] == 'call' && inner[3][0] == 'num') || + (inner[0] == 'unary-prefix' && inner[1] == '+' && inner[2][0] == 'call')) { + node[1] = inner[2]; + } } }); // Add a final return if one is missing. @@ -564,7 +572,7 @@ function simplifyExpressionsPre(ast) { simplifyBitops(ast); joinAdditions(ast); // simplifyZeroComp(ast); TODO: investigate performance - if (asm) addFinalReturns(ast); + if (asm) asmOpts(ast); } // In typed arrays mode 2, we can have diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js index 3437163e..745873f8 100644 --- a/tools/test-js-optimizer-asm-pre-output.js +++ b/tools/test-js-optimizer-asm-pre-output.js @@ -6,6 +6,8 @@ function a() { f(8); HEAP[1024] = 5; HEAP[1024] = 5; + whee(12, 13); + whee(12, 13); } function b($this, $__n) { $this = $this | 0; diff --git a/tools/test-js-optimizer-asm-pre.js b/tools/test-js-optimizer-asm-pre.js index 42eb435a..36fe245a 100644 --- a/tools/test-js-optimizer-asm-pre.js +++ b/tools/test-js-optimizer-asm-pre.js @@ -6,6 +6,8 @@ function a() { f(347 & 12); HEAP[4096 >> 2] = 5; HEAP[(4096 & 8191) >> 2] = 5; + whee(12, 13) | 0; + +whee(12, 13); } function b($this, $__n) { $this = $this | 0; |