From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116722 invoked by alias); 9 Oct 2015 09:01:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 116692 invoked by uid 89); 9 Oct 2015 09:01:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Fri, 09 Oct 2015 09:01:42 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CC0E8AAD1 for ; Fri, 9 Oct 2015 09:01:38 +0000 (UTC) Date: Fri, 09 Oct 2015 09:01:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Warn about duplicate patterns in match.pd Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2015-10/txt/msg00933.txt.bz2 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 * 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 (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 {