From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 62564 invoked by alias); 1 Oct 2015 08:21:04 -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 62549 invoked by uid 89); 1 Oct 2015 08:21:03 -0000 Authentication-Results: sourceware.org; auth=none 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-f47.google.com Received: from mail-pa0-f47.google.com (HELO mail-pa0-f47.google.com) (209.85.220.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 01 Oct 2015 08:21:01 +0000 Received: by pablk4 with SMTP id lk4so67155122pab.3 for ; Thu, 01 Oct 2015 01:21:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:cc:subject:references:in-reply-to:content-type; bh=ukvDSdqmEkQyz1xcXXr0DVLncYsFZxmFzT6Qa/wTOx0=; b=jLOFl+lW11ygdnMyA/gNFDMqYcxsl14HU85j63vjv/VYFCXwTIZx8HeuhzHH1mhBiO W8ocW/6mbpxl6WWvRKgFZBMekoglonDKtkttCUhACXwzQ2p1HHAINozYBldTQusoeeJ8 tOZwoHLfBQvDOmdaJszEQjyxW50MDWvimaHPk60IDWV4tRSDJ+dCt+qmvBlbF4gULKMy Fv8EzA8B3kZIhgpljdzHLA6UtAd69ABfiXiJ9dmRY3orHIn93s3ueZ3HFn7CBSAj5xCk /bOAtwp+KAYPpf+AKjjb3qQeRBRSk8iLoeGM/UPriMzNKJZbgy2LwdkUamxGbUFyk8i2 hGHg== X-Gm-Message-State: ALoCoQljsNmvWcn44RtLU649/FTiFcaEpPAvpOH20lGH3LDBFZqA6NoQELrPSeEUEgLdhfNqpk3Z X-Received: by 10.66.164.132 with SMTP id yq4mr10744417pab.8.1443687659979; Thu, 01 Oct 2015 01:20:59 -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 jv5sm5026317pbc.47.2015.10.01.01.20.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 01:20:59 -0700 (PDT) Message-ID: <560CECE9.6040905@linaro.org> Date: Thu, 01 Oct 2015 08:21:00 -0000 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 , 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> <560CE7BF.30709@linaro.org> In-Reply-To: Content-Type: multipart/mixed; boundary="------------090404030001030609010908" X-SW-Source: 2015-10/txt/msg00016.txt.bz2 This is a multi-part message in MIME format. --------------090404030001030609010908 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Content-length: 421 Marc, Ah I did misunderstand you. Patch with match.pd formatting fix. On 10/01/2015 01:05 AM, Marc Glisse wrote: > On Thu, 1 Oct 2015, Michael Collison wrote: > >> ChangeLog formatting and test case fixed. > > Oups, sorry for the lack of precision, but I meant indenting the code > in match.pd, I hadn't even looked at the ChangeLog. > -- Michael Collison Linaro Toolchain Working Group michael.collison@linaro.org --------------090404030001030609010908 Content-Type: text/plain; charset=UTF-8; name="ChangeLog.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ChangeLog.txt" Content-length: 261 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. --------------090404030001030609010908 Content-Type: text/x-patch; name="tcwg-140-v9.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="tcwg-140-v9.patch" Content-length: 1299 diff --git a/gcc/match.pd b/gcc/match.pd index bd5c267..caf3c82 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 --------------090404030001030609010908--