diff options
-rw-r--r-- | tools/js-optimizer.js | 11 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre-output.js | 44 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre.js | 46 |
3 files changed, 95 insertions, 6 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index d26d902f..69abe23a 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -428,12 +428,13 @@ function simplifyExpressionsPre(ast) { if (stack[i] == 1) { // we will replace ourselves with the non-zero side. Recursively process that node. var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other; - // Great, we can eliminate - rerun = true; - while (other = process(result, result[0], stack)) { - result = other; + // replace node in-place + node.length = result.length; + for (var j = 0; j < result.length; j++) { + node[j] = result[j]; } - return result; + rerun = true; + return process(result, result[0], stack); } else if (stack[i] == -1) { break; // Too bad, we can't } else if (asm) { diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js index afd43893..84c95360 100644 --- a/tools/test-js-optimizer-asm-pre-output.js +++ b/tools/test-js-optimizer-asm-pre-output.js @@ -5,4 +5,48 @@ function a() { f(351); f(8); } +function b($this, $__n) { + $this = $this | 0; + $__n = $__n | 0; + var $4 = 0, $5 = 0, $10 = 0, $13 = 0, $14 = 0, $15 = 0, $23 = 0, $30 = 0, $38 = 0, $40 = 0; + if (($__n | 0) == 0) { + return; + } + $4 = $this; + $5 = HEAP8[$4 & 16777215] | 0; + if (($5 & 1) << 24 >> 24 == 0) { + $14 = 10; + $13 = $5; + } else { + $10 = HEAP32[($this & 16777215) >> 2] | 0; + $14 = ($10 & -2) - 1 | 0; + $13 = $10 & 255; + } + $15 = $13 & 255; + if (($15 & 1 | 0) == 0) { + $23 = $15 >>> 1; + } else { + $23 = HEAP32[($this + 4 & 16777215) >> 2] | 0; + } + if (($14 - $23 | 0) >>> 0 < $__n >>> 0) { + __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEjjjjjj($this, $14, ($__n - $14 | 0) + $23 | 0, $23, $23); + $30 = HEAP8[$4 & 16777215] | 0; + } else { + $30 = $13; + } + if (($30 & 1) << 24 >> 24 == 0) { + $38 = $this + 1 | 0; + } else { + $38 = HEAP32[($this + 8 & 16777215) >> 2] | 0; + } + _memset($38 + $23 | 0, 0, $__n | 0, 1, 1213141516); + $40 = $23 + $__n | 0; + if ((HEAP8[$4 & 16777215] & 1) << 24 >> 24 == 0) { + HEAP8[$4 & 16777215] = $40 << 1 & 255; + } else { + HEAP32[($this + 4 & 16777215) >> 2] = $40; + } + HEAP8[$38 + $40 & 16777215] = 0; + return; +} diff --git a/tools/test-js-optimizer-asm-pre.js b/tools/test-js-optimizer-asm-pre.js index 6c9e64c1..3042ef66 100644 --- a/tools/test-js-optimizer-asm-pre.js +++ b/tools/test-js-optimizer-asm-pre.js @@ -5,4 +5,48 @@ function a() { f(347 | 12); f(347 & 12); } -// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a"] +function b($this, $__n) { + $this = $this | 0; + $__n = $__n | 0; + var $4 = 0, $5 = 0, $10 = 0, $13 = 0, $14 = 0, $15 = 0, $23 = 0, $30 = 0, $38 = 0, $40 = 0; + if (($__n | 0) == 0) { + return; + } + $4 = $this; + $5 = HEAP8[$4 & 16777215] | 0; + if (($5 & 1) << 24 >> 24 == 0) { + $14 = 10; + $13 = $5; + } else { + $10 = HEAP32[(($this | 0) & 16777215) >> 2] | 0; + $14 = ($10 & -2) - 1 | 0; + $13 = $10 & 255; + } + $15 = $13 & 255; + if (($15 & 1 | 0) == 0) { + $23 = $15 >>> 1; + } else { + $23 = HEAP32[(($this + 4 | 0) & 16777215) >> 2] | 0; + } + if (($14 - $23 | 0) >>> 0 < $__n >>> 0) { + __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEjjjjjj($this, $14, ($__n - $14 | 0) + $23 | 0, $23, $23); + $30 = HEAP8[$4 & 16777215] | 0; + } else { + $30 = $13; + } + if (($30 & 1) << 24 >> 24 == 0) { + $38 = $this + 1 | 0; + } else { + $38 = HEAP32[(($this + 8 | 0) & 16777215) >> 2] | 0; + } + _memset($38 + $23 | 0 | 0 | 0, 0 | 0 | 0, $__n | 0 | 0, 1 | 0 | 0, 1213141516); + $40 = $23 + $__n | 0; + if (((HEAP8[$4 & 16777215] | 0) & 1) << 24 >> 24 == 0) { + HEAP8[$4 & 16777215] = $40 << 1 & 255; + } else { + HEAP32[(($this + 4 | 0) & 16777215) >> 2] = $40; + } + HEAP8[($38 + $40 | 0) & 16777215] = 0; + return; +} +// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b"] |