From patchwork Thu Dec 15 11:01:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hurugalawadi, Naveen" X-Patchwork-Id: 706032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tfVrg5cqpz9snm for ; Thu, 15 Dec 2016 22:02:10 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="SXYOf4IF"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=aKFUFVGFxh3zdQmpKUZGpZLbt/c5sj8VCvtKAOhb7AxVBH0mPn 2V+3OsfNe3axngZTN4TpUYVLfFn2F6+D2UV+5Z5OMX3kWSjMULBuZMCOcXNxflxO PHc9k/TKQQ0RJID91Sx1IulfCsa+6QDKJTPAUIaIsnEx6R1TalKrEqxUo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=ge+zNaDihosL0eHMfFCo4ykjOp8=; b=SXYOf4IFhM0P2lxOuFCE ZbtZ6Fi/auvcDpMadh0Ob/9D5iZXo6BIwzBM4FxzjwS113MK7HiGG0uYoI8xQZi3 YVYXvpAqGlEB9W8EAJ5ttFmf+szUA8vk/2MqcKTX6skONVb6lbT+ePw0kC43vohL BoYxwua/6Qk5OcXrArGHBFk= Received: (qmail 84185 invoked by alias); 15 Dec 2016 11:02:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk 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 83607 invoked by uid 89); 15 Dec 2016 11:02:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=hs, H*RU:sk:NAM03-C, H*RU:sk:mail-co, HX-HELO:sk:NAM03-C X-HELO: NAM03-CO1-obe.outbound.protection.outlook.com Received: from mail-co1nam03on0069.outbound.protection.outlook.com (HELO NAM03-CO1-obe.outbound.protection.outlook.com) (104.47.40.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Dec 2016 11:01:50 +0000 Received: from CO2PR07MB2694.namprd07.prod.outlook.com (10.166.214.7) by SN1PR07MB2320.namprd07.prod.outlook.com (10.169.127.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8; Thu, 15 Dec 2016 11:01:47 +0000 Received: from CO2PR07MB2694.namprd07.prod.outlook.com ([10.166.214.7]) by CO2PR07MB2694.namprd07.prod.outlook.com ([10.166.214.7]) with mapi id 15.01.0771.014; Thu, 15 Dec 2016 11:01:46 +0000 From: "Hurugalawadi, Naveen" To: "gcc-patches@gcc.gnu.org" CC: "Pinski, Andrew" , Richard Biener , "marc.glisse@inria.fr" Subject: [PATCH] [Match & Simplify] Optimize some minmax patterns Date: Thu, 15 Dec 2016 11:01:45 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Naveen.Hurugalawadi@cavium.com; x-microsoft-exchange-diagnostics: 1; SN1PR07MB2320; 7:Dkv0J0DmKY+ZzBinSOrFEYwNpJVsebpAIL/Gm+6xl8Gd5Yvq8WxlejpEi1EAupqWkcv7iAZODK8pziWVWt30B2TrFxipjTB9UlFpCfbCcBKk8uoWfRky+Ixli26O87t3+LSIAYAhInXCrdlIFJ9fzGGN0sJ39YYSF4T5IL98+L3+sjKyEOIHcG0nCe1gFI7fS07ehTkZedDfjPcxfYlsKn6JkoxCou+rxrM9Pf6M0FmHY/BfKsRK83/d/ooWSdXZpw5RGBkgdrAkgtlCYXebU28xmItFuwDq5oyRQD8I8BK8ML8hfr+4/cExdE4U18SVTdt7/yXeHp+bTRShgu9tlXK0Hz0AMuFgIOgUmPV0fhebFNXsg5FtyIiQwpD1w09u4kUjTr79eTTBfU1OGl0k+HTrPxi1NS1i27625dnKwoKbJUnyqrZBx3eAHff2EG13eaeR/QIXZSESVMHFWZ3HfQ== x-forefront-antispam-report: SFV:SKI; SCL:-1SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39840400002)(39450400003)(39410400002)(377424004)(199003)(189002)(81166006)(4326007)(38730400001)(305945005)(81156014)(76576001)(8936002)(6506006)(68736007)(8676002)(39060400001)(25786008)(77096006)(2906002)(6436002)(122556002)(4001150100001)(3280700002)(6916009)(7736002)(3660700001)(86362001)(2501003)(2900100001)(99286002)(106356001)(66066001)(106116001)(105586002)(110136003)(101416001)(5660300001)(9686002)(2351001)(54356999)(97736004)(7696004)(74316002)(99936001)(189998001)(102836003)(6116002)(50986999)(3846002)(92566002)(33656002)(5890100001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR07MB2320; H:CO2PR07MB2694.namprd07.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; x-ms-office365-filtering-correlation-id: 9068c28f-490f-448c-0616-08d424d9c316 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:SN1PR07MB2320; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(102415395)(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(6072148); SRVR:SN1PR07MB2320; BCL:0; PCL:0; RULEID:; SRVR:SN1PR07MB2320; x-forefront-prvs: 0157DEB61B received-spf: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2016 11:01:45.9280 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB2320 Hi, Please find attached the patch that optimizes some patterns in maxmin on same variabes with constants. Bootstrapped and Regression tested on x86_64 & aarch64-thunder-linux. Please review the patch and let us know if its okay? 2016-12-15 Andrew Pinski Naveen H.S gcc * match.pd (max:c @0 (plus@2 @0 INTEGER_CST@1)): New Pattern. (min:c @0 (plus@2 @0 INTEGER_CST@1)) : New Pattern. gcc/testsuite * gcc.dg/max.c: New Testcase. * gcc.dg/min.c: New Testcase. diff --git a/gcc/match.pd b/gcc/match.pd index f4cc2d8..ff5e97b 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1324,6 +1324,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Simplifications of MIN_EXPR, MAX_EXPR, fmin() and fmax(). */ +/* max (a, a + CST) -> a + CST where CST is positive. */ +/* max (a, a + CST) -> a where CST is negative. */ +(simplify + (max:c @0 (plus@2 @0 INTEGER_CST@1)) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + (if (tree_int_cst_sgn (@1) > 0) + @2 + @0))) + +/* min (a, a + CST) -> a where CST is positive. */ +/* min (a, a + CST) -> a + CST where CST is negative. */ +(simplify + (min:c @0 (plus@2 @0 INTEGER_CST@1)) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + (if (tree_int_cst_sgn (@1) > 0) + @0 + @2))) + (for minmax (min max FMIN FMAX) (simplify (minmax @0 @0) diff --git a/gcc/testsuite/gcc.dg/max.c b/gcc/testsuite/gcc.dg/max.c new file mode 100644 index 0000000..e979810 --- /dev/null +++ b/gcc/testsuite/gcc.dg/max.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +static inline int +max (int a, int b) +{ + return a < b ? b : a; +} + +int +test_00 (int a) +{ + return max (a, a + 8); +} + +int +test_01 (int a) +{ + return max (a, a - 8); +} + +/* { dg-final { scan-tree-dump-not "MAX_EXPR" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/min.c b/gcc/testsuite/gcc.dg/min.c new file mode 100644 index 0000000..d847270 --- /dev/null +++ b/gcc/testsuite/gcc.dg/min.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +static inline int +min (int a, int b) +{ + return a < b ? a : b; +} + +int +test_00 (int a) +{ + return min (a, a + 8); +} + +int +test_01 (int a) +{ + return min (a, a - 8); +} + +/* { dg-final { scan-tree-dump-not "MIN_EXPR" "optimized" } } */