diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 16:41:44 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 16:43:52 -0800 |
commit | 78dbafb289e222550abda6b53e7099352a599804 (patch) | |
tree | bac704182dd01dc3d78bf0f1ca6064f78b1d7786 /tools/js-optimizer.js | |
parent | 0779c55c28f17d796f3f13962cfcac954e6cef59 (diff) |
keep a coercion right on top of heap accesses in asm mode
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 22d0f4d1..7fe8d99f 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -404,7 +404,7 @@ function removeUnneededLabelSettings(ast) { // Various expression simplifications. Pre run before closure (where we still have metadata), Post run after. -function simplifyExpressionsPre(ast) { +function simplifyExpressionsPre(ast, asm) { // When there is a bunch of math like (((8+5)|0)+12)|0, only the external |0 is needed, one correction is enough. // At each node, ((X|0)+Y)|0 can be transformed into (X+Y): The inner corrections are not needed // TODO: Is the same is true for 0xff, 0xffff? @@ -423,10 +423,11 @@ function simplifyExpressionsPre(ast) { // We might be able to remove this correction for (var i = stack.length-1; i >= 0; i--) { if (stack[i] == 1) { - // Great, we can eliminate - rerun = true; // we will replace ourselves with the non-zero side. Recursively process that node. var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other; + if (asm && result[0] == 'sub') break; // we must keep a coercion right on top of a heap access in asm mode + // Great, we can eliminate + rerun = true; while (other = process(result, result[0], stack)) { result = other; } @@ -522,6 +523,10 @@ function simplifyExpressionsPre(ast) { // simplifyZeroComp(ast); TODO: investigate performance } +function simplifyExpressionsPreAsm(ast) { + simplifyExpressionsPre(ast, true); +} + // In typed arrays mode 2, we can have // HEAP[x >> 2] // very often. We can in some cases do the shift on the variable itself when it is set, @@ -2134,6 +2139,7 @@ var passes = { removeAssignsToUndefined: removeAssignsToUndefined, //removeUnneededLabelSettings: removeUnneededLabelSettings, simplifyExpressionsPre: simplifyExpressionsPre, + simplifyExpressionsPreAsm: simplifyExpressionsPreAsm, optimizeShiftsConservative: optimizeShiftsConservative, optimizeShiftsAggressive: optimizeShiftsAggressive, simplifyExpressionsPost: simplifyExpressionsPost, |