From e4e8063f6d568277b297f19d51801cd7dda9545c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 7 Jan 2014 14:05:53 -0800 Subject: handle variables that assign a value including themselves in aggressiveVariableElimination --- tools/js-optimizer.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tools/js-optimizer.js') diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 7b1c6bd1..b507a45a 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -3030,17 +3030,18 @@ function aggressiveVariableEliminationInternal(func, asmData) { allTrivials = {}; - var values = {}; + var values = {}, recursives = {}; function evaluate(name) { var node = values[name]; if (node) return node; - values[node] = null; // prevent infinite recursion + values[name] = null; // prevent infinite recursion var def = defs[name]; if (def) { node = def[3]; if (node[0] == 'name') { var name2 = node[1]; + assert(name2 !== name); if (name2 in trivials) { node = evaluate(name2); } @@ -3048,6 +3049,10 @@ function aggressiveVariableEliminationInternal(func, asmData) { traverse(node, function(node, type) { if (type == 'name') { var name2 = node[1]; + if (name2 === name) { + recursives[name] = 1; + return false; + } if (name2 in trivials) { return evaluate(name2); } @@ -3062,6 +3067,9 @@ function aggressiveVariableEliminationInternal(func, asmData) { for (var name in trivials) { evaluate(name); } + for (var name in recursives) { + delete trivials[name]; + } for (var name in trivials) { var def = defs[name]; -- cgit v1.2.3-70-g09d2