public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Warn about duplicate patterns in match.pd
@ 2015-10-09  9:01 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2015-10-09  9:01 UTC (permalink / raw)
  To: gcc-patches


This teaches genmatch to warn about multiple patterns that match
the exact same expressions (you should usually merge those otherwise
the first one wins always).

It also removes some existing (harmless) duplicates (the first one
is the one that should have matched).  This reduces the amount of
generated code.

Bootstrap/regtest running on x86_64-unknown-linux-gnu.

Richard.

2015-10-09  Richard Biener  <rguenther@suse.de>

	* genmatch.c (print_operand): Fix formatting.
	(dt_node::append_simplify): Warn for multiple simplifiers
	that match the same pattern.
	* match.pd (log (exp @0)): Remove duplicates.

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 228635)
+++ gcc/genmatch.c	(working copy)
@@ -731,11 +731,10 @@ print_operand (operand *o, FILE *f = std
 
       if (flattened == false)
 	{
-	  putc (' ', f);
 	  for (unsigned i = 0; i < e->ops.length (); ++i)
 	    {
-	      print_operand (e->ops[i], f, flattened);
 	      putc (' ', f);
+	      print_operand (e->ops[i], f, flattened);
 	    }
 	}
       putc (')', f);
@@ -1563,6 +1562,16 @@ dt_node::append_simplify (simplify *s, u
 			  dt_operand **indexes)
 {
   dt_simplify *n = new dt_simplify (s, pattern_no, indexes);
+  for (unsigned i = 0; i < kids.length (); ++i)
+    if (dt_simplify *s2 = dyn_cast <dt_simplify *> (kids[i]))
+      {
+	warning_at (s->match->location, "duplicate pattern");
+	print_operand (s->match, stderr);
+	fprintf (stderr, "\n");
+	warning_at (s2->s->match->location, "previous pattern defined here");
+	print_operand (s2->s->match, stderr);
+	fprintf (stderr, "\n");
+      }
   return append_node (n);
 }
 
Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 228635)
+++ gcc/match.pd	(working copy)
@@ -2169,18 +2181,16 @@ (define_operator_list CEXPI BUILT_IN_CEX
    (mult @0 (POW @1 (negate @2))))
 
  /* Special case, optimize logN(expN(x)) = x.  */
- (for logs (LOG LOG2 LOG10)
-      exps (EXP EXP2 EXP10)
+ (for logs (LOG LOG2 LOG10 LOG10)
+      exps (EXP EXP2 EXP10 POW10)
   (simplify
    (logs (exps @0))
     @0))
  /* Optimize logN(func()) for various exponential functions.  We
     want to determine the value "x" and the power "exponent" in
     order to transform logN(x**exponent) into exponent*logN(x).  */
- (for logs (LOG LOG LOG LOG
-            LOG2 LOG2 LOG2 LOG2
-	    LOG10 LOG10 LOG10 LOG10)
-      exps (EXP EXP2 EXP10 POW10)
+ (for logs (LOG  LOG   LOG   LOG2 LOG2  LOG2  LOG10 LOG10)
+      exps (EXP2 EXP10 POW10 EXP  EXP10 POW10 EXP   EXP2)
   (simplify
    (logs (exps @0))
    (with {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-10-09  9:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-09  9:01 [PATCH] Warn about duplicate patterns in match.pd 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).