From 2fdb22bc26185e94ccd775bbfe8ea271be03df45 Mon Sep 17 00:00:00 2001 From: Max Graey Date: Thu, 15 Sep 2022 23:17:51 +0300 Subject: [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 --- src/ir/properties.h | 4 ++++ src/passes/OptimizeInstructions.cpp | 19 +++++-------------- 2 files changed, 9 insertions(+), 14 deletions(-) (limited to 'src') 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 @@ -3507,20 +3507,6 @@ private: return curr; } } - { - 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 @@ -4709,6 +4695,11 @@ private: return true; } switch (binary->op) { + case SubFloat32: + case SubFloat64: { + // Should apply x - C -> x + (-C) + return binary->right->is(); + } case AddFloat32: case MulFloat32: case AddFloat64: -- cgit v1.2.3