From: Marc Glisse Date: Tue, 26 May 2015 11:14:16 +0000 (+0200) Subject: match.pd (swapped_tcc_comparison): New operator list. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=534bd33b61d08e0bf4d58efbeb3da5a368f8a247;p=gcc.git match.pd (swapped_tcc_comparison): New operator list. 2015-05-26 Marc Glisse * match.pd (swapped_tcc_comparison): New operator list. (-A CMP -B): New simplification. * fold-const.c (fold_comparison): Remove corresponding code. From-SVN: r223689 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d4107ca584c..3197dfcfe47 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-05-26 Marc Glisse + + * 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 * caller-save.c (init_caller_save): Base temporary register numbers diff --git a/gcc/fold-const.c b/gcc/fold-const.c index c38a63336d3..5545ecf3b97 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9183,24 +9183,11 @@ fold_comparison (location_t loc, enum tree_code code, tree type, 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)) diff --git a/gcc/match.pd b/gcc/match.pd index 3ac36455278..1e46677d525 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -38,6 +38,8 @@ along with GCC; see the file COPYING3. If not see 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 @@ -980,6 +982,24 @@ along with GCC; see the file COPYING3. If not see (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)