aboutsummaryrefslogtreecommitdiff
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
parent94dfbf75aa9813432a60e6832f34f26e8b763512 (diff)
parent208893daffc8aab7a1a8e75fbd10cd5144b569c4 (diff)
Merge branch 'incoming' of github.com:kripken/emscripten into incoming
-rw-r--r--tools/js-optimizer.js10
-rw-r--r--tools/test-js-optimizer-asm-pre-output.js4
-rw-r--r--tools/test-js-optimizer-asm-pre.js7
3 files changed, 20 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') {
diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js
index 59a42010..b7afab26 100644
--- a/tools/test-js-optimizer-asm-pre-output.js
+++ b/tools/test-js-optimizer-asm-pre-output.js
@@ -63,6 +63,9 @@ function b($this, $__n) {
HEAP32[($this + 4 & 16777215) >> 2] = $40;
}
HEAP8[$38 + $40 & 16777215] = 0;
+ HEAP32[$4] = ~HEAP32[$5];
+ HEAP32[$4] = ~HEAP32[$5];
+ HEAP32[$4] = ~HEAP32[$5];
return;
}
function rett() {
@@ -127,6 +130,7 @@ function compare_result_simplification() {
HEAP32[$4] = HEAP32[$5] == HEAP32[$6];
HEAP32[$4] = HEAP32[$5] === HEAP32[$6];
HEAP32[$4] = HEAP32[$5] != HEAP32[$6];
+ HEAP32[$4] = HEAP32[$5] !== HEAP32[$6];
var x = HEAP32[$5] != HEAP32[$6] | 0;
}
function tempDoublePtr($45, $14, $28, $42) {
diff --git a/tools/test-js-optimizer-asm-pre.js b/tools/test-js-optimizer-asm-pre.js
index 7ca941fa..b762a60e 100644
--- a/tools/test-js-optimizer-asm-pre.js
+++ b/tools/test-js-optimizer-asm-pre.js
@@ -64,6 +64,12 @@ function b($this, $__n) {
HEAP32[(($this + 4 | 0) & 16777215) >> 2] = $40;
}
HEAP8[($38 + $40 | 0) & 16777215] = 0;
+ // Eliminate the |0.
+ HEAP32[$4] = ((~(HEAP32[$5]|0))|0);
+ // Rewrite to ~.
+ HEAP32[$4] = HEAP32[$5]^-1;
+ // Rewrite to ~ and eliminate the |0.
+ HEAP32[$4] = ((HEAP32[$5]|0)^-1)|0;
return;
}
function rett() {
@@ -131,6 +137,7 @@ function compare_result_simplification() {
HEAP32[$4] = (HEAP32[$5] == HEAP32[$6]) & 1;
HEAP32[$4] = (HEAP32[$5] === HEAP32[$6]) & 1;
HEAP32[$4] = (HEAP32[$5] != HEAP32[$6]) & 1;
+ HEAP32[$4] = (HEAP32[$5] !== HEAP32[$6]) & 1;
// Convert the &1 to |0 here, since we don't get an implicit coersion.
var x = (HEAP32[$5] != HEAP32[$6]) & 1;
}