aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-07-08 17:02:27 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-08 17:02:27 -0700
commitd24631b99e37c863f853f2e8706e9114df5b51ee (patch)
treec1b2c6fae18ee567c08ef4d540debf5acfed3fb9 /tools/js-optimizer.js
parent94dfbf75aa9813432a60e6832f34f26e8b763512 (diff)
parent208893daffc8aab7a1a8e75fbd10cd5144b569c4 (diff)
Merge branch 'incoming' of github.com:kripken/emscripten into incoming
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index a5075910..22769bb4 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -405,7 +405,7 @@ function removeUnneededLabelSettings(ast) {
// Various expression simplifications. Pre run before closure (where we still have metadata), Post run after.
var USEFUL_BINARY_OPS = set('<<', '>>', '|', '&', '^');
-var COMPARE_OPS = set('<', '<=', '>', '>=', '==', '===', '!=');
+var COMPARE_OPS = set('<', '<=', '>', '>=', '==', '===', '!=', '!==');
function simplifyExpressionsPre(ast) {
// Simplify common expressions used to perform integer conversion operations
@@ -504,6 +504,8 @@ function simplifyExpressionsPre(ast) {
stack.push(1);
} else if ((type === 'binary' && node[1] in SAFE_BINARY_OPS) || type === 'num' || type === 'name') {
stack.push(0); // This node is safe in that it does not interfere with this optimization
+ } else if (type === 'unary-prefix' && node[1] === '~') {
+ stack.push(1);
} else {
stack.push(-1); // This node is dangerous! Give up if you see this before you see '1'
}
@@ -554,6 +556,12 @@ function simplifyExpressionsPre(ast) {
}
}
}
+ } else if (type === 'binary' && node[1] === '^') {
+ // LLVM represents bitwise not as xor with -1. Translate it back to an actual bitwise not.
+ if (node[3][0] === 'unary-prefix' && node[3][1] === '-' && node[3][2][0] === 'num' &&
+ node[3][2][1] === 1) {
+ return ['unary-prefix', '~', node[2]];
+ }
} else if (type === 'binary' && node[1] === '>>' && node[3][0] === 'num' &&
node[2][0] === 'binary' && node[2][1] === '<<' && node[2][3][0] === 'num' &&
node[2][2][0] === 'sub' && node[2][2][1][0] === 'name') {