optimize redundant frounds in -O3

This commit is contained in:
Alon Zakai 2014-02-11 15:24:33 -08:00
Родитель 1ba4722cda
Коммит e22e4a8192
5 изменённых файлов: 28 добавлений и 2 удалений

2
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()

Просмотреть файл

@ -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(),

Просмотреть файл

@ -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 },

Просмотреть файл

@ -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"]

Просмотреть файл

@ -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);
}