From: Richard Biener Date: Wed, 15 Jul 2015 12:25:57 +0000 (+0000) Subject: fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var and bool_var == 1... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=55cf394666c6d7f7414e713ff6c3aa7cd9070d30;p=gcc.git fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var and bool_var == 1 -> bool_var simplifications ... 2015-07-15 Richard Biener * fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var and bool_var == 1 -> bool_var simplifications ... * match.pd: ... to patterns here. Factor out negate_expr_p cases from the A - B -> A + (-B) patterns as negate_expr_p predicate and add a -(A + B) -> (-B) - A pattern. From-SVN: r225825 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dac10abdb74..67508208735 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-07-15 Richard Biener + + * fold-const.c (fold_binary_loc): Move bool_var != 0 -> bool_var + and bool_var == 1 -> bool_var simplifications ... + * match.pd: ... to patterns here. Factor out negate_expr_p + cases from the A - B -> A + (-B) patterns as negate_expr_p + predicate and add a -(A + B) -> (-B) - A pattern. + 2015-07-15 Robert Suchanek * config/mips/mips.c (mips_emit_save_slot_move): Fix typo. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 7078edb1634..acccb3c6007 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -11245,16 +11245,6 @@ fold_binary_loc (location_t loc, if (tem != NULL_TREE) return tem; - /* bool_var != 0 becomes bool_var. */ - if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_zerop (arg1) - && code == NE_EXPR) - return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); - - /* bool_var == 1 becomes bool_var. */ - if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1) - && code == EQ_EXPR) - return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0)); - /* bool_var != 1 becomes !bool_var. */ if (TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE && integer_onep (arg1) && code == NE_EXPR) diff --git a/gcc/match.pd b/gcc/match.pd index 8bedb235788..a3fba51969e 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -479,23 +479,38 @@ along with GCC; see the file COPYING3. If not see (abs tree_expr_nonnegative_p@0) @0) -/* A - B -> A + (-B) if B is easily negatable. This just covers - very few cases of "easily negatable", effectively inlining negate_expr_p. */ -(simplify - (minus @0 INTEGER_CST@1) +/* A few cases of fold-const.c negate_expr_p predicate. */ +(match negate_expr_p + INTEGER_CST (if ((INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type)) || (!TYPE_OVERFLOW_SANITIZED (type) - && may_negate_without_overflow_p (@1))) - (plus @0 (negate @1)))) + && may_negate_without_overflow_p (t))))) +(match negate_expr_p + FIXED_CST) +(match negate_expr_p + (negate @0) + (if (!TYPE_OVERFLOW_SANITIZED (type)))) +(match negate_expr_p + REAL_CST + (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (t))))) +/* VECTOR_CST handling of non-wrapping types would recurse in unsupported + ways. */ +(match negate_expr_p + VECTOR_CST + (if (FLOAT_TYPE_P (TREE_TYPE (type)) || TYPE_OVERFLOW_WRAPS (type)))) + +/* -(A + B) -> (-B) - A. */ (simplify - (minus @0 REAL_CST@1) - (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1))) - (plus @0 (negate @1)))) + (negate (plus:c @0 negate_expr_p@1)) + (if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type)) + && !HONOR_SIGNED_ZEROS (element_mode (type))) + (minus (negate @1) @0))) + +/* A - B -> A + (-B) if B is easily negatable. */ (simplify - (minus @0 VECTOR_CST@1) - (if (FLOAT_TYPE_P (type) || TYPE_OVERFLOW_WRAPS (type)) - (plus @0 (negate @1)))) + (minus @0 negate_expr_p@1) + (plus @0 (negate @1))) /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST)) @@ -1678,6 +1693,20 @@ along with GCC; see the file COPYING3. If not see (if (tree_nop_conversion_p (TREE_TYPE (@3), TREE_TYPE (@0))) (cmp @0 (bit_xor @1 (convert @2)))))) +/* bool_var != 0 becomes bool_var. */ +(simplify + (ne @0 integer_zerop@1) + (if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE + && types_match (type, TREE_TYPE (@0))) + (non_lvalue @0))) +/* bool_var == 1 becomes bool_var. */ +(simplify + (eq @0 integer_onep@1) + (if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE + && types_match (type, TREE_TYPE (@0))) + (non_lvalue @0))) + + /* Simplification of math builtins. */ /* fold_builtin_logarithm */