diff options
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 15 | ||||
-rw-r--r-- | test/passes/optimize-instructions_all-features.txt | 20 |
2 files changed, 22 insertions, 13 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))) || diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt index 1873b8d3a..b80330ad6 100644 --- a/test/passes/optimize-instructions_all-features.txt +++ b/test/passes/optimize-instructions_all-features.txt @@ -3354,15 +3354,15 @@ ) ) (drop - (f32.mul + (f32.sub + (f32.const -0) (local.get $y32) - (f32.const -1) ) ) (drop - (f64.mul + (f64.sub + (f64.const -0) (local.get $y64) - (f64.const -1) ) ) (drop @@ -4276,15 +4276,15 @@ ) ) (drop - (f32.mul + (f32.sub + (f32.const -0) (local.get $fx) - (f32.const -1) ) ) (drop - (f64.mul + (f64.sub + (f64.const -0) (local.get $fy) - (f64.const -1) ) ) (drop @@ -4362,9 +4362,9 @@ ) ) (drop - (f32.mul + (f32.sub + (f32.const -0) (local.get $fx) - (f32.const -1) ) ) (drop |