summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/OptimizeInstructions.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index f16b0c1be..2f1b6b6a4 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -414,6 +414,31 @@ struct OptimizeInstructions
}
}
{
+ // -x + y ==> y - x
+ // where x, y are floating points
+ Expression* x;
+ if (matches(curr, binary(Add, unary(Neg, any(&x)), any()))) {
+ curr->op = Abstract::getBinary(curr->type, Sub);
+ curr->left = x;
+ std::swap(curr->left, curr->right);
+ return replaceCurrent(curr);
+ }
+ }
+ {
+ // x + (-y) ==> x - y
+ // x - (-y) ==> x + y
+ // where x, y are floating points
+ Expression* y;
+ if (matches(curr, binary(Add, any(), unary(Neg, any(&y)))) ||
+ matches(curr, binary(Sub, any(), unary(Neg, any(&y))))) {
+ curr->op = Abstract::getBinary(
+ curr->type,
+ curr->op == Abstract::getBinary(curr->type, Add) ? Sub : Add);
+ curr->right = y;
+ return replaceCurrent(curr);
+ }
+ }
+ {
// -x * -y ==> x * y
// where x, y are integers
Binary* bin;