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.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index 003f204a9..9b47f6a0f 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1697,9 +1697,18 @@ private:
curr->left = left;
return curr;
}
- // x * -1.0 ==> -x
- if (fastMath && matches(curr, binary(Mul, any(), fval(-1.0)))) {
- return builder.makeUnary(Abstract::getUnary(type, Neg), left);
+ // x * -1.0 ==>
+ // -x, if fastMath == true
+ // -0.0 - x, if fastMath == false
+ if (matches(curr, binary(Mul, any(), fval(-1.0)))) {
+ if (fastMath) {
+ return builder.makeUnary(Abstract::getUnary(type, Neg), left);
+ }
+ // x * -1.0 ==> -0.0 - x
+ curr->op = Abstract::getBinary(type, Sub);
+ right->value = Literal::makeZero(type).neg();
+ std::swap(curr->left, curr->right);
+ return curr;
}
if (matches(curr, binary(Mul, any(&left), constant(1))) ||
matches(curr, binary(DivS, any(&left), constant(1))) ||