From patchwork Fri Sep 18 06:31:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Collison X-Patchwork-Id: 53858 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 0F41A22A0D for ; Fri, 18 Sep 2015 06:32:09 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf13460389lbb.3 for ; Thu, 17 Sep 2015 23:32:08 -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 :content-transfer-encoding:x-original-sender :x-original-authentication-results; bh=T5CPAdX5/uzTjtqIbhIufN/SZV9/IQYWJyHMu1/iO9A=; b=d6Ixw3qlHczHfoi/j3K/jJOftbU4l9l0BcuIwwO1+SQUg+cc8FCDD/OXmzW87X5Tkw 9JxnmclSt/1ORsIzMUMxiJxe4jgEGM/f5AjW/Q2YiLJYv/w24+INNG2RYqdfC7QZxUr+ LCIqL8Unc50rWWKVWtYcMuU1w78BtWZ+lRZwLbyuMeDbqBn94CNtlOMLjstFuxSGMnZZ LVSiH/DWxJxpvdmWVyyVfGvSoAned7JE/nBs54Mw2MzAvzMPLpgMFQVZDOKcjXWFm7h6 a7XYqkAzc/qK9zgAJ3BADu6ouY/z2c9IzP2XQyauUn6YT0ZjQMhr/fjVuV7L9osIu9Ep wCsQ== X-Gm-Message-State: ALoCoQln/zJ8Q/EUkWjzzZYnIDiblMGzSD4Kyr+NPStqIxiVPxlzbiawuh37chxTa7lAOmLJ3CnD X-Received: by 10.112.130.41 with SMTP id ob9mr532509lbb.17.1442557928014; Thu, 17 Sep 2015 23:32:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.138 with SMTP id v10ls33110lae.25.gmail; Thu, 17 Sep 2015 23:32:07 -0700 (PDT) X-Received: by 10.112.198.66 with SMTP id ja2mr2376973lbc.22.1442557927751; Thu, 17 Sep 2015 23:32:07 -0700 (PDT) Received: from mail-la0-x234.google.com (mail-la0-x234.google.com. [2a00:1450:4010:c03::234]) by mx.google.com with ESMTPS id du4si4878217lac.145.2015.09.17.23.32.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 23:32:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::234 as permitted sender) client-ip=2a00:1450:4010:c03::234; Received: by lamp12 with SMTP id p12so24101960lam.0 for ; Thu, 17 Sep 2015 23:32:07 -0700 (PDT) X-Received: by 10.152.5.133 with SMTP id s5mr2339200las.19.1442557927562; Thu, 17 Sep 2015 23:32:07 -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 w3csp97472lbq; Thu, 17 Sep 2015 23:32:06 -0700 (PDT) X-Received: by 10.66.235.226 with SMTP id up2mr5318866pac.89.1442557926268; Thu, 17 Sep 2015 23:32:06 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id kg8si11077700pab.100.2015.09.17.23.32.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 23:32:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-407734-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 58775 invoked by alias); 18 Sep 2015 06:31:53 -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 58760 invoked by uid 89); 18 Sep 2015 06:31:51 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f54.google.com Received: from mail-pa0-f54.google.com (HELO mail-pa0-f54.google.com) (209.85.220.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 18 Sep 2015 06:31:50 +0000 Received: by pacfv12 with SMTP id fv12so42735077pac.2 for ; Thu, 17 Sep 2015 23:31:49 -0700 (PDT) X-Received: by 10.66.161.7 with SMTP id xo7mr5205402pab.57.1442557908877; Thu, 17 Sep 2015 23:31:48 -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 j16sm6878433pbq.23.2015.09.17.23.31.47 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 Sep 2015 23:31:48 -0700 (PDT) Message-ID: <55FBAFD1.9080300@linaro.org> Date: Thu, 17 Sep 2015 23:31:45 -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: Jeff Law , Richard Biener CC: gcc Patches 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> In-Reply-To: <55BBBE2E.1020408@redhat.com> 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:c03::234 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 On 07/31/2015 11:27 AM, Jeff Law wrote: > On 07/31/2015 12:18 PM, Michael Collison wrote: >> Hi Jeff, >> >> Yes I will create a test case. I'm not quite sure what to check for even >> in the machine dependent test case. It's quite possible for the >> instructions that are generated to change over time. > I think we're going to want to look at the gimple IR and search for > the MIN/MAX expressions rather than the instructions. Given we don't > know where the transformation is going to land (yet), you can probably > start with -fdump-tree-optimized and scanning the .optimized dump. > > We can still do that and have the test be target specific. > > jeff > Jeff and Richard, 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 +(bit_and:c (op @0 @1) (op @0 @2)) +(if (INTEGRAL_TYPE_P (TREE_TYPE (@0))) +(op @0 (min @1 @2))))) + +/* Transform (@0 > @1 and @0 > @2) to use max */ +(for op (gt ge) +(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) + 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" } } */