Skip to content

Explicitly recognise asm_float_zero #5046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function test() {
var f1 = f0;
if (HEAPF32[(0 | 0) >> 2] <= HEAPF32[(1 | 0) >> 2]) {
f1 = Math_fround(+1);
return Math_fround(f1);
} else {
f1 = Math_fround(+2);
return Math_fround(f1);
}
return f0;
}
12 changes: 12 additions & 0 deletions tests/optimizer/test-no-reduce-dead-float-return-to-nothing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function test() {
var f1 = f0;
if (HEAPF32[(0 | 0) >> 2] <= HEAPF32[(1 | 0) >> 2]) {
f1 = Math_fround(+1);
return Math_fround(f1);
} else {
f1 = Math_fround(+2);
return Math_fround(f1);
}
return f0;
}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["test"]
11 changes: 11 additions & 0 deletions tests/optimizer/test-reduce-dead-float-return-output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function test() {
var f1 = f0;
if (HEAPF32[(0 | 0) >> 2] <= HEAPF32[(1 | 0) >> 2]) {
f1 = Math_fround(+1);
return Math_fround(f1);
} else {
f1 = Math_fround(+2);
return Math_fround(f1);
}
return f0;
}
12 changes: 12 additions & 0 deletions tests/optimizer/test-reduce-dead-float-return.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function test() {
var $x = Math_fround(0);
if (HEAPF32[(0|0)>>2] <= HEAPF32[(1|0)>>2]) {
$x = Math_fround(+1);
return (Math_fround($x));
} else {
$x = Math_fround(+2);
return (Math_fround($x));
}
return Math_fround((Math_fround(+0)));
}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["test"]
4 changes: 4 additions & 0 deletions tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,10 @@ def test_js_optimizer(self):
['asm', 'asmPreciseF32', 'simplifyExpressions', 'optimizeFrounds']),
(path_from_root('tests', 'optimizer', 'test-js-optimizer-asm-pre-f32.js'), open(path_from_root('tests', 'optimizer', 'test-js-optimizer-asm-pre-output-f32-nosimp.js')).read(),
['asm', 'asmPreciseF32', 'optimizeFrounds']),
(path_from_root('tests', 'optimizer', 'test-reduce-dead-float-return.js'), open(path_from_root('tests', 'optimizer', 'test-reduce-dead-float-return-output.js')).read(),
['asm', 'optimizeFrounds', 'registerizeHarder']),
(path_from_root('tests', 'optimizer', 'test-no-reduce-dead-float-return-to-nothing.js'), open(path_from_root('tests', 'optimizer', 'test-no-reduce-dead-float-return-to-nothing-output.js')).read(),
['asm', 'registerizeHarder']),
(path_from_root('tests', 'optimizer', 'test-js-optimizer-asm-last.js'), [open(path_from_root('tests', 'optimizer', 'test-js-optimizer-asm-lastOpts-output.js')).read(), open(path_from_root('tests', 'optimizer', 'test-js-optimizer-asm-lastOpts-output2.js')).read(), open(path_from_root('tests', 'optimizer', 'test-js-optimizer-asm-lastOpts-output3.js')).read()],
['asm', 'asmLastOpts']),
(path_from_root('tests', 'optimizer', 'asmLastOpts.js'), open(path_from_root('tests', 'optimizer', 'asmLastOpts-output.js')).read(),
Expand Down
1 change: 1 addition & 0 deletions tools/js-optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ function detectType(node, asmInfo, inVarDef) {
if (ret !== ASM_NONE) return ret;
}
if (!inVarDef) {
if (ASM_FLOAT_ZERO && ASM_FLOAT_ZERO === node[1]) return ASM_FLOAT;
switch (node[1]) {
case 'inf': case 'nan': return ASM_DOUBLE; // TODO: when minified
case 'tempRet0': return ASM_INT;
Expand Down
1 change: 1 addition & 0 deletions tools/optimizer/optimizer-shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ AsmType detectType(Ref node, AsmData *asmData, bool inVarDef) {
if (ret != ASM_NONE) return ret;
}
if (!inVarDef) {
if (!ASM_FLOAT_ZERO.isNull() && node[1] == ASM_FLOAT_ZERO) return ASM_FLOAT;
if (node[1] == INF || node[1] == NaN) return ASM_DOUBLE;
if (node[1] == TEMP_RET0) return ASM_INT;
return ASM_NONE;
Expand Down