From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119691 invoked by alias); 18 Sep 2015 07:00:53 -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 119680 invoked by uid 89); 18 Sep 2015 07:00:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mail2-relais-roc.national.inria.fr Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 18 Sep 2015 07:00:47 +0000 Received: from 89-158-40-219.rev.numericable.fr (HELO laptop-mg.local) ([89.158.40.219]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2015 09:00:43 +0200 Date: Fri, 18 Sep 2015 07:38:00 -0000 From: Marc Glisse Reply-To: gcc-patches@gcc.gnu.org To: Michael Collison cc: Jeff Law , Richard Biener , gcc Patches Subject: Re: [PATCH] Optimize certain end of loop conditions into min/max operation In-Reply-To: <55FBAFD1.9080300@linaro.org> Message-ID: References: <55B5A884.4060105@linaro.org> <55B65A4B.3050705@redhat.com> <55BBA052.2060900@redhat.com> <55BBBBE6.2070207@linaro.org> <55BBBE2E.1020408@redhat.com> <55FBAFD1.9080300@linaro.org> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-SW-Source: 2015-09/txt/msg01360.txt.bz2 On Thu, 17 Sep 2015, Michael Collison wrote: > Here is the the patch modified with test cases for MIN_EXPR and MAX_EXPR > expressions. I need some assistance; this test case will fail on targets that > don't have support for MIN/MAX such as 68k. Is there any way to remedy this > short of enumerating whether a target support MIN/MAX in > testsuite/lib/target_support? > > 2015-07-24 Michael Collison > Andrew Pinski > > * match.pd ((x < y) && (x < z) -> x < min (y,z), > (x > y) and (x > z) -> x > max (y,z)) > * testsuite/gcc.dg/tree-ssa/minmax-loopend.c: New test. > > diff --git a/gcc/match.pd b/gcc/match.pd > index 5e8fd32..8691710 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1793,3 +1793,17 @@ along with GCC; see the file COPYING3. If not see > (convert (bit_and (op (convert:utype @0) (convert:utype @1)) > (convert:utype @4))))))) > > + > +/* Transform (@0 < @1 and @0 < @2) to use min */ > +(for op (lt le) > +(simplify You seem to be missing all indentation. > +(bit_and:c (op @0 @1) (op @0 @2)) :c seems useless here. On the other hand, it might make sense to use op:s since this is mostly useful if it removes the 2 original comparisons. > +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) How did you chose this restriction? It seems safe enough, but the transformation could make sense in other cases as well. It can always be generalized later though. > +(op @0 (min @1 @2))))) > + > +/* Transform (@0 > @1 and @0 > @2) to use max */ > +(for op (gt ge) Note that you could unify the patterns with something like: (for op (lt le gt ge) ext (min min max max) (simplify ... > +(simplify > +(bit_and:c (op @0 @1) (op @0 @2)) > +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) > +(op @0 (max @1 @2))))) > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c > b/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c > new file mode 100644 > index 0000000..cc0189a > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c > @@ -0,0 +1,23 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > + > +#define N 1024 > + > +int a[N], b[N], c[N]; > + > +void add (unsigned int m, unsigned int n) > +{ > + unsigned int i; > + for (i = 0; i < m && i < n; ++i) Maybe writing '&' instead of '&&' would make it depend less on the target. Also, both tests seem to be for GENERIC (i.e. I expect that you are already seeing the optimized version with -fdump-tree-original or -fdump-tree-gimple). Maybe something as simple as: int f(long a, long b, long c) { int cmp1 = a < b; int cmp2 = a < c; return cmp1 & cmp2; } > + a[i] = b[i] + c[i]; > +} > + > +void add2 (unsigned int m, unsigned int n) > +{ > + unsigned int i; > + for (i = N-1; i > m && i > n; --i) > + a[i] = b[i] + c[i]; > +} > + > +/* { dg-final { scan-tree-dump "MIN_EXPR" 1 "optimized" } } */ > +/* { dg-final { scan-tree-dump "MAX_EXPR" 1 "optimized" } } */ -- Marc Glisse