diff --git a/emcc b/emcc index 3c427677f..490e64088 100755 --- a/emcc +++ b/emcc @@ -1967,16 +1967,23 @@ try: if len(js_optimizer_extra_info) == 0: js_optimizer_extra_info = None if len(js_optimizer_queue) > 0 and not(not shared.Settings.ASM_JS and len(js_optimizer_queue) == 1 and js_optimizer_queue[0] == 'last'): - if DEBUG != '2': + + def add_opt_args(args): if shared.Settings.ASM_JS: - js_optimizer_queue = ['asm'] + js_optimizer_queue + args = ['asm'] + args + if shared.Settings.PRECISE_F32: + args = ['asmPreciseF32'] + args + return args + + if DEBUG != '2': + js_optimizer_queue = add_opt_args(js_optimizer_queue) logging.debug('applying js optimization passes: %s', js_optimizer_queue) final = shared.Building.js_optimizer(final, js_optimizer_queue, jcache, debug_level >= 4, js_optimizer_extra_info) js_transform_tempfiles.append(final) if DEBUG: save_intermediate('js_opts') else: for name in js_optimizer_queue: - passes = [name] + passes = add_opt_args([name]) if shared.Settings.ASM_JS: passes = ['asm'] + passes logging.debug('applying js optimization pass: %s', passes) diff --git a/tests/test_other.py b/tests/test_other.py index bc05826ea..47d26416e 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -1779,6 +1779,8 @@ f.close() ['asm', 'registerize', 'minifyLocals']), (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']), (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 2ae3ce47a..905e80fc0 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -709,10 +709,6 @@ function simplifyExpressions(ast) { } } }); - var hasFloat = false; - for (var v in asmData.vars) { - if (asmData.vars[v] === ASM_FLOAT) hasFloat = true; - } for (var v in bitcastVars) { var info = bitcastVars[v]; // good variables define only one type, use only one type, have definitions and uses, and define as a different type than they use @@ -726,7 +722,7 @@ function simplifyExpressions(ast) { if (correct === 'HEAP32') { define[3] = ['binary', '|', define[3], ['num', 0]]; } else { - define[3] = ['unary-prefix', '+', define[3]]; + define[3] = makeAsmCoercion(define[3], asmPreciseF32 ? ASM_FLOAT : ASM_DOUBLE); } // do we want a simplifybitops on the new values here? }); @@ -735,7 +731,7 @@ function simplifyExpressions(ast) { }); var correctType; switch(asmData.vars[v]) { - case ASM_INT: correctType = hasFloat ? ASM_FLOAT : ASM_DOUBLE; break; + case ASM_INT: correctType = asmPreciseF32 ? ASM_FLOAT : ASM_DOUBLE; break; case ASM_FLOAT: case ASM_DOUBLE: correctType = ASM_INT; break; } asmData.vars[v] = correctType; @@ -5162,7 +5158,7 @@ function asmLastOpts(ast) { // Passes table -var minifyWhitespace = false, printMetadata = true, asm = false, last = false; +var minifyWhitespace = false, printMetadata = true, asm = false, asmPreciseF32 = false, last = false; var passes = { // passes @@ -5191,6 +5187,7 @@ var passes = { minifyWhitespace: function() { minifyWhitespace = true }, noPrintMetadata: function() { printMetadata = false }, asm: function() { asm = true }, + asmPreciseF32: function() { asmPreciseF32 = true }, last: function() { last = true }, }; diff --git a/tools/test-js-optimizer-asm-pre-f32.js b/tools/test-js-optimizer-asm-pre-f32.js new file mode 100644 index 000000000..a5604ef9c --- /dev/null +++ b/tools/test-js-optimizer-asm-pre-f32.js @@ -0,0 +1,11 @@ +function badf() { + var $9 = Math_fround(0); + $9 = (HEAP32[tempDoublePtr>>2]=$8,Math_fround(HEAPF32[tempDoublePtr>>2])); + HEAPF32[$gep23_asptr>>2] = $9; +} +function badf2() { + var $9 = 0; + $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"] diff --git a/tools/test-js-optimizer-asm-pre-output-f32.js b/tools/test-js-optimizer-asm-pre-output-f32.js new file mode 100644 index 000000000..42343f555 --- /dev/null +++ b/tools/test-js-optimizer-asm-pre-output-f32.js @@ -0,0 +1,11 @@ +function badf() { + var $9 = 0; + $9 = $8 | 0; + HEAP32[$gep23_asptr >> 2] = $9; +} +function badf2() { + var $9 = Math_fround(0); + $9 = Math_fround($8); + HEAPF32[$gep23_asptr >> 2] = $9; +} +