From patchwork Thu Oct 1 07:58:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Collison X-Patchwork-Id: 54345 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by patches.linaro.org (Postfix) with ESMTPS id 406E423009 for ; Thu, 1 Oct 2015 07:59:18 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf2884323lbb.3 for ; Thu, 01 Oct 2015 00:59:17 -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=hsMtfgxOaOENXownQtQQTWwnlBmjm4wdua+TnOgHkts=; b=Jpi+KCpFrH+R0R+hcAfbWdUm0T1sf/KVSh6mjRN2p+YNHBKNsbFm9y5CyKHtJLcd0z AcycCIddFU7OTZ79rUvm4ZLCGxkqpfZZ8O0JtVBEKIrxOMIXpZdKjI8ppGzBrfV26Mrm Ykqmw85tE84aXy3bVrUeQ0VIOXBbR36pSwkJTVCVn83oWqXDeiRDIGF73fvc2F8gAHWg RRY6o9AhAvQ4N0ym6dMTcjf5iJN/nMbTn69MR2SRmgafJ4z/CZdAXZeullYQ/6VhFvBY i6tYhol5KkPa1jXvkZcdyg7xVz4vDC9vN2oKultzcPL0UBlnxpZvklgzvhjBs5MGH2wm WXPQ== X-Gm-Message-State: ALoCoQlepmzGhUiooj9hmj62nMnjvncF9P+ih/3xHANTlg/LtXsbefjQ+rNdIsBIwhadx+aVUKwM X-Received: by 10.194.240.230 with SMTP id wd6mr1173659wjc.0.1443686357040; Thu, 01 Oct 2015 00:59:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.145.132 with SMTP id t126ls105224lfd.89.gmail; Thu, 01 Oct 2015 00:59:16 -0700 (PDT) X-Received: by 10.25.209.80 with SMTP id i77mr1595956lfg.92.1443686356632; Thu, 01 Oct 2015 00:59:16 -0700 (PDT) Received: from mail-lb0-x235.google.com (mail-lb0-x235.google.com. [2a00:1450:4010:c04::235]) by mx.google.com with ESMTPS id y191si2197361lfd.174.2015.10.01.00.59.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 00:59:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c04::235 as permitted sender) client-ip=2a00:1450:4010:c04::235; Received: by lbwr8 with SMTP id r8so4416649lbw.2 for ; Thu, 01 Oct 2015 00:59:16 -0700 (PDT) X-Received: by 10.25.82.10 with SMTP id g10mr1619287lfb.56.1443686356359; Thu, 01 Oct 2015 00:59:16 -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 w3csp421166lbq; Thu, 1 Oct 2015 00:59:14 -0700 (PDT) X-Received: by 10.68.113.37 with SMTP id iv5mr10305988pbb.2.1443686354239; Thu, 01 Oct 2015 00:59:14 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id wk3si7123214pab.93.2015.10.01.00.59.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 00:59:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-408791-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 2637 invoked by alias); 1 Oct 2015 07:59:01 -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 2625 invoked by uid 89); 1 Oct 2015 07:59:00 -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-f51.google.com Received: from mail-pa0-f51.google.com (HELO mail-pa0-f51.google.com) (209.85.220.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 01 Oct 2015 07:58:59 +0000 Received: by pacfv12 with SMTP id fv12so68501667pac.2 for ; Thu, 01 Oct 2015 00:58:57 -0700 (PDT) X-Received: by 10.69.26.161 with SMTP id iz1mr10563219pbd.17.1443686337640; Thu, 01 Oct 2015 00:58:57 -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 ou1sm4936324pbb.0.2015.10.01.00.58.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 00:58:56 -0700 (PDT) Message-ID: <560CE7BF.30709@linaro.org> Date: Thu, 01 Oct 2015 00:58:55 -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::235 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 ChangeLog formatting and test case fixed. 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..2e4300c --- /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-times "MIN_EXPR" 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "MAX_EXPR" 1 "optimized" } } */ -- 1.9.1