diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-04-08 19:10:56 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-04-08 19:10:56 -0700 |
commit | c0fdf61aafb9914f9415f3ce85fa9c1d9b16f115 (patch) | |
tree | 66b2b82c7dd6621669ca9e78a134441adf25dc14 | |
parent | d93fd8156ba2530d5ff12caaf9b0eaf557f60de5 (diff) |
do not eliminate loop vars if there are non-loop vars in the else that are influenced by the loop var or the helper
-rw-r--r-- | tools/eliminator/asm-eliminator-test-output.js | 44 | ||||
-rw-r--r-- | tools/eliminator/asm-eliminator-test.js | 47 | ||||
-rw-r--r-- | tools/js-optimizer.js | 19 |
3 files changed, 109 insertions, 1 deletions
diff --git a/tools/eliminator/asm-eliminator-test-output.js b/tools/eliminator/asm-eliminator-test-output.js index a3873067..9caf99d0 100644 --- a/tools/eliminator/asm-eliminator-test-output.js +++ b/tools/eliminator/asm-eliminator-test-output.js @@ -857,4 +857,48 @@ function elimOneLoopVar($argc, $argv) { HEAP32[$vararg_buffer1 >> 2] = $curri$012; return $retval$0 | 0; } +function elimOneLoopVar2() { + var $storemerge3$neg9 = 0, $18 = 0, $25 = 0, $26 = 0, $30 = 0, $jp = 0; + $storemerge3$neg9 = -1; + while (1) { + $25 = $jp + ($26 << 2) | 0; + HEAP32[$25 >> 2] = ($18 + $storemerge3$neg9 | 0) + (HEAP32[$25 >> 2] | 0) | 0; + $30 = $26 + 1 | 0; + if (($30 | 0) == 63) { + break; + } else { + $storemerge3$neg9 = $26 ^ -1; + $26 = $30; + } + } +} +function elimOneLoopVar3() { + var $storemerge3$neg9 = 0, $18 = 0, $25 = 0, $26 = 0, $30 = 0, $jp = 0; + $storemerge3$neg9 = -1; + while (1) { + $25 = $jp + ($26 << 2) | 0; + HEAP32[$25 >> 2] = ($18 + $storemerge3$neg9 | 0) + (HEAP32[$25 >> 2] | 0) | 0; + $30 = $26 + 1 | 0; + if (($30 | 0) == 63) { + break; + } else { + $storemerge3$neg9 = $30 ^ -1; + $26 = $30; + } + } +} +function elimOneLoopVar4() { + var $storemerge3$neg9 = 0, $18 = 0, $25 = 0, $26 = 0, $jp = 0; + $storemerge3$neg9 = -1; + while (1) { + $25 = $jp + ($26 << 2) | 0; + HEAP32[$25 >> 2] = ($18 + $storemerge3$neg9 | 0) + (HEAP32[$25 >> 2] | 0) | 0; + $26 = $26 + 1 | 0; + if (($26 | 0) == 63) { + break; + } else { + $storemerge3$neg9 = $18 ^ -1; + } + } +} diff --git a/tools/eliminator/asm-eliminator-test.js b/tools/eliminator/asm-eliminator-test.js index 312e9e2c..a3de3d9d 100644 --- a/tools/eliminator/asm-eliminator-test.js +++ b/tools/eliminator/asm-eliminator-test.js @@ -1086,5 +1086,50 @@ function elimOneLoopVar($argc, $argv) { HEAP32[$vararg_buffer1 >> 2] = $curri$012; return $retval$0 | 0; } -// 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"] +function elimOneLoopVar2() { + var $storemerge3$neg9 = 0, $18 = 0, $25 = 0, $26 = 0, $30 = 0, $jp = 0; + $storemerge3$neg9 = -1; + while (1) { + $25 = $jp + ($26 << 2) | 0; + HEAP32[$25 >> 2] = ($18 + $storemerge3$neg9 | 0) + (HEAP32[$25 >> 2] | 0) | 0; + $30 = $26 + 1 | 0; + if (($30 | 0) == 63) { + break; + } else { + $storemerge3$neg9 = $26 ^ -1; // $26 is a loopvar, use here is dangerous + $26 = $30; + } + } +} +function elimOneLoopVar3() { + var $storemerge3$neg9 = 0, $18 = 0, $25 = 0, $26 = 0, $30 = 0, $jp = 0; + $storemerge3$neg9 = -1; + while (1) { + $25 = $jp + ($26 << 2) | 0; + HEAP32[$25 >> 2] = ($18 + $storemerge3$neg9 | 0) + (HEAP32[$25 >> 2] | 0) | 0; + $30 = $26 + 1 | 0; + if (($30 | 0) == 63) { + break; + } else { + $storemerge3$neg9 = $30 ^ -1; // $26 is a helper, use here is dangerous + $26 = $30; + } + } +} +function elimOneLoopVar4() { + var $storemerge3$neg9 = 0, $18 = 0, $25 = 0, $26 = 0, $30 = 0, $jp = 0; + $storemerge3$neg9 = -1; + while (1) { + $25 = $jp + ($26 << 2) | 0; + HEAP32[$25 >> 2] = ($18 + $storemerge3$neg9 | 0) + (HEAP32[$25 >> 2] | 0) | 0; + $30 = $26 + 1 | 0; + if (($30 | 0) == 63) { + break; + } else { + $storemerge3$neg9 = $18 ^ -1; + $26 = $30; + } + } +} +// 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"] diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 086ed30e..e75ff317 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -3550,6 +3550,25 @@ function eliminate(ast, memSafe) { } } } + // remove loop vars that are used in the rest of the else + for (var i = 0; i < assigns.length; i++) { + if (assigns[i][0] === 'stat' && assigns[i][1][0] === 'assign') { + var assign = assigns[i][1]; + if (!(assign[1] === true && assign[2][0] === 'name' && assign[3][0] === 'name') || loopers.indexOf(assign[2][1]) < 0) { + // this is not one of the loop assigns + traverse(assign, function(node, type) { + if (type === 'name') { + var index = loopers.indexOf(node[1]); + if (index < 0) index = helpers.indexOf(node[1]); + if (index >= 0) { + loopers.splice(index, 1); + helpers.splice(index, 1); + } + } + }); + } + } + } if (loopers.length === 0) return; for (var l = 0; l < loopers.length; l++) { var looper = loopers[l]; |