diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 18:24:29 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 18:24:29 -0800 |
commit | d7c3e10b670e35866b6a50865a0baad225280aeb (patch) | |
tree | ae67ec5eeb2c07ce44031f3d0006b7a1098f1c9f /tools/js-optimizer.js | |
parent | 4c4caded645576f4cfe2c9088eaba09b6d731f90 (diff) |
optimize |,& on constants
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 446ca723..ed9aa46d 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -419,22 +419,26 @@ function simplifyExpressionsPre(ast, asm) { while (rerun) { rerun = false; traverseGenerated(ast, function process(node, type, stack) { - if (type == 'binary' && node[1] == '|' && (jsonCompare(node[2], ZERO) || jsonCompare(node[3], ZERO))) { - // We might be able to remove this correction - for (var i = stack.length-1; i >= 0; i--) { - if (stack[i] == 1) { - // we will replace ourselves with the non-zero side. Recursively process that node. - var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other; - // Great, we can eliminate - rerun = true; - while (other = process(result, result[0], stack)) { - result = other; + if (type == 'binary' && node[1] == '|') { + if (node[2][0] == 'num' && node[3][0] == 'num') { + return ['num', node[2][1] | node[3][1]]; + } else if (jsonCompare(node[2], ZERO) || jsonCompare(node[3], ZERO)) { + // We might be able to remove this correction + for (var i = stack.length-1; i >= 0; i--) { + if (stack[i] == 1) { + // we will replace ourselves with the non-zero side. Recursively process that node. + var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other; + // Great, we can eliminate + rerun = true; + while (other = process(result, result[0], stack)) { + result = other; + } + return result; + } else if (stack[i] == -1) { + break; // Too bad, we can't + } else if (asm) { + break; // we must keep a coercion right on top of a heap access in asm mode } - return result; - } else if (stack[i] == -1) { - break; // Too bad, we can't - } else if (asm) { - break; // we must keep a coercion right on top of a heap access in asm mode } } stack.push(1); // From here on up, no need for this kind of correction, it's done at the top @@ -452,6 +456,7 @@ function simplifyExpressionsPre(ast, asm) { // &-related optimizations traverseGenerated(ast, function(node, type) { if (type == 'binary' && node[1] == '&' && node[3][0] == 'num') { + if (node[2][0] == 'num') return ['num', node[2][1] & node[3][1]]; var input = node[2]; var amount = node[3][1]; if (input[0] == 'binary' && input[1] == '&' && input[3][0] == 'num') { |