diff options
author | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-02-11 13:27:04 -0800 |
---|---|---|
committer | Alon Zakai (kripken) <alonzakai@gmail.com> | 2017-02-16 22:45:37 -0800 |
commit | 2553266cf716df3f03d5d057887ed660c12f4fb6 (patch) | |
tree | 1aeb8d2c57a32bfaaa4acd8596d74502d89f5a55 /src | |
parent | f57637d7164d8a6369d2ba281559b8d3cef7bd33 (diff) | |
download | binaryen-2553266cf716df3f03d5d057887ed660c12f4fb6.tar.gz binaryen-2553266cf716df3f03d5d057887ed660c12f4fb6.tar.bz2 binaryen-2553266cf716df3f03d5d057887ed660c12f4fb6.zip |
optimize out add/sub of 0
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 51fb67065..1c549cab6 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -622,7 +622,15 @@ private: }; // find all factors seek(binary, 1); - if (constants.size() <= 1) return nullptr; // nothing to do + if (constants.size() <= 1) { + // nothing much to do, except for the trivial case of adding/subbing a zero + if (auto* c = binary->right->dynCast<Const>()) { + if (c->value.geti32() == 0) { + return binary->left; + } + } + return nullptr; + } // wipe out all constants, we'll replace with a single added one for (auto* c : constants) { c->value = Literal(int32_t(0)); |