aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-11 15:24:33 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-02-11 15:24:42 -0800
commite22e4a8192810891c7b3ff0b5790cd63ce5119ae (patch)
treed3d5ce09e20549ae5c4a767e46d7dbe618894cdb
parent1ba4722cda9dd14cca465bd640f25d18781a4754 (diff)
optimize redundant frounds in -O3
-rwxr-xr-xemcc2
-rw-r--r--tests/test_other.py2
-rw-r--r--tools/js-optimizer.js12
-rw-r--r--tools/test-js-optimizer-asm-pre-f32.js8
-rw-r--r--tools/test-js-optimizer-asm-pre-output-f32.js6
5 files changed, 28 insertions, 2 deletions
diff --git a/emcc b/emcc
index 854a04d4..8bcbf636 100755
--- a/emcc
+++ b/emcc
@@ -1672,6 +1672,8 @@ try:
js_optimizer_queue += ['simplifyExpressions']
+ if opt_level >= 3 and shared.Settings.PRECISE_F32: js_optimizer_queue += ['optimizeFrounds']
+
if closure and not shared.Settings.ASM_JS:
flush_js_optimizer_queue()
diff --git a/tests/test_other.py b/tests/test_other.py
index c3aaa9e1..e5dbb38a 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -1780,7 +1780,7 @@ f.close()
(path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(),
['asm', 'simplifyExpressions']),
(path_from_root('tools', 'test-js-optimizer-asm-pre-f32.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output-f32.js')).read(),
- ['asm', 'asmPreciseF32', 'simplifyExpressions']),
+ ['asm', 'asmPreciseF32', 'simplifyExpressions', 'optimizeFrounds']),
(path_from_root('tools', 'test-js-optimizer-asm-last.js'), open(path_from_root('tools', 'test-js-optimizer-asm-last-output.js')).read(),
['asm', 'last']),
(path_from_root('tools', 'test-js-optimizer-asm-relocate.js'), open(path_from_root('tools', 'test-js-optimizer-asm-relocate-output.js')).read(),
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index f9be66df..c8766bc6 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -5099,6 +5099,17 @@ function safeHeap(ast) {
});
}
+function optimizeFrounds(ast) {
+ // collapse fround(fround(..)), which can happen due to elimination
+ function fix(node) {
+ traverseChildren(node, fix);
+ if (node[0] === 'call' && node[1][0] === 'name' && node[1][1] === 'Math_fround' && node[2][0][0] === 'call' && node[2][0][1][0] === 'name' && node[2][0][1][1] === 'Math_fround') {
+ return node[2][0];
+ }
+ }
+ traverseChildren(ast, fix);
+}
+
// Last pass utilities
// Change +5 to DOT$ZERO(5). We then textually change 5 to 5.0 (uglify's ast cannot differentiate between 5 and 5.0 directly)
@@ -5210,6 +5221,7 @@ var passes = {
relocate: relocate,
outline: outline,
safeHeap: safeHeap,
+ optimizeFrounds: optimizeFrounds,
// flags
minifyWhitespace: function() { minifyWhitespace = true },
diff --git a/tools/test-js-optimizer-asm-pre-f32.js b/tools/test-js-optimizer-asm-pre-f32.js
index a5604ef9..5471deeb 100644
--- a/tools/test-js-optimizer-asm-pre-f32.js
+++ b/tools/test-js-optimizer-asm-pre-f32.js
@@ -8,4 +8,10 @@ function badf2() {
$9 = (HEAPF32[tempDoublePtr>>2]=$8,HEAP32[tempDoublePtr>>2]|0);
HEAP32[$gep23_asptr>>2] = $9;
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b", "rett", "ret2t", "retf", "i32_8", "tempDoublePtr", "boxx", "_main", "badf", "badf2"]
+function dupe() {
+ x = Math_fround(x);
+ x = Math_fround(Math_fround(x));
+ x = Math_fround(Math_fround(Math_fround(x)));
+ x = Math_fround(Math_fround(Math_fround(Math_fround(x))));
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["badf", "badf2", "dupe"]
diff --git a/tools/test-js-optimizer-asm-pre-output-f32.js b/tools/test-js-optimizer-asm-pre-output-f32.js
index 42343f55..19059619 100644
--- a/tools/test-js-optimizer-asm-pre-output-f32.js
+++ b/tools/test-js-optimizer-asm-pre-output-f32.js
@@ -8,4 +8,10 @@ function badf2() {
$9 = Math_fround($8);
HEAPF32[$gep23_asptr >> 2] = $9;
}
+function dupe() {
+ x = Math_fround(x);
+ x = Math_fround(x);
+ x = Math_fround(x);
+ x = Math_fround(x);
+}