[PATCH] Fix PR68590

2015-12-01 Thread Richard Biener

The following avoids PR68590 by merging two match.pd patterns.

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

Richard.

2015-12-01  Richard Biener  

PR middle-end/68590
* match.pd: Merge (eq @0 @0) and (ge/le @0 @0) patterns.

Index: gcc/match.pd
===
--- gcc/match.pd(revision 231065)
+++ gcc/match.pd(working copy)
@@ -1828,15 +1828,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  
 /* Simplify comparison of something with itself.  For IEEE
floating-point, we can only do some of these simplifications.  */
-(simplify
- (eq @0 @0)
- (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
-  || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0
-  { constant_boolean_node (true, type); }))
-(for cmp (ge le)
+(for cmp (eq ge le)
  (simplify
   (cmp @0 @0)
-  (eq @0 @0)))
+  (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
+   || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0
+   { constant_boolean_node (true, type); }
+   (if (cmp != EQ_EXPR)
+(eq @0 @0)
 (for cmp (ne gt lt)
  (simplify
   (cmp @0 @0)


[PATCH] Fix PR68590

2015-12-01 Thread Richard Biener

This fixes the PR in another way as well, allowing as many capture
uses in the replacement expression as in the original one, avoiding
some spurious save_exprs that way (and not perform "CSE" within
the match-and-simplify framework).

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

Richard.

2015-12-01  Richard Biener  

PR middle-end/68590
* genmatch.c (struct capture_info): Add match_use_count.
(capture_info::walk_match): Increment match_use_count.
(dt_simplify::gen_1): For GENERIC, only wrap multi-use
replacements in a save_expr if they occur more often than
in the original expression.

Index: gcc/genmatch.c
===
--- gcc/genmatch.c  (revision 231101)
+++ gcc/genmatch.c  (working copy)
@@ -1851,7 +1850,8 @@ struct capture_info
   bool force_single_use;
   bool cond_expr_cond_p;
   unsigned long toplevel_msk;
-  int result_use_count;
+  unsigned match_use_count;
+  unsigned result_use_count;
   unsigned same_as;
   capture *c;
 };
@@ -1901,6 +1901,7 @@ capture_info::walk_match (operand *o, un
   if (capture *c = dyn_cast  (o))
 {
   unsigned where = c->where;
+  info[where].match_use_count++;
   info[where].toplevel_msk |= 1 << toplevel_arg;
   info[where].force_no_side_effects_p |= conditional_p;
   info[where].cond_expr_cond_p |= cond_expr_cond_p;
@@ -3106,13 +3107,16 @@ dt_simplify::gen_1 (FILE *f, int indent,
  else if (is_a  (opr))
is_predicate = true;
  /* Search for captures used multiple times in the result expression
-and dependent on TREE_SIDE_EFFECTS emit a SAVE_EXPR.  */
+and wrap them in a SAVE_EXPR.  Allow as many uses as in the
+original expression.  */
  if (!is_predicate)
for (int i = 0; i < s->capture_max + 1; ++i)
  {
-   if (cinfo.info[i].same_as != (unsigned)i)
+   if (cinfo.info[i].same_as != (unsigned)i
+   || cinfo.info[i].cse_p)
  continue;
-   if (cinfo.info[i].result_use_count > 1)
+   if (cinfo.info[i].result_use_count
+   > cinfo.info[i].match_use_count)
  fprintf_indent (f, indent,
  "captures[%d] = save_expr (captures[%d]);\n",
  i, i);