diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-11 15:24:33 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-11 15:24:42 -0800 |
commit | e22e4a8192810891c7b3ff0b5790cd63ce5119ae (patch) | |
tree | d3d5ce09e20549ae5c4a767e46d7dbe618894cdb /tools | |
parent | 1ba4722cda9dd14cca465bd640f25d18781a4754 (diff) |
optimize redundant frounds in -O3
Diffstat (limited to 'tools')
-rw-r--r-- | tools/js-optimizer.js | 12 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre-f32.js | 8 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-pre-output-f32.js | 6 |
3 files changed, 25 insertions, 1 deletions
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); +} |