match.pd: Add two abs patterns.
authorRichard Biener <rguenther@suse.de>
Mon, 3 Nov 2014 12:59:47 +0000 (12:59 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 3 Nov 2014 12:59:47 +0000 (12:59 +0000)
2014-11-03  Richard Biener  <rguenther@suse.de>

* 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

gcc/ChangeLog
gcc/fold-const.c
gcc/gimple-fold.c
gcc/match.pd

index 41a4f57c799f7879af3d35bcc08fcfadc8e8cdfb..9025278f1cfff45c430a81029bf6044b41295b2e 100644 (file)
@@ -1,3 +1,14 @@
+2014-11-03  Richard Biener  <rguenther@suse.de>
+
+       * 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  <marc.glisse@inria.fr>
 
        PR tree-optimization/60770
index 78d51829bfe20b8308aaf53bb9c824f9cc9b17ff..efcefa70c1fd86592ce8a1ebf7b85d76e9aa487d 100644 (file)
@@ -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<x>> = ABS_EXPR<x> 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)
index 088a0dd0f33ba1a20002da4cba894264f465f4fc..547f9a75c36b982568dee6e42ed73d85b0049746 100644 (file)
@@ -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:
             {
index 2057dccba46f164ff0c0a7e7b97e5a66ba0af31a..826ceb477f031caa514088327bafa3c5c3a9ccc1 100644 (file)
@@ -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)))