diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-13 13:22:39 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-13 13:22:39 -0800 |
commit | dc8b20bbb26d4a10119f07b58e02a1a15eccd07c (patch) | |
tree | d2cf90091d38dc550d9d47b967c28c0c188985d0 /tools/js-optimizer.js | |
parent | 33745b7c407af78f9ea0d1c71d35ccf64e3ba2ed (diff) |
optimize & expressions more
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index c463970f..85a7b214 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -441,6 +441,32 @@ function simplifyExpressionsPre(ast) { } }, null, []); } + + // &-related optimizations + traverseGenerated(ast, function(node, type) { + if (type == 'binary' && node[1] == '&' && node[3][0] == 'num') { + var input = node[2]; + var amount = node[3][1]; + if (input[0] == 'binary' && input[1] == '&' && input[3][0] == 'num') { + // Collapse X & 255 & 1 + node[3][1] = amount & input[3][1]; + node[2] = input[2]; + } else if (input[0] == 'sub' && input[1][0] == 'name') { + // HEAP8[..] & 255 => HEAPU8[..] + var name = input[1][1]; + if (name.substr(0, 4) == 'HEAP') { + var unsigned = name[4] == 'U'; + var bits = parseInt(name.substr(unsigned ? 5 : 4)); + if (amount == Math.pow(2, bits)-1) { + if (!unsigned) { + input[1][1] = 'HEAPU' + bits; // make unsigned + } + return input; + } + } + } + } + }); } // The most common mathop is addition, e.g. in getelementptr done repeatedly. We can join all of those, |