summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-11-30 15:02:01 -0800
committerGitHub <noreply@github.com>2016-11-30 15:02:01 -0800
commit36be3e0151dd7357e47b2d8f432bdd706a30466c (patch)
tree99a40bc874dbe786ae14eaec0e78bdcfc0ea0c86 /src/passes/OptimizeInstructions.cpp
parent7d2d9ec9f2f936d0a53b7dc60089456a0654d29c (diff)
downloadbinaryen-36be3e0151dd7357e47b2d8f432bdd706a30466c.tar.gz
binaryen-36be3e0151dd7357e47b2d8f432bdd706a30466c.tar.bz2
binaryen-36be3e0151dd7357e47b2d8f432bdd706a30466c.zip
Fix regression from #850 (#851)
* fix regression from #850 - it is not always safe to fold added offsets into load/store offsets, as the add wraps but offset does not * small refactoring to simplify asm2wasm pass invocation
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp28
1 files changed, 1 insertions, 27 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 37207ffc7..04216f1ee 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -436,33 +436,7 @@ private:
// fold constant factors into the offset
void optimizeMemoryAccess(Expression*& ptr, Address& offset) {
- while (1) {
- auto* add = ptr->dynCast<Binary>();
- if (!add) break;
- if (add->op != AddInt32) break;
- auto* left = add->left->dynCast<Const>();
- auto* right = add->right->dynCast<Const>();
- // note: in optimized code, we shouldn't see an add of two constants, so don't worry about that much
- // (precompute would optimize that)
- if (left) {
- auto value = left->value.geti32();
- if (value >= 0) {
- offset = offset + value;
- ptr = add->right;
- continue;
- }
- }
- if (right) {
- auto value = right->value.geti32();
- if (value >= 0) {
- offset = offset + value;
- ptr = add->left;
- continue;
- }
- }
- break;
- }
- // finally, ptr may be a const, but it isn't worth folding that in (we still have a const); in fact,
+ // ptr may be a const, but it isn't worth folding that in (we still have a const); in fact,
// it's better to do the opposite for gzip purposes as well as for readability.
auto* last = ptr->dynCast<Const>();
if (last) {