aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-07 20:41:55 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-06-07 20:41:55 -0700
commit8c3c8879d0a6c70fce10ee645e0f871f44f3d45a (patch)
tree928c04ed6fde094e93ee9e4f1bf4be9389ae193f
parent9e7ce499b5883eeb6cd9deac70d997ff5d0f7eeb (diff)
eliminate bitcasts of immediately loaded values
-rw-r--r--tools/js-optimizer.js16
-rw-r--r--tools/test-js-optimizer-asm-pre-output.js2
-rw-r--r--tools/test-js-optimizer-asm-pre.js2
3 files changed, 20 insertions, 0 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 9b559ee2..7aff3a47 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -543,6 +543,22 @@ function simplifyExpressionsPre(ast) {
node[3] = value[1][3];
}
}
+ } else if (type == 'seq') {
+ // (HEAP32[tempDoublePtr >> 2] = HEAP32[$37 >> 2], +HEAPF32[tempDoublePtr >> 2])
+ // ==>
+ // +HEAPF32[$37 >> 2]
+ if (node[0] == 'seq' && node[1][0] == 'assign' && node[1][2][0] == 'sub' && node[1][2][1][0] == 'name' &&
+ (node[1][2][1][1] == 'HEAP32' || node[1][2][1][1] == 'HEAPF32') &&
+ node[1][2][2][0] == 'binary' && node[1][2][2][2][0] == 'name' && node[1][2][2][2][1] == 'tempDoublePtr' &&
+ node[1][3][0] == 'sub' && node[1][3][1][0] == 'name' && (node[1][3][1][1] == 'HEAP32' || node[1][3][1][1] == 'HEAPF32')) {
+ if (node[1][2][1][1] == 'HEAP32') {
+ node[1][3][1][1] = 'HEAPF32';
+ return ['unary-prefix', '+', node[1][3]];
+ } else {
+ node[1][3][1][1] = 'HEAP32';
+ return ['binary', '|', node[1][3], ['num', 0]];
+ }
+ }
}
});
diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js
index 57a7a4f8..2f1fca1d 100644
--- a/tools/test-js-optimizer-asm-pre-output.js
+++ b/tools/test-js-optimizer-asm-pre-output.js
@@ -114,5 +114,7 @@ function tempDoublePtr($45, $14, $28, $42) {
$42 = $42 | 0;
HEAPF32[$45 >> 2] = ($14 < $28 ? $14 : $28) - $42;
HEAP32[$world + 102916 >> 2] = _malloc(192) | 0;
+ f(+HEAPF32[$45 >> 2]);
+ g(HEAP32[$14 >> 2] | 0);
}
diff --git a/tools/test-js-optimizer-asm-pre.js b/tools/test-js-optimizer-asm-pre.js
index 27eff714..16a2566a 100644
--- a/tools/test-js-optimizer-asm-pre.js
+++ b/tools/test-js-optimizer-asm-pre.js
@@ -116,5 +116,7 @@ function tempDoublePtr($45, $14, $28, $42) {
$42 = $42 | 0;
HEAP32[$45 >> 2] = 0 | (HEAPF32[tempDoublePtr >> 2] = ($14 < $28 ? $14 : $28) - $42, HEAP32[tempDoublePtr >> 2] | 0);
HEAP32[$world + 102916 >> 2] = _malloc(192) | 0;
+ f((HEAP32[tempDoublePtr >> 2] = HEAP32[$45 >> 2], +HEAPF32[tempDoublePtr >> 2]));
+ g((HEAPF32[tempDoublePtr >> 2] = HEAPF32[$14 >> 2], HEAP32[tempDoublePtr >> 2] | 0));
}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b", "rett", "ret2t", "retf", "i32_8", "tempDoublePtr"]