diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 16:41:44 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 16:43:52 -0800 |
commit | 78dbafb289e222550abda6b53e7099352a599804 (patch) | |
tree | bac704182dd01dc3d78bf0f1ca6064f78b1d7786 | |
parent | 0779c55c28f17d796f3f13962cfcac954e6cef59 (diff) |
keep a coercion right on top of heap accesses in asm mode
-rwxr-xr-x | emcc | 9 | ||||
-rwxr-xr-x | tests/runner.py | 2 | ||||
-rw-r--r-- | tools/js-optimizer.js | 12 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre-output.js | 4 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre.js | 4 |
5 files changed, 26 insertions, 5 deletions
@@ -1186,9 +1186,14 @@ try: else: return 'eliminate' - js_optimizer_queue += [get_eliminate()] + def get_simplify_pre(): + if shared.Settings.ASM_JS: + return 'simplifyExpressionsPreAsm' + else: + return 'simplifyExpressionsPre' + + js_optimizer_queue += [get_eliminate(), get_simplify_pre()] - js_optimizer_queue += ['simplifyExpressionsPre'] if shared.Settings.RELOOP: js_optimizer_queue += ['optimizeShiftsAggressive', get_eliminate()] # aggressive shifts optimization requires loops, it breaks on switches diff --git a/tests/runner.py b/tests/runner.py index a6508fe9..d5662375 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8929,6 +8929,8 @@ f.close() ['eliminateAsm']), (path_from_root('tools', 'test-js-optimizer-asm-regs.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-output.js')).read(), ['registerizeAsm']), + (path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(), + ['simplifyExpressionsPreAsm']), ]: output = Popen([NODE_JS, path_from_root('tools', 'js-optimizer.js'), input] + passes, stdin=PIPE, stdout=PIPE).communicate()[0] self.assertIdentical(expected, output.replace('\r\n', '\n').replace('\n\n', '\n')) diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 22d0f4d1..7fe8d99f 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -404,7 +404,7 @@ function removeUnneededLabelSettings(ast) { // Various expression simplifications. Pre run before closure (where we still have metadata), Post run after. -function simplifyExpressionsPre(ast) { +function simplifyExpressionsPre(ast, asm) { // When there is a bunch of math like (((8+5)|0)+12)|0, only the external |0 is needed, one correction is enough. // At each node, ((X|0)+Y)|0 can be transformed into (X+Y): The inner corrections are not needed // TODO: Is the same is true for 0xff, 0xffff? @@ -423,10 +423,11 @@ function simplifyExpressionsPre(ast) { // We might be able to remove this correction for (var i = stack.length-1; i >= 0; i--) { if (stack[i] == 1) { - // Great, we can eliminate - rerun = true; // we will replace ourselves with the non-zero side. Recursively process that node. var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other; + if (asm && result[0] == 'sub') break; // we must keep a coercion right on top of a heap access in asm mode + // Great, we can eliminate + rerun = true; while (other = process(result, result[0], stack)) { result = other; } @@ -522,6 +523,10 @@ function simplifyExpressionsPre(ast) { // simplifyZeroComp(ast); TODO: investigate performance } +function simplifyExpressionsPreAsm(ast) { + simplifyExpressionsPre(ast, true); +} + // In typed arrays mode 2, we can have // HEAP[x >> 2] // very often. We can in some cases do the shift on the variable itself when it is set, @@ -2134,6 +2139,7 @@ var passes = { removeAssignsToUndefined: removeAssignsToUndefined, //removeUnneededLabelSettings: removeUnneededLabelSettings, simplifyExpressionsPre: simplifyExpressionsPre, + simplifyExpressionsPreAsm: simplifyExpressionsPreAsm, optimizeShiftsConservative: optimizeShiftsConservative, optimizeShiftsAggressive: optimizeShiftsAggressive, simplifyExpressionsPost: simplifyExpressionsPost, diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js new file mode 100644 index 00000000..10212470 --- /dev/null +++ b/tools/test-js-optimizer-asm-pre-output.js @@ -0,0 +1,4 @@ +function a() { + f((HEAPU8[10202] | 0) + 5 | 0); +} + diff --git a/tools/test-js-optimizer-asm-pre.js b/tools/test-js-optimizer-asm-pre.js new file mode 100644 index 00000000..8d33a6a2 --- /dev/null +++ b/tools/test-js-optimizer-asm-pre.js @@ -0,0 +1,4 @@ +function a() { + f((HEAPU8[10202] | 0) + 5 | 0); +} +// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a"] |