From patchwork Thu Oct 1 05:40:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Collison X-Patchwork-Id: 54342 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id 87F5823009 for ; Thu, 1 Oct 2015 05:40:45 +0000 (UTC) Received: by lana8 with SMTP id a8sf648813lan.1 for ; Wed, 30 Sep 2015 22:40:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type:x-original-sender :x-original-authentication-results; bh=A0yfgkAXdQ1Ak0CLLlZNNREuG+kt4CYd2iL+FnF4L64=; b=QsVrm5sxnj+POdk6XTvlDo2tNFyI4ekuaPhBVyCuJh5uQTUzOCnD8NLvMEaPGRmToW nyT/kIFCqWwfwvQ17gz9CP8tg3YYbIpl0dxvX9OcTEd8PIB2F/6zjMmMdFKYi1Lbl4Zk jQPNU6k3oZ2LSFbNyvvNKn7K3ONcc4wk8BSCNVT1XEvPrCN+b4wzKYeYopnToleN+yHu +/hEnGL8eCxJMEoYg3G0AWzvkCpDIbfc0CUDuXYNuDpf455BrhMRdSmFsUFdgOWyMmTW E1Tlqg0PMhA5azXcWwIXtQSZmFKjNl3K2MKtXo1JBU6VdnU6tV1y2pvsQJaHANASL1IB eR2g== X-Gm-Message-State: ALoCoQkJHfdBAqny/KGrOP6H/5jVjumUzo+pBNTw6zr6HfCHNIOLuNs/ZbuRPl8YHw62+XK2VcKP X-Received: by 10.112.169.34 with SMTP id ab2mr1071686lbc.23.1443678044446; Wed, 30 Sep 2015 22:40:44 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.90.68 with SMTP id o65ls86769lfb.4.gmail; Wed, 30 Sep 2015 22:40:44 -0700 (PDT) X-Received: by 10.25.18.160 with SMTP id 32mr1481035lfs.0.1443678044179; Wed, 30 Sep 2015 22:40:44 -0700 (PDT) Received: from mail-lb0-x22c.google.com (mail-lb0-x22c.google.com. [2a00:1450:4010:c04::22c]) by mx.google.com with ESMTPS id 29si1993543lfq.18.2015.09.30.22.40.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Sep 2015 22:40:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22c as permitted sender) client-ip=2a00:1450:4010:c04::22c; Received: by lbcao8 with SMTP id ao8so2816552lbc.3 for ; Wed, 30 Sep 2015 22:40:43 -0700 (PDT) X-Received: by 10.25.20.80 with SMTP id k77mr1441400lfi.117.1443678043732; Wed, 30 Sep 2015 22:40:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp368599lbq; Wed, 30 Sep 2015 22:40:41 -0700 (PDT) X-Received: by 10.107.169.102 with SMTP id s99mr7542566ioe.190.1443678041158; Wed, 30 Sep 2015 22:40:41 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x4si908349igr.34.2015.09.30.22.40.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Sep 2015 22:40:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-408783-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 51783 invoked by alias); 1 Oct 2015 05:40:28 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 51773 invoked by uid 89); 1 Oct 2015 05:40:27 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f52.google.com Received: from mail-pa0-f52.google.com (HELO mail-pa0-f52.google.com) (209.85.220.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 01 Oct 2015 05:40:26 +0000 Received: by padhy16 with SMTP id hy16so63412680pad.1 for ; Wed, 30 Sep 2015 22:40:23 -0700 (PDT) X-Received: by 10.68.69.79 with SMTP id c15mr9696787pbu.90.1443678023461; Wed, 30 Sep 2015 22:40:23 -0700 (PDT) Received: from [192.168.1.14] (ip70-176-202-128.ph.ph.cox.net. [70.176.202.128]) by smtp.googlemail.com with ESMTPSA id qg2sm3989209pbb.80.2015.09.30.22.40.22 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 30 Sep 2015 22:40:22 -0700 (PDT) Message-ID: <560CC744.4040704@linaro.org> Date: Wed, 30 Sep 2015 22:40:20 -0700 From: Michael Collison User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org CC: Richard Biener , marc.glisse@inria.fr, Jeff Law Subject: Re: [PATCH] Optimize certain end of loop conditions into min/max operation 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> <560B8F51.6030108@linaro.org> <560C0D65.2010300@linaro.org> In-Reply-To: X-Original-Sender: michael.collison@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::22c as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Richard and Marc, Latest patch attached which incorporates all comments. 2015-09-30 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. On 09/30/2015 12:30 PM, Marc Glisse wrote: >>>>>> On Fri, 18 Sep 2015, Marc Glisse wrote: >>>>>>>> +(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. > > As I was saying, :c is useless. > (x:c y z) > is replaced by two copies of the transformation, one with > (x y z) > and the other with > (x z y) > In your transformation, both versions would be equivalent, so the second > one is redundant. > > Also, if you have: > a=x b=x c=a&b; > reuse(a); > reuse(b); > > (i.e. the comparison results are used for more than just this bit_and) > then your transformation may make the code more expensive. To avoid > this, you can write op:s, meaning that the result of op is used only > once. > diff --git a/gcc/match.pd b/gcc/match.pd index bd5c267..ef2e025 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2311,3 +2311,13 @@ along with GCC; see the file COPYING3. If not see (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); } (convert (bit_and (op (convert:utype @0) (convert:utype @1)) (convert:utype @4)))))))) + +/* Transform (@0 < @1 and @0 < @2) to use min, + (@0 > @1 and @0 > @2) to use max */ +(for op (lt le gt ge) + ext (min min max max) +(simplify +(bit_and (op:s @0 @1) (op:s @0 @2)) +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) +(op @0 (ext @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..dfe6120 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/minmax-loopend.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int min_test(long a, long b, long c) { + int cmp1 = a < b; + int cmp2 = a < c; + return cmp1 & cmp2; +} + +int max_test (long a, long b, long c) { + int cmp1 = a > b; + int cmp2 = a > c; + return cmp1 & cmp2; +} + +/* { dg-final { scan-tree-dump "MIN_EXPR" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump "MAX_EXPR" 1 "optimized" } } */ -- 1.9.1