[PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Richard Biener

This merges patterns implementing the bitwise patterns from 
tree-ssa-forwprop.c.  I've removed duplicate functionality from
fold-const.c as I found them, some may be still lurking in the
depths.

This also fixes a bug in genmatch which made user-defined predicates
matching anything, thus

(match foo
 @0
 (if ...

not work (that is: ignored).

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

Richard.

2014-11-06  Richard Biener  

* match.pd: Implement bitwise binary and unary simplifications
from tree-ssa-forwprop.c.
* fold-const.c (fold_unary_loc): Remove them here.
(fold_binary_loc): Likewise.
* tree-ssa-forwprop.c (simplify_not_neg_expr): Remove.
(truth_valued_ssa_name): Likewise.
(lookup_logical_inverted_value): Likewise.
(simplify_bitwise_binary_1): Likewise.
(hoist_conversion_for_bitop_p): Likewise.
(simplify_bitwise_binary_boolean): Likewise.
(simplify_bitwise_binary): Likewise.
(pass_forwprop::execute): Remove calls to simplify_not_neg_expr
and simplify_bitwise_binary.
* genmatch.c (dt_node::append_true_op): Use safe_as_a for parent.
(decision_tree::insert): Also insert non-expressions.

* gcc.dg/tree-ssa/forwprop-28.c: Adjust scanning for the
desired transform.

Index: trunk/gcc/fold-const.c
===
--- trunk.orig/gcc/fold-const.c 2014-11-05 13:31:01.131942296 +0100
+++ trunk/gcc/fold-const.c  2014-11-05 13:35:29.362930558 +0100
@@ -8008,8 +8008,6 @@ fold_unary_loc (location_t loc, enum tre
 case BIT_NOT_EXPR:
   if (TREE_CODE (arg0) == INTEGER_CST)
 return fold_not_const (arg0, type);
-  else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
-   return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
   /* Convert ~ (-A) to A - 1.  */
   else if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR)
return fold_build2_loc (loc, MINUS_EXPR, type,
@@ -11152,26 +11150,6 @@ fold_binary_loc (location_t loc,
arg1);
}
 
-  /* (X & Y) | Y is (X, Y).  */
-  if (TREE_CODE (arg0) == BIT_AND_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
-   return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0));
-  /* (X & Y) | X is (Y, X).  */
-  if (TREE_CODE (arg0) == BIT_AND_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
- && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
-   return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1));
-  /* X | (X & Y) is (Y, X).  */
-  if (TREE_CODE (arg1) == BIT_AND_EXPR
- && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)
- && reorder_operands_p (arg0, TREE_OPERAND (arg1, 1)))
-   return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 1));
-  /* X | (Y & X) is (Y, X).  */
-  if (TREE_CODE (arg1) == BIT_AND_EXPR
- && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)
- && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
-   return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 0));
-
   /* (X & ~Y) | (~X & Y) is X ^ Y */
   if (TREE_CODE (arg0) == BIT_AND_EXPR
  && TREE_CODE (arg1) == BIT_AND_EXPR)
