summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp10
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));