+2015-05-26 Marc Glisse <marc.glisse@inria.fr>
+
+ * match.pd (swapped_tcc_comparison): New operator list.
+ (-A CMP -B): New simplification.
+ * fold-const.c (fold_comparison): Remove corresponding code.
+
2015-05-26 Richard Sandiford <richard.sandiford@arm.com>
* caller-save.c (init_caller_save): Base temporary register numbers
fold_convert_loc (loc, newtype, targ0),
fold_convert_loc (loc, newtype, targ1));
- /* (-a) CMP (-b) -> b CMP a */
- if (TREE_CODE (arg0) == NEGATE_EXPR
- && TREE_CODE (arg1) == NEGATE_EXPR)
- return fold_build2_loc (loc, code, type, TREE_OPERAND (arg1, 0),
- TREE_OPERAND (arg0, 0));
-
if (TREE_CODE (arg1) == REAL_CST)
{
REAL_VALUE_TYPE cst;
cst = TREE_REAL_CST (arg1);
- /* (-a) CMP CST -> a swap(CMP) (-CST) */
- if (TREE_CODE (arg0) == NEGATE_EXPR)
- return fold_build2_loc (loc, swap_tree_comparison (code), type,
- TREE_OPERAND (arg0, 0),
- build_real (TREE_TYPE (arg1),
- real_value_negate (&cst)));
-
/* IEEE doesn't distinguish +0 and -0 in comparisons. */
/* a CMP (-0) -> a CMP 0 */
if (REAL_VALUE_MINUS_ZERO (cst))
ge gt ne eq lt le ordered unordered ge gt le lt ltgt uneq)
(define_operator_list inverted_tcc_comparison_with_nans
unge ungt ne eq unlt unle ordered unordered ge gt le lt ltgt uneq)
+(define_operator_list swapped_tcc_comparison
+ gt ge eq ne le lt unordered ordered ungt unge unlt unle uneq ltgt)
/* Simplifications of operations with one constant operand and
(bit_and:c (ordered @0 @0) (ordered:c@2 @0 @1))
@2)
+/* -A CMP -B -> B CMP A. */
+(for cmp (tcc_comparison)
+ scmp (swapped_tcc_comparison)
+ (simplify
+ (cmp (negate @0) (negate @1))
+ (if (FLOAT_TYPE_P (TREE_TYPE (@0))
+ || (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))))
+ (scmp @0 @1)))
+ (simplify
+ (cmp (negate @0) CONSTANT_CLASS_P@1)
+ (if (FLOAT_TYPE_P (TREE_TYPE (@0))
+ || (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))))
+ (with { tree tem = fold_unary (NEGATE_EXPR, TREE_TYPE (@0), @1); }
+ (if (tem && !TREE_OVERFLOW (tem))
+ (scmp @0 { tem; }))))))
+
/* Simplification of math builtins. */
(define_operator_list LOG BUILT_IN_LOGF BUILT_IN_LOG BUILT_IN_LOGL)