aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-12-28 17:43:22 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-12-28 17:43:22 -0800
commitf0d47bd575a8c7ca758718ff0e6e5763f936dd6d (patch)
treeb1f9667fe69a275ed033cde6b504830920041c38 /tools/js-optimizer.js
parent995e37ebc0a6a4906dd8dcd0a05f664ddd6dbaf1 (diff)
fix bug in optimizeShifts with not fixing the shift of X = needsShift
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 5bf88a33..a317543d 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -149,7 +149,7 @@ function emptyNode() {
// Passes
// Dump the AST. Useful for debugging. For example,
-// echo "HEAP[(a+b+c)>>2]" | node tools/js-optimizer.js dump
+// echo "HEAP[(a+b+c)>>2]" | node tools/js-optimizer.js dumpAst
function dumpAst(ast) {
printErr(JSON.stringify(ast));
}
@@ -354,6 +354,7 @@ function simplifyExpressionsPre(ast) {
// HEAP[x >> 2]
// very often. We can in some cases do the shift on the variable itself when it is set,
// to greatly reduce the number of shift operations.
+// XXX x << 24 >> 24 - are we breaking that? only optimize small shifts!
function optimizeShifts(ast) {
traverseGeneratedFunctions(ast, function(fun) {
var funMore = true;
@@ -508,7 +509,8 @@ function optimizeShifts(ast) {
});
traverse(fun, function(node, type, stack) { // replace name with unshifted name, making everything valid again by balancing the assign changes
stack.push(node);
- if (node[0] == 'name' && !node[2] && vars[node[1]] && vars[node[1]].primaryShift >= 0 && stack[stack.length-2][0] != 'assign') {
+ if (node[0] == 'name' && !node[2] && vars[node[1]] && vars[node[1]].primaryShift >= 0 &&
+ (stack[stack.length-2][0] != 'assign' || stack[stack.length-2][2] != node)) { // ignore changing VAR in |VAR = something|
node[2] = true;
return ['binary', '<<', node, ['num', vars[node[1]].primaryShift]];
}