keep a coercion right on top of heap accesses in asm mode

This commit is contained in:
Alon Zakai 2013-01-08 16:41:44 -08:00
Родитель 0779c55c28
Коммит 78dbafb289
5 изменённых файлов: 26 добавлений и 5 удалений

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

@ -1186,9 +1186,14 @@ try:
else:
return 'eliminate'
js_optimizer_queue += [get_eliminate()]
def get_simplify_pre():
if shared.Settings.ASM_JS:
return 'simplifyExpressionsPreAsm'
else:
return 'simplifyExpressionsPre'
js_optimizer_queue += [get_eliminate(), get_simplify_pre()]
js_optimizer_queue += ['simplifyExpressionsPre']
if shared.Settings.RELOOP:
js_optimizer_queue += ['optimizeShiftsAggressive', get_eliminate()] # aggressive shifts optimization requires loops, it breaks on switches

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

@ -8929,6 +8929,8 @@ f.close()
['eliminateAsm']),
(path_from_root('tools', 'test-js-optimizer-asm-regs.js'), open(path_from_root('tools', 'test-js-optimizer-asm-regs-output.js')).read(),
['registerizeAsm']),
(path_from_root('tools', 'test-js-optimizer-asm-pre.js'), open(path_from_root('tools', 'test-js-optimizer-asm-pre-output.js')).read(),
['simplifyExpressionsPreAsm']),
]:
output = Popen([NODE_JS, path_from_root('tools', 'js-optimizer.js'), input] + passes, stdin=PIPE, stdout=PIPE).communicate()[0]
self.assertIdentical(expected, output.replace('\r\n', '\n').replace('\n\n', '\n'))

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

@ -404,7 +404,7 @@ function removeUnneededLabelSettings(ast) {
// Various expression simplifications. Pre run before closure (where we still have metadata), Post run after.
function simplifyExpressionsPre(ast) {
function simplifyExpressionsPre(ast, asm) {
// When there is a bunch of math like (((8+5)|0)+12)|0, only the external |0 is needed, one correction is enough.
// At each node, ((X|0)+Y)|0 can be transformed into (X+Y): The inner corrections are not needed
// TODO: Is the same is true for 0xff, 0xffff?
@ -423,10 +423,11 @@ function simplifyExpressionsPre(ast) {
// We might be able to remove this correction
for (var i = stack.length-1; i >= 0; i--) {
if (stack[i] == 1) {
// Great, we can eliminate
rerun = true;
// we will replace ourselves with the non-zero side. Recursively process that node.
var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other;
if (asm && result[0] == 'sub') break; // we must keep a coercion right on top of a heap access in asm mode
// Great, we can eliminate
rerun = true;
while (other = process(result, result[0], stack)) {
result = other;
}
@ -522,6 +523,10 @@ function simplifyExpressionsPre(ast) {
// simplifyZeroComp(ast); TODO: investigate performance
}
function simplifyExpressionsPreAsm(ast) {
simplifyExpressionsPre(ast, true);
}
// In typed arrays mode 2, we can have
// HEAP[x >> 2]
// very often. We can in some cases do the shift on the variable itself when it is set,
@ -2134,6 +2139,7 @@ var passes = {
removeAssignsToUndefined: removeAssignsToUndefined,
//removeUnneededLabelSettings: removeUnneededLabelSettings,
simplifyExpressionsPre: simplifyExpressionsPre,
simplifyExpressionsPreAsm: simplifyExpressionsPreAsm,
optimizeShiftsConservative: optimizeShiftsConservative,
optimizeShiftsAggressive: optimizeShiftsAggressive,
simplifyExpressionsPost: simplifyExpressionsPost,

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

@ -0,0 +1,4 @@
function a() {
f((HEAPU8[10202] | 0) + 5 | 0);
}

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

@ -0,0 +1,4 @@
function a() {
f((HEAPU8[10202] | 0) + 5 | 0);
}
// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a"]