@@ -11391,42 +11369,6 @@ fold_binary_loc (location_t loc,
  && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
 
-  /* Canonicalize (X | C1) & C2 as (X & C2) | (C1 & C2).  */
-  if (TREE_CODE (arg0) == BIT_IOR_EXPR
- && TREE_CODE (arg1) == INTEGER_CST
- && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
-   {
- tree tmp1 = fold_convert_loc (loc, type, arg1);
- tree tmp2 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
- tree tmp3 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
- tmp2 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp2, tmp1);
- tmp3 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp3, tmp1);
- return
-   fold_convert_loc (loc, type,
- fold_build2_loc (loc, BIT_IOR_EXPR,
-  type, tmp2, tmp3));
-   }
-
-  /* (X | Y) & Y is (X, Y).  */
-  if (TREE_CODE (arg0) == BIT_IOR_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
-   return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0));
-  /* (X | Y) & X is (Y, X).  */
-  if (TREE_CODE (arg0) == BIT_IOR_EXPR
- && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
- && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
-   return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1));
-  /* X & (X | Y) is (Y, X).  */
-  if (TREE_CODE (arg1) == BIT_IOR_EXPR
- && operand_equal_p (arg0, TREE_OPER

Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread pinskia




> On Nov 6, 2014, at 12:55 AM, Richard Biener  wrote:
> 
> 
> This merges patterns implementing the bitwise patterns from 
> tree-ssa-forwprop.c.  I've removed duplicate functionality from
> fold-const.c as I found them, some may be still lurking in the
> depths.
> 
> This also fixes a bug in genmatch which made user-defined predicates
> matching anything, thus
> 
> (match foo
> @0
> (if ...
> 
> not work (that is: ignored).
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Only one small comment. 

> 
> Richard.
> 
> 2014-11-06  Richard Biener  
> 
>* match.pd: Implement bitwise binary and unary simplifications
>from tree-ssa-forwprop.c.
>* fold-const.c (fold_unary_loc): Remove them here.
>(fold_binary_loc): Likewise.
>* tree-ssa-forwprop.c (simplify_not_neg_expr): Remove.
>(truth_valued_ssa_name): Likewise.
>(lookup_logical_inverted_value): Likewise.
>(simplify_bitwise_binary_1): Likewise.
>(hoist_conversion_for_bitop_p): Likewise.
>(simplify_bitwise_binary_boolean): Likewise.
>(simplify_bitwise_binary): Likewise.
>(pass_forwprop::execute): Remove calls to simplify_not_neg_expr
>and simplify_bitwise_binary.
>* genmatch.c (dt_node::append_true_op): Use safe_as_a for parent.
>(decision_tree::insert): Also insert non-expressions.
> 
>* gcc.dg/tree-ssa/forwprop-28.c: Adjust scanning for the
>desired transform.
> 
> Index: trunk/gcc/fold-const.c
> ===
> --- trunk.orig/gcc/fold-const.c2014-11-05 13:31:01.131942296 +0100
> +++ trunk/gcc/fold-const.c2014-11-05 13:35:29.362930558 +0100
> @@ -8008,8 +8008,6 @@ fold_unary_loc (location_t loc, enum tre
> case BIT_NOT_EXPR:
>   if (TREE_CODE (arg0) == INTEGER_CST)
> return fold_not_const (arg0, type);
> -  else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
> -return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
>   /* Convert ~ (-A) to A - 1.  */
>   else if (INTEGRAL_TYPE_P (type) && TREE_CODE (arg0) == NEGATE_EXPR)
>return fold_build2_loc (loc, MINUS_EXPR, type,
> @@ -11152,26 +11150,6 @@ fold_binary_loc (location_t loc,
>arg1);
>}
> 
> -  /* (X & Y) | Y is (X, Y).  */
> -  if (TREE_CODE (arg0) == BIT_AND_EXPR
> -  && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
> -return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0));
> -  /* (X & Y) | X is (Y, X).  */
> -  if (TREE_CODE (arg0) == BIT_AND_EXPR
> -  && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
> -  && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
> -return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1));
> -  /* X | (X & Y) is (Y, X).  */
> -  if (TREE_CODE (arg1) == BIT_AND_EXPR
> -  && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)
> -  && reorder_operands_p (arg0, TREE_OPERAND (arg1, 1)))
> -return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 1));
> -  /* X | (Y & X) is (Y, X).  */
> -  if (TREE_CODE (arg1) == BIT_AND_EXPR
> -  && operand_equal_p (arg0, TREE_OPERAND (arg1, 1), 0)
> -  && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
> -return omit_one_operand_loc (loc, type, arg0, TREE_OPERAND (arg1, 0));
> -
>   /* (X & ~Y) | (~X & Y) is X ^ Y */
>   if (TREE_CODE (arg0) == BIT_AND_EXPR
>  && TREE_CODE (arg1) == BIT_AND_EXPR)
> @@ -11391,42 +11369,6 @@ fold_binary_loc (location_t loc,
>  && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
>return omit_one_operand_loc (loc, type, integer_zero_node, arg0);
> 
> -  /* Canonicalize (X | C1) & C2 as (X & C2) | (C1 & C2).  */
> -  if (TREE_CODE (arg0) == BIT_IOR_EXPR
> -  && TREE_CODE (arg1) == INTEGER_CST
> -  && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
> -{
> -  tree tmp1 = fold_convert_loc (loc, type, arg1);
> -  tree tmp2 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
> -  tree tmp3 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
> -  tmp2 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp2, tmp1);
> -  tmp3 = fold_build2_loc (loc, BIT_AND_EXPR, type, tmp3, tmp1);
> -  return
> -fold_convert_loc (loc, type,
> -  fold_build2_loc (loc, BIT_IOR_EXPR,
> -   type, tmp2, tmp3));
> -}
> -
> -  /* (X | Y) & Y is (X, Y).  */
> -  if (TREE_CODE (arg0) == BIT_IOR_EXPR
> -  && operand_equal_p (TREE_OPERAND (arg0, 1), arg1, 0))
> -return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 0));
> -  /* (X | Y) & X is (Y, X).  */
> -  if (TREE_CODE (arg0) == BIT_IOR_EXPR
> -  && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
> -  && reorder_operands_p (TREE_OPERAND (arg0, 1), arg1))
> -return omit_one_operand_loc (loc, type, arg1, TREE_OPERAND (arg0, 1));
> -  /* X & (X | Y) is (Y, X).  */
> -  if (TREE_CODE (arg1) ==

Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Marc Glisse

On Thu, 6 Nov 2014, Richard Biener wrote:


+/* Simplify (A & B) OP0 (C & B) to (A OP0 C) & B. */



+/* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */


As soon as there are 2+ operations in the result, this comment in 
fwprop_ssa_val becomes outdated, no?


  /* We continue matching along SSA use-def edges for SSA names
 that are not single-use.  Currently there are no patterns
 that would cause any issues with that.  */

(I am not opposing the patch, just trying to understand how things work 
for when I'll propose new patterns)


--
Marc Glisse


Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Marc Glisse

On Thu, 6 Nov 2014, Richard Biener wrote:


+/* Try simple folding for X op !X, and X op X with the help
+   of the truth_valued_p and logical_inverted_value predicates.  */
+(match truth_valued_p
+ @0
+ (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1)))
+(for op (lt le eq ne ge gt truth_and truth_andif truth_or truth_orif truth_xor)
+ (match truth_valued_p
+  (op @0 @1)))
+(match truth_valued_p
+  (truth_not @0))
+
+(match (logical_inverted_value @0)
+ (bit_not truth_valued_p@0))
+(match (logical_inverted_value @0)
+ (eq @0 integer_zerop)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
+(match (logical_inverted_value @0)
+ (ne truth_valued_p@0 integer_onep)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
+(match (logical_inverted_value @0)
+ (bit_xor truth_valued_p@0 integer_onep))
+
+/* X & !X -> 0.  */
+(simplify
+ (bit_and:c @0 (logical_inverted_value @0))
+ { build_zero_cst (type); })
+/* X | !X and X ^ !X -> 1, , if X is truth-valued.  */
+(for op (bit_ior bit_xor)
+ (simplify
+  (op:c truth_valued_p@0 (logical_inverted_value @0))
+  { build_one_cst (type); }))


Shouldn't that be build_true_cst (type) so it is -1 for vectors? It
seems that it could match:
vec a, b;
vec c=a

Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Richard Biener
On Thu, 6 Nov 2014, Marc Glisse wrote:

> On Thu, 6 Nov 2014, Richard Biener wrote:
> 
> > +/* Simplify (A & B) OP0 (C & B) to (A OP0 C) & B. */
> 
> > +/* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
> 
> As soon as there are 2+ operations in the result, this comment in
> fwprop_ssa_val becomes outdated, no?

Yes, but in the above case the 2nd operand of the outer | folds
to a constant, thus the whole expression only uses a single SSA
name.  Btw, I was careful to only convert patterns from 
tree-ssa-forwprop.c that do not care about the number of uses
(if you look there are not many that do - mainly all the
comparison simplification)

>   /* We continue matching along SSA use-def edges for SSA names
>  that are not single-use.  Currently there are no patterns
>  that would cause any issues with that.  */
> 
> (I am not opposing the patch, just trying to understand how things work for
> when I'll propose new patterns)

If it's entirely new patterns and the pattern is a simplification
I wouldn't care about single-uses.  CSE is supposed to fix things up
for us.  Exceptions may apply if for example the operation we transform
to is more expensive than the two we combine it from.

But well - apply common sense.

I am currently trying to make us not regress ;)  (I don't expect
to get to replace the comparison simplification tree-ssa-forwprop.c
does with patterns as fold_comparison and friends has so many
transforms with "interesting" implementations - not during this
stage1 at least)

Richard.


Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Richard Biener
On Thu, 6 Nov 2014, Marc Glisse wrote:

> On Thu, 6 Nov 2014, Richard Biener wrote:
> 
> > +/* Try simple folding for X op !X, and X op X with the help
> > +   of the truth_valued_p and logical_inverted_value predicates.  */
> > +(match truth_valued_p
> > + @0
> > + (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1)))
> > +(for op (lt le eq ne ge gt truth_and truth_andif truth_or truth_orif
> > truth_xor)
> > + (match truth_valued_p
> > +  (op @0 @1)))
> > +(match truth_valued_p
> > +  (truth_not @0))
> > +
> > +(match (logical_inverted_value @0)
> > + (bit_not truth_valued_p@0))
> > +(match (logical_inverted_value @0)
> > + (eq @0 integer_zerop)
> > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
> > +(match (logical_inverted_value @0)
> > + (ne truth_valued_p@0 integer_onep)
> > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
> > +(match (logical_inverted_value @0)
> > + (bit_xor truth_valued_p@0 integer_onep))
> > +
> > +/* X & !X -> 0.  */
> > +(simplify
> > + (bit_and:c @0 (logical_inverted_value @0))
> > + { build_zero_cst (type); })
> > +/* X | !X and X ^ !X -> 1, , if X is truth-valued.  */
> > +(for op (bit_ior bit_xor)
> > + (simplify
> > +  (op:c truth_valued_p@0 (logical_inverted_value @0))
> > +  { build_one_cst (type); }))
> 
> Shouldn't that be build_true_cst (type) so it is -1 for vectors? It
> seems that it could match:
> vec a, b;
> vec c=a vec d=~c;
> vec e=c|d;

Probably.  Note that I copied this from tree-ssa-forwprop.c.

Generally I try to avoid fixing bugs or improving things at this point
to make the transition more obvious.

Richard.


Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Marc Glisse

On Thu, 6 Nov 2014, Richard Biener wrote:


On Thu, 6 Nov 2014, Marc Glisse wrote:


On Thu, 6 Nov 2014, Richard Biener wrote:


+/* Try simple folding for X op !X, and X op X with the help
+   of the truth_valued_p and logical_inverted_value predicates.  */
+(match truth_valued_p
+ @0
+ (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1)))
+(for op (lt le eq ne ge gt truth_and truth_andif truth_or truth_orif
truth_xor)
+ (match truth_valued_p
+  (op @0 @1)))
+(match truth_valued_p
+  (truth_not @0))
+
+(match (logical_inverted_value @0)
+ (bit_not truth_valued_p@0))
+(match (logical_inverted_value @0)
+ (eq @0 integer_zerop)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
+(match (logical_inverted_value @0)
+ (ne truth_valued_p@0 integer_onep)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
+(match (logical_inverted_value @0)
+ (bit_xor truth_valued_p@0 integer_onep))
+
+/* X & !X -> 0.  */
+(simplify
+ (bit_and:c @0 (logical_inverted_value @0))
+ { build_zero_cst (type); })
+/* X | !X and X ^ !X -> 1, , if X is truth-valued.  */
+(for op (bit_ior bit_xor)
+ (simplify
+  (op:c truth_valued_p@0 (logical_inverted_value @0))
+  { build_one_cst (type); }))


Shouldn't that be build_true_cst (type) so it is -1 for vectors? It
seems that it could match:
vec a, b;
vec c=a

Probably.  Note that I copied this from tree-ssa-forwprop.c.

Generally I try to avoid fixing bugs or improving things at this point
to make the transition more obvious.


But truth_valued_ssa_name starts with:

  if (!INTEGRAL_TYPE_P (type))
return false;

so it does not match vectors. lookup_logical_inverted_value has a similar 
test.


--
Marc Glisse


Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Richard Biener
On Thu, 6 Nov 2014, Marc Glisse wrote:

> On Thu, 6 Nov 2014, Richard Biener wrote:
> 
> > On Thu, 6 Nov 2014, Marc Glisse wrote:
> > 
> > > On Thu, 6 Nov 2014, Richard Biener wrote:
> > > 
> > > > +/* Try simple folding for X op !X, and X op X with the help
> > > > +   of the truth_valued_p and logical_inverted_value predicates.  */
> > > > +(match truth_valued_p
> > > > + @0
> > > > + (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1)))
> > > > +(for op (lt le eq ne ge gt truth_and truth_andif truth_or truth_orif
> > > > truth_xor)
> > > > + (match truth_valued_p
> > > > +  (op @0 @1)))
> > > > +(match truth_valued_p
> > > > +  (truth_not @0))
> > > > +
> > > > +(match (logical_inverted_value @0)
> > > > + (bit_not truth_valued_p@0))
> > > > +(match (logical_inverted_value @0)
> > > > + (eq @0 integer_zerop)
> > > > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
> > > > +(match (logical_inverted_value @0)
> > > > + (ne truth_valued_p@0 integer_onep)
> > > > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
> > > > +(match (logical_inverted_value @0)
> > > > + (bit_xor truth_valued_p@0 integer_onep))
> > > > +
> > > > +/* X & !X -> 0.  */
> > > > +(simplify
> > > > + (bit_and:c @0 (logical_inverted_value @0))
> > > > + { build_zero_cst (type); })
> > > > +/* X | !X and X ^ !X -> 1, , if X is truth-valued.  */
> > > > +(for op (bit_ior bit_xor)
> > > > + (simplify
> > > > +  (op:c truth_valued_p@0 (logical_inverted_value @0))
> > > > +  { build_one_cst (type); }))
> > > 
> > > Shouldn't that be build_true_cst (type) so it is -1 for vectors? It
> > > seems that it could match:
> > > vec a, b;
> > > vec c=a > > vec d=~c;
> > > vec e=c|d;
> > 
> > Probably.  Note that I copied this from tree-ssa-forwprop.c.
> > 
> > Generally I try to avoid fixing bugs or improving things at this point
> > to make the transition more obvious.
> 
> But truth_valued_ssa_name starts with:
> 
>   if (!INTEGRAL_TYPE_P (type))
> return false;
> 
> so it does not match vectors. lookup_logical_inverted_value has a similar
> test.

But truth_valued_p doesn't catch vector types, no?  That said,
the

> > > > +(match (logical_inverted_value @0)
> > > > + (bit_xor truth_valued_p@0 integer_onep))

would have a similar issue for vectors?

I'll happily approve a patch that makes it work correctly for vectors
(with a testcase)!

A bug with a testcase that is miscompiled is also ok, I'll fix that
then.

Thanks,
Richard.


Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-06 Thread Marc Glisse

On Thu, 6 Nov 2014, Richard Biener wrote:


On Thu, 6 Nov 2014, Marc Glisse wrote:


On Thu, 6 Nov 2014, Richard Biener wrote:


On Thu, 6 Nov 2014, Marc Glisse wrote:


On Thu, 6 Nov 2014, Richard Biener wrote:


+/* Try simple folding for X op !X, and X op X with the help
+   of the truth_valued_p and logical_inverted_value predicates.  */
+(match truth_valued_p
+ @0
+ (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1)))
+(for op (lt le eq ne ge gt truth_and truth_andif truth_or truth_orif
truth_xor)
+ (match truth_valued_p
+  (op @0 @1)))
+(match truth_valued_p
+  (truth_not @0))
+
+(match (logical_inverted_value @0)
+ (bit_not truth_valued_p@0))
+(match (logical_inverted_value @0)
+ (eq @0 integer_zerop)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
+(match (logical_inverted_value @0)
+ (ne truth_valued_p@0 integer_onep)
+ (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)
+(match (logical_inverted_value @0)
+ (bit_xor truth_valued_p@0 integer_onep))
+
+/* X & !X -> 0.  */
+(simplify
+ (bit_and:c @0 (logical_inverted_value @0))
+ { build_zero_cst (type); })
+/* X | !X and X ^ !X -> 1, , if X is truth-valued.  */
+(for op (bit_ior bit_xor)
+ (simplify
+  (op:c truth_valued_p@0 (logical_inverted_value @0))
+  { build_one_cst (type); }))


Shouldn't that be build_true_cst (type) so it is -1 for vectors? It
seems that it could match:
vec a, b;
vec c=a

Probably.  Note that I copied this from tree-ssa-forwprop.c.

Generally I try to avoid fixing bugs or improving things at this point
to make the transition more obvious.


But truth_valued_ssa_name starts with:

  if (!INTEGRAL_TYPE_P (type))
return false;

so it does not match vectors. lookup_logical_inverted_value has a similar
test.


But truth_valued_p doesn't catch vector types, no?


IIUC it catches a
That said, the


+(match (logical_inverted_value @0)
+ (bit_xor truth_valued_p@0 integer_onep))


would have a similar issue for vectors?


Probably, yes. integer_truep maybe, to match a new build_true_cst...


I'll happily approve a patch that makes it work correctly for vectors
(with a testcase)!


I'd like to wait until you are mostly done merging, so I can make just one 
pass on the .pd file.


--
Marc Glisse


Re: [PATCH][11/n] Merge from match-and-simplify, bit patterns from forwprop

2014-11-08 Thread H.J. Lu
On Thu, Nov 6, 2014 at 12:55 AM, Richard Biener  wrote:
>
> This merges patterns implementing the bitwise patterns from
> tree-ssa-forwprop.c.  I've removed duplicate functionality from
> fold-const.c as I found them, some may be still lurking in the
> depths.
>
> This also fixes a bug in genmatch which made user-defined predicates
> matching anything, thus
>
> (match foo
>  @0
>  (if ...
>
> not work (that is: ignored).
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
>
> Richard.
>
> 2014-11-06  Richard Biener  
>
> * match.pd: Implement bitwise binary and unary simplifications
> from tree-ssa-forwprop.c.
> * fold-const.c (fold_unary_loc): Remove them here.
> (fold_binary_loc): Likewise.
> * tree-ssa-forwprop.c (simplify_not_neg_expr): Remove.
> (truth_valued_ssa_name): Likewise.
> (lookup_logical_inverted_value): Likewise.
> (simplify_bitwise_binary_1): Likewise.
> (hoist_conversion_for_bitop_p): Likewise.
> (simplify_bitwise_binary_boolean): Likewise.
> (simplify_bitwise_binary): Likewise.
> (pass_forwprop::execute): Remove calls to simplify_not_neg_expr
> and simplify_bitwise_binary.
> * genmatch.c (dt_node::append_true_op): Use safe_as_a for parent.
> (decision_tree::insert): Also insert non-expressions.
>
> * gcc.dg/tree-ssa/forwprop-28.c: Adjust scanning for the
> desired transform.
>

This caused:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63787


H.J.