From: Richard Biener Date: Mon, 3 Nov 2014 12:59:47 +0000 (+0000) Subject: match.pd: Add two abs patterns. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f3582e541c61d1ae2f859d1c83ba6559fd5eccfb;p=gcc.git match.pd: Add two abs patterns. 2014-11-03 Richard Biener * match.pd: Add two abs patterns. Announce tree_expr_nonnegative_p. Also drop bogus FLOAT_EXPR and FIX_TRUNC_EXPR. * fold-const.c (fold_unary_loc): Remove them here. (tree_unary_nonnegative_warnv_p): Use CASE_CONVERT. * gimple-fold.c (fold_gimple_assign): Remove now obsolete GIMPLE_UNARY_RHS case. (gimple_fold_stmt_to_constant_1): Likewise. (replace_stmt_with_simplification): Fix inverted comparison. From-SVN: r217039 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 41a4f57c799..9025278f1cf 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2014-11-03 Richard Biener + + * match.pd: Add two abs patterns. Announce tree_expr_nonnegative_p. + Also drop bogus FLOAT_EXPR and FIX_TRUNC_EXPR. + * fold-const.c (fold_unary_loc): Remove them here. + (tree_unary_nonnegative_warnv_p): Use CASE_CONVERT. + * gimple-fold.c (fold_gimple_assign): Remove now obsolete + GIMPLE_UNARY_RHS case. + (gimple_fold_stmt_to_constant_1): Likewise. + (replace_stmt_with_simplification): Fix inverted comparison. + 2014-11-03 Marc Glisse PR tree-optimization/60770 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 78d51829bfe..efcefa70c1f 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7958,8 +7958,6 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0) case ABS_EXPR: if (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST) return fold_abs_const (arg0, type); - else if (TREE_CODE (arg0) == NEGATE_EXPR) - return fold_build1_loc (loc, ABS_EXPR, type, TREE_OPERAND (arg0, 0)); /* Convert fabs((double)float) into (double)fabsf(float). */ else if (TREE_CODE (arg0) == NOP_EXPR && TREE_CODE (type) == REAL_TYPE) @@ -7974,8 +7972,6 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0) /* ABS_EXPR> = ABS_EXPR even if flag_wrapv is on. */ else if (TREE_CODE (arg0) == ABS_EXPR) return arg0; - else if (tree_expr_nonnegative_p (arg0)) - return arg0; /* Strip sign ops from argument. */ if (TREE_CODE (type) == REAL_TYPE) diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 088a0dd0f33..547f9a75c36 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -417,27 +417,6 @@ fold_gimple_assign (gimple_stmt_iterator *si) break; case GIMPLE_UNARY_RHS: - { - tree rhs = gimple_assign_rhs1 (stmt); - - result = fold_unary_loc (loc, subcode, gimple_expr_type (stmt), rhs); - if (result) - { - /* If the operation was a conversion do _not_ mark a - resulting constant with TREE_OVERFLOW if the original - constant was not. These conversions have implementation - defined behavior and retaining the TREE_OVERFLOW flag - here would confuse later passes such as VRP. */ - if (CONVERT_EXPR_CODE_P (subcode) - && TREE_CODE (result) == INTEGER_CST - && TREE_CODE (rhs) == INTEGER_CST) - TREE_OVERFLOW (result) = TREE_OVERFLOW (rhs); - - STRIP_USELESS_TYPE_CONVERSION (result); - if (valid_gimple_rhs_p (result)) - return result; - } - } break; case GIMPLE_BINARY_RHS: @@ -2876,7 +2855,7 @@ replace_stmt_with_simplification (gimple_stmt_iterator *gsi, && rcode.is_tree_code ()) { if (!inplace - || gimple_num_ops (stmt) <= get_gimple_rhs_num_ops (rcode)) + || gimple_num_ops (stmt) > get_gimple_rhs_num_ops (rcode)) { maybe_build_generic_op (rcode, TREE_TYPE (gimple_assign_lhs (stmt)), @@ -4523,16 +4502,7 @@ gimple_fold_stmt_to_constant_1 (gimple stmt, tree (*valueize) (tree)) } case GIMPLE_UNARY_RHS: - { - /* Handle unary operators that can appear in GIMPLE form. - Note that we know the single operand must be a constant, - so this should almost always return a simplified RHS. */ - tree op0 = (*valueize) (gimple_assign_rhs1 (stmt)); - - return - fold_unary_ignore_overflow_loc (loc, subcode, - gimple_expr_type (stmt), op0); - } + return NULL_TREE; case GIMPLE_BINARY_RHS: { diff --git a/gcc/match.pd b/gcc/match.pd index 2057dccba46..826ceb477f0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -27,7 +27,8 @@ along with GCC; see the file COPYING3. If not see (define_predicates integer_onep integer_zerop integer_all_onesp real_zerop real_onep - CONSTANT_CLASS_P) + CONSTANT_CLASS_P + tree_expr_nonnegative_p) /* Simplifications of operations with one constant operand and @@ -104,11 +105,18 @@ along with GCC; see the file COPYING3. If not see (bitop @0 @0) (non_lvalue @0))) +(simplify + (abs (negate @0)) + (abs @0)) +(simplify + (abs tree_expr_nonnegative_p@0) + @0) + /* Simplifications of conversions. */ /* Basic strip-useless-type-conversions / strip_nops. */ -(for cvt (convert view_convert) +(for cvt (convert view_convert float fix_trunc) (simplify (cvt @0) (if ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@0)))