[PATCH][9/n] Merge from match-and-simplify, more patterns

Richard Biener rguenther@suse.de
Thu Oct 30 13:58:00 GMT 2014


On Thu, 30 Oct 2014, Richard Biener wrote:

> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Oops, posted the wrong patch.  The following is correct - I've
removed the single-use restriction as no patterns would behave
badly but stuff like x & x wouldn't match.

Richard.

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

	* match.pd: Implement more patterns that simplify to a single value.
	* fold-const.c (fold_binary_loc): Remove them here.
	* tree-ssa-forwprop.c (simplify_bitwise_binary): Likewise.
	(fwprop_ssa_val): Remove restriction on single uses.

Index: trunk/gcc/fold-const.c
===================================================================
*** trunk.orig/gcc/fold-const.c	2014-10-30 14:02:58.477371843 +0100
--- trunk/gcc/fold-const.c	2014-10-30 14:03:05.829371337 +0100
*************** fold_binary_loc (location_t loc,
*** 11089,11097 ****
  
      case BIT_IOR_EXPR:
      bit_ior:
-       if (operand_equal_p (arg0, arg1, 0))
- 	return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
- 
        /* ~X | X is -1.  */
        if (TREE_CODE (arg0) == BIT_NOT_EXPR
  	  && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
--- 11089,11094 ----
*************** fold_binary_loc (location_t loc,
*** 11227,11235 ****
        goto bit_rotate;
  
      case BIT_XOR_EXPR:
-       if (integer_all_onesp (arg1))
- 	return fold_build1_loc (loc, BIT_NOT_EXPR, type, op0);
- 
        /* ~X ^ X is -1.  */
        if (TREE_CODE (arg0) == BIT_NOT_EXPR
  	  && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
--- 11224,11229 ----
*************** fold_binary_loc (location_t loc,
*** 11384,11394 ****
        goto bit_rotate;
  
      case BIT_AND_EXPR:
-       if (integer_all_onesp (arg1))
- 	return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
-       if (operand_equal_p (arg0, arg1, 0))
- 	return non_lvalue_loc (loc, fold_convert_loc (loc, type, arg0));
- 
        /* ~X & X, (X == 0) & X, and !X & X are always zero.  */
        if ((TREE_CODE (arg0) == BIT_NOT_EXPR
  	   || TREE_CODE (arg0) == TRUTH_NOT_EXPR
--- 11378,11383 ----
Index: trunk/gcc/match.pd
===================================================================
*** trunk.orig/gcc/match.pd	2014-10-30 14:02:58.477371843 +0100
--- trunk/gcc/match.pd	2014-10-30 14:04:22.869366033 +0100
*************** along with GCC; see the file COPYING3.
*** 31,37 ****
  
  
  /* Simplifications of operations with one constant operand and
!    simplifications to constants.  */
  
  (for op (plus pointer_plus minus bit_ior bit_xor)
    (simplify
--- 31,37 ----
  
  
  /* Simplifications of operations with one constant operand and
!    simplifications to constants or single values.  */
  
  (for op (plus pointer_plus minus bit_ior bit_xor)
    (simplify
*************** along with GCC; see the file COPYING3.
*** 88,93 ****
--- 88,109 ----
    (bit_xor @0 @0)
    { build_zero_cst (type); })
  
+ /* Canonicalize X ^ ~0 to ~X.  */
+ (simplify
+   (bit_xor @0 integer_all_onesp@1)
+   (bit_not @0))
+ 
+ /* x & ~0 -> x  */
+ (simplify
+  (bit_and @0 integer_all_onesp)
+   (non_lvalue @0))
+ 
+ /* x & x -> x,  x | x -> x  */
+ (for bitop (bit_and bit_ior)
+  (simplify
+   (bitop @0 @0)
+   (non_lvalue @0)))
+ 
  
  /* Simplifications of conversions.  */
  
Index: trunk/gcc/tree-ssa-forwprop.c
===================================================================
*** trunk.orig/gcc/tree-ssa-forwprop.c	2014-10-30 14:02:58.477371843 +0100
--- trunk/gcc/tree-ssa-forwprop.c	2014-10-30 14:03:05.830371337 +0100
*************** simplify_bitwise_binary (gimple_stmt_ite
*** 2097,2112 ****
        return true;
      }
  
-   /* Canonicalize X ^ ~0 to ~X.  */
-   if (code == BIT_XOR_EXPR
-       && integer_all_onesp (arg2))
-     {
-       gimple_assign_set_rhs_with_ops (gsi, BIT_NOT_EXPR, arg1, NULL_TREE);
-       gcc_assert (gsi_stmt (*gsi) == stmt);
-       update_stmt (stmt);
-       return true;
-     }
- 
    /* Try simple folding for X op !X, and X op X.  */
    res = simplify_bitwise_binary_1 (code, TREE_TYPE (arg1), arg1, arg2);
    if (res != NULL_TREE)
--- 2097,2102 ----



More information about the Gcc-patches mailing list