summaryrefslogtreecommitdiff
path: root/src/passes/OptimizeInstructions.cpp
diff options
context:
space:
mode:
authorMax Graey <maxgraey@gmail.com>2020-10-05 23:37:43 +0300
committerGitHub <noreply@github.com>2020-10-05 13:37:43 -0700
commitfc7f66a870f6bcf17091d6cb8b7545a8e7593e7c (patch)
treebd4ecd5bdb6821e406970edfb074163ec74fe43a /src/passes/OptimizeInstructions.cpp
parent654cfca4fabda64dd91d2df9b07422b8bffc9357 (diff)
downloadbinaryen-fc7f66a870f6bcf17091d6cb8b7545a8e7593e7c.tar.gz
binaryen-fc7f66a870f6bcf17091d6cb8b7545a8e7593e7c.tar.bz2
binaryen-fc7f66a870f6bcf17091d6cb8b7545a8e7593e7c.zip
fast-math: Fold `fp * -1` to `-fp` (#3189)
Diffstat (limited to 'src/passes/OptimizeInstructions.cpp')
-rw-r--r--src/passes/OptimizeInstructions.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp
index de96e418e..3a344ff88 100644
--- a/src/passes/OptimizeInstructions.cpp
+++ b/src/passes/OptimizeInstructions.cpp
@@ -1447,8 +1447,7 @@ private:
}
{
double value;
- if (fastMath &&
- matches(curr, binary(Abstract::Sub, any(), fval(&value))) &&
+ if (matches(curr, binary(Abstract::Sub, any(), fval(&value))) &&
value == 0.0) {
// x - (-0.0) ==> x + 0.0
if (std::signbit(value)) {
@@ -1470,6 +1469,10 @@ private:
return curr->left;
}
}
+ // x * -1.0 ==> -x
+ if (fastMath && matches(curr, binary(Abstract::Mul, any(), fval(-1.0)))) {
+ return builder.makeUnary(Abstract::getUnary(type, Abstract::Neg), left);
+ }
if (matches(curr, binary(Abstract::Mul, any(&left), constant(1))) ||
matches(curr, binary(Abstract::DivS, any(&left), constant(1))) ||
matches(curr, binary(Abstract::DivU, any(&left), constant(1)))) {