diff options
author | Max Graey <maxgraey@gmail.com> | 2022-09-15 23:17:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-15 13:17:51 -0700 |
commit | 2fdb22bc26185e94ccd775bbfe8ea271be03df45 (patch) | |
tree | 7c9935698de035f905eafc247f547af6acd3aea1 /src | |
parent | 0d8aff6d85850a5f05ed6f5dc359f1b93120769d (diff) | |
download | binaryen-2fdb22bc26185e94ccd775bbfe8ea271be03df45.tar.gz binaryen-2fdb22bc26185e94ccd775bbfe8ea271be03df45.tar.bz2 binaryen-2fdb22bc26185e94ccd775bbfe8ea271be03df45.zip |
[OptimizeInstructions] More canonizations for floating points (#5033)
x - C -> x + (-C)
min(C, x) -> min(x, C)
max(C, x) -> max(x, C)
And remove redundant rules
Diffstat (limited to 'src')
-rw-r--r-- | src/ir/properties.h | 4 | ||||
-rw-r--r-- | src/passes/OptimizeInstructions.cpp | 19 |
2 files changed, 9 insertions, 14 deletions
diff --git a/src/ir/properties.h b/src/ir/properties.h index 1d2937d81..a32a737ef 100644 --- a/src/ir/properties.h +++ b/src/ir/properties.h @@ -42,8 +42,12 @@ inline bool isSymmetric(Binary* binary) { case EqInt64: case NeInt64: + case MinFloat32: + case MaxFloat32: case EqFloat32: case NeFloat32: + case MinFloat64: + case MaxFloat64: case EqFloat64: case NeFloat64: return true; diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 286bfd2b6..f16b0c1be 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -3508,20 +3508,6 @@ private: } } { - double value; - if (matches(curr, binary(Sub, any(), fval(&value))) && value == 0.0) { - // x - (-0.0) ==> x + 0.0 - if (std::signbit(value)) { - curr->op = Abstract::getBinary(type, Add); - right->value = right->value.neg(); - return curr; - } else if (fastMath) { - // x - 0.0 ==> x - return curr->left; - } - } - } - { // x * 2.0 ==> x + x // but we apply this only for simple expressions like // local.get and global.get for avoid using extra local @@ -4709,6 +4695,11 @@ private: return true; } switch (binary->op) { + case SubFloat32: + case SubFloat64: { + // Should apply x - C -> x + (-C) + return binary->right->is<Const>(); + } case AddFloat32: case MulFloat32: case AddFloat64: |