aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-05-17 20:53:41 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-05-18 10:25:00 -0700
commit57360800512dc1b23532e1c125c8e0627ccdbcfa (patch)
tree4631ae59fff7954b3547c6478d16daf34b1d702a /tools
parent398cded47b7e08fbb753fb7b4788da29a22195bb (diff)
fix looptemp replacements when there is a continue with a phi of the loop variable
Diffstat (limited to 'tools')
-rw-r--r--tools/eliminator/asm-eliminator-test-output.js18
-rw-r--r--tools/eliminator/asm-eliminator-test.js19
-rw-r--r--tools/js-optimizer.js6
3 files changed, 42 insertions, 1 deletions
diff --git a/tools/eliminator/asm-eliminator-test-output.js b/tools/eliminator/asm-eliminator-test-output.js
index 50bd8f49..d530a90c 100644
--- a/tools/eliminator/asm-eliminator-test-output.js
+++ b/tools/eliminator/asm-eliminator-test-output.js
@@ -936,4 +936,22 @@ function elimOneLoopVar5() {
}
}
}
+function loopVarWithContinue() {
+ var i = 0, i$looptemp = 0;
+ i = 0;
+ while (1) {
+ i$looptemp = i;
+ i = i + 1;
+ if (check()) {
+ i = i$looptemp + 1;
+ continue;
+ }
+ work(i);
+ work(i$looptemp);
+ work(i);
+ if (check()) {
+ break;
+ }
+ }
+}
diff --git a/tools/eliminator/asm-eliminator-test.js b/tools/eliminator/asm-eliminator-test.js
index 2613b356..8c469964 100644
--- a/tools/eliminator/asm-eliminator-test.js
+++ b/tools/eliminator/asm-eliminator-test.js
@@ -1189,5 +1189,24 @@ function elimOneLoopVar5() {
}
}
}
+function loopVarWithContinue() {
+ var i = 0, inc = 0;
+ i = 0;
+ while (1) {
+ inc = i + 1;
+ if (check()) {
+ i = i + 1;
+ continue;
+ }
+ work(inc);
+ work(i);
+ work(inc);
+ if (check()) {
+ break;
+ } else {
+ i = inc;
+ }
+ }
+}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "__Z11printResultPiS_j", "_segment_holding", "__ZN5identC2EiPKcPci", "_vec2Length", "exc", "label", "confuusion", "tempDouble", "_org_apache_harmony_luni_util_NumberConverter_freeFormat__", "__ZN23b2EdgeAndPolygonContact8EvaluateEP10b2ManifoldRK11b2TransformS4_", "_java_nio_charset_Charset_forNameInternal___java_lang_String", "looop2", "looop3", "looop4", "looop5", "looop6", "looop7", "looop8", "multiloop", "multiloop2", "tempDouble2", "watIf", "select2", "binary", "cute", "selfAssign", "elimOneLoopVar", "elimOneLoopVar2", "elimOneLoopVar3", "elimOneLoopVar4", "elimOneLoopVarStillUsed", "elimOneLoopVarStillUsedSE", "elimOneLoopVar5"]
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index fe00254a..c0096df4 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -3717,11 +3717,15 @@ function eliminate(ast, memSafe) {
assert(!(temp in asmData.vars));
for (var i = firstLooperUsage; i <= lastLooperUsage; i++) {
var curr = i < stats.length-1 ? stats[i] : last[1]; // on the last line, just look in the condition
- traverse(curr, function(node, type) {
+ traverse(curr, function looperToLooptemp(node, type) {
if (type === 'name') {
if (node[1] === looper) {
node[1] = temp;
}
+ } else if (type === 'assign' && node[2][0] === 'name') {
+ // do not traverse the assignment target, phi assignments to the loop variable must remain
+ traverse(node[3], looperToLooptemp);
+ return null;
}
});
}