public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Merge from match-and-simplify, remove fold_unary dispatch from fold_stmt
@ 2014-10-31 14:34 Richard Biener
  2014-11-03 12:58 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2014-10-31 14:34 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1017 bytes --]

This implements the last pattern from fold_unary that covers
inputs that can come from a GIMPLE_UNARY_RHS assignment
and thus allows removal of the fold_unary dispatch from fold_stmt
and gimple_fold_stmt_to_constant_1.  Remember that to not cause
regressions it is enough to cover cases that do not need SSA
name use-def following.  Also remember that gimple_simplify
still dispatches to fold_unary for all tcc_constant operands.

The next goal is obviously to remove the GIMPLE_BINARY_RHS and
GIMPLE_TERNARY_RHS dispatches to fold_binary/ternary.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2014-10-31  Richard Biener  <rguenther@suse.de>

        * match.pd: Add two abs patterns.  Announce tree_expr_nonnegative_p.
        * 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.

[-- Attachment #2: mas-merge-10 --]
[-- Type: application/octet-stream, Size: 3963 bytes --]

2014-10-31  Richard Biener  <rguenther@suse.de>

	* match.pd: Add two abs patterns.  Announce tree_expr_nonnegative_p.
	* 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.

Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 216949)
+++ gcc/match.pd	(working copy)
@@ -27,7 +27,8 @@ along with GCC; see the file COPYING3.
 (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,6 +105,13 @@ (define_predicates
   (bitop @0 @0)
   (non_lvalue @0)))
 
+(simplify
+ (abs (negate @0))
+ (abs @0))
+(simplify
+ (abs tree_expr_nonnegative_p@0)
+ @0)
+
 
 /* Simplifications of conversions.  */
 
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 216949)
+++ gcc/fold-const.c	(working copy)
@@ -7957,8 +7957,6 @@ fold_unary_loc (location_t loc, enum tre
     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)
@@ -7973,8 +7971,6 @@ fold_unary_loc (location_t loc, enum tre
       /* 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)
@@ -15099,7 +15095,7 @@ tree_unary_nonnegative_warnv_p (enum tre
       return tree_expr_nonnegative_warnv_p (op0,
 					    strict_overflow_p);
 
-    case NOP_EXPR:
+    CASE_CONVERT:
       {
 	tree inner_type = TREE_TYPE (op0);
 	tree outer_type = type;
Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 216949)
+++ gcc/gimple-fold.c	(working copy)
@@ -417,27 +417,6 @@ fold_gimple_assign (gimple_stmt_iterator
       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:
@@ -4524,16 +4503,7 @@ gimple_fold_stmt_to_constant_1 (gimple s
             }
 
           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:
             {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Merge from match-and-simplify, remove fold_unary dispatch from fold_stmt
  2014-10-31 14:34 [PATCH] Merge from match-and-simplify, remove fold_unary dispatch from fold_stmt Richard Biener
@ 2014-11-03 12:58 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2014-11-03 12:58 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]

On Fri, Oct 31, 2014 at 2:07 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> This implements the last pattern from fold_unary that covers
> inputs that can come from a GIMPLE_UNARY_RHS assignment
> and thus allows removal of the fold_unary dispatch from fold_stmt
> and gimple_fold_stmt_to_constant_1.  Remember that to not cause
> regressions it is enough to cover cases that do not need SSA
> name use-def following.  Also remember that gimple_simplify
> still dispatches to fold_unary for all tcc_constant operands.
>
> The next goal is obviously to remove the GIMPLE_BINARY_RHS and
> GIMPLE_TERNARY_RHS dispatches to fold_binary/ternary.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

The following is what I applied.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Richard.

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.

[-- Attachment #2: mas-merge-10 --]
[-- Type: application/octet-stream, Size: 4308 bytes --]

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.

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	(revision 216949)
+++ gcc/fold-const.c	(working copy)
@@ -7957,8 +7957,6 @@ fold_unary_loc (location_t loc, enum tre
     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)
@@ -7973,8 +7971,6 @@ fold_unary_loc (location_t loc, enum tre
       /* 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)
@@ -15099,7 +15095,7 @@ tree_unary_nonnegative_warnv_p (enum tre
       return tree_expr_nonnegative_warnv_p (op0,
 					    strict_overflow_p);
 
-    case NOP_EXPR:
+    CASE_CONVERT:
       {
 	tree inner_type = TREE_TYPE (op0);
 	tree outer_type = type;
Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 216949)
+++ gcc/gimple-fold.c	(working copy)
@@ -417,27 +417,6 @@ fold_gimple_assign (gimple_stmt_iterator
       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:
@@ -4524,16 +4503,7 @@ gimple_fold_stmt_to_constant_1 (gimple s
             }
 
           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: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 216977)
+++ gcc/match.pd	(working copy)
@@ -27,7 +27,8 @@ along with GCC; see the file COPYING3.
 (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 @@ (define_predicates
   (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)))

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-03 12:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-31 14:34 [PATCH] Merge from match-and-simplify, remove fold_unary dispatch from fold_stmt Richard Biener
2014-11-03 12:58 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).