From b090967580b4b1d03134b4dd11d849fd50f23951 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 8 Jul 2013 11:23:18 -0700 Subject: Xor optimizations. Optimize x^-1 to ~x; this comes up because LLVM does not have a bitwise negate operator. Optimize x&1^1 to !x; this comes up because of how LLVM lowers C++ bool variables. Also, add an optimization to simplifyExpressionsPre to eliminate |0 from '~' expressions in more cases. --- tools/js-optimizer.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools/js-optimizer.js') diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 0d1e8801..f69278b0 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -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') { -- cgit v1.2.3-18-g5258 From 30d6e3ce7d7b28998264b913b793a921d6d78e41 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 8 Jul 2013 11:23:41 -0700 Subject: Add '!==' as a comparison operator. --- tools/js-optimizer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/js-optimizer.js') diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index f69278b0..e7a745e1 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 -- cgit v1.2.3-18-g5258