From patchwork Tue Jul 21 09:16:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hurugalawadi, Naveen" X-Patchwork-Id: 498118 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 2902F140D23 for ; Tue, 21 Jul 2015 19:16:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=oLeOSBcM; 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:references:in-reply-to :content-type:mime-version; q=dns; s=default; b=umRhLWhG8N7COThI 6qEWFC1GOIHnbl+X9bSO1fIqLA57Fr0AusQiNR7n4zMAkQh5Klo232u7HC76ieRU 1e3mzU20eNHPm0CWYensVHiTB+HR1xN8XE1RQq3JUK+O8Vc714KgL2jFc9Qs2Dc2 aVpNGr5g4dIBJxhM4VMm34KAxyc= 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:references:in-reply-to :content-type:mime-version; s=default; bh=JIN0hcpNjxOKmVebN99ekS 61C2E=; b=oLeOSBcMNMXTCMXmu4QeYwTs3zffp3eVF5Ap6SmhitygM6/9ZuD+z9 eaRW7+dV2KGgZvJmP7uosli2GfxrvAQeaAZnSV2Ox87DyHTqHrIbceCi1LEuSNSf fo+fPtLAxyF0rCYIO2a1hlhIrBDnXIwTTKRzWoy1APHpw2nAStyiI= Received: (qmail 95228 invoked by alias); 21 Jul 2015 09:16:16 -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 95156 invoked by uid 89); 21 Jul 2015 09:16:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.0 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: na01-bn1-obe.outbound.protection.outlook.com Received: from mail-bn1bon0063.outbound.protection.outlook.com (HELO na01-bn1-obe.outbound.protection.outlook.com) (157.56.111.63) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Tue, 21 Jul 2015 09:16:14 +0000 Received: from SN2PR0701MB1024.namprd07.prod.outlook.com (10.160.57.150) by SN2PR0701MB1021.namprd07.prod.outlook.com (10.160.57.147) with Microsoft SMTP Server (TLS) id 15.1.213.14; Tue, 21 Jul 2015 09:16:11 +0000 Received: from SN2PR0701MB1024.namprd07.prod.outlook.com ([10.160.57.150]) by SN2PR0701MB1024.namprd07.prod.outlook.com ([10.160.57.150]) with mapi id 15.01.0213.021; Tue, 21 Jul 2015 09:16:11 +0000 From: "Hurugalawadi, Naveen" To: Richard Biener CC: "gcc-patches@gcc.gnu.org" Subject: Re: [PR25530] Convert (unsigned t / 2) * 2 into (unsigned t & ~1) Date: Tue, 21 Jul 2015 09:16:11 +0000 Message-ID: References: , In-Reply-To: authentication-results: gcc.gnu.org; dkim=none (message not signed) header.d=none; x-microsoft-exchange-diagnostics: 1; SN2PR0701MB1021; 5:GLcGj3V1/JkhEbhKusH0QHnOeFATCxGuCrLN8w4YZtKYBWpuJz1n3oPakV6TbG8le+224EeNKkNHBOGsGdlf2TCZDfns7e3CpKnqv5gznWska9GnVt6ngrrMUmn6Bys9IabmvuCi1b1hqfQxgVG9zg==; 24:SHkp6rV4bpxh5aX1+SPnQToKOHlsuSgXpx5IMSIPn8WPIOMrx/X7/1G78l3FnjdbwjNjeAVzW7r1l7dIBx5Wp9CnU3AJ9cC8ICyQbBpGEYk=; 20:QGvC0zREOavvRRmgrVbtOq1K+xDexYdN9uo64pMrc3ix7AJQiyNJe69s+c+oHTOXC7Wkk/AJ3fS6YHOHuHKUoQ== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN2PR0701MB1021; sn2pr0701mb1021: X-MS-Exchange-Organization-RulesExecuted x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:SN2PR0701MB1021; BCL:0; PCL:0; RULEID:; SRVR:SN2PR0701MB1021; x-forefront-prvs: 0644578634 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(54534003)(164054003)(377424004)(51914003)(2900100001)(102836002)(87936001)(66066001)(5001960100002)(110136002)(33656002)(74316001)(2950100001)(106116001)(76576001)(122556002)(99286002)(77096005)(92566002)(54356999)(2656002)(40100003)(86362001)(77156002)(62966003)(76176999)(50986999)(19580405001)(19580395003)(46102003)(99936001)(189998001)(5002640100001)(5890100001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR0701MB1021; H:SN2PR0701MB1024.namprd07.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jul 2015 09:16:11.4597 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR0701MB1021 Hi, >> handle exact_div differently, like fold-const.c does. >> Then expressing ~1 with the result expression is really excessive - you >> should simply build this with @1 - 1 if @1 is a power of two. Thanks for the review and comments. Please find attached the modified patch as per your comments. Please review the same and let me know if any further modifications are required. Regression Tested on X86_64. Thanks, Naveen gcc/testsuite/ChangeLog: 2015-07-21 Naveen H.S PR middle-end/25530 * gcc.dg/pr25530.c: New test. gcc/ChangeLog: 2015-07-21 Naveen H.S PR middle-end/25530 * match.pd (mult (exact_div @0 INTEGET_CST@1) @1) : New simplifier. (mult (trunc_div @0 integer_pow2p@1) @1) : New simplifier. --- a/gcc/match.pd +++ b/gcc/match.pd @@ -280,6 +280,15 @@ along with GCC; see the file COPYING3. If not see && integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0) (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))))) +/* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1. */ +(simplify + (mult (exact_div @0 INTEGET_CST@1) @1) + @0) + +(simplify + (mult (trunc_div @0 integer_pow2p@1) @1) + (bit_and @0 (negate @1))) + /* X % Y is smaller than Y. */ (for cmp (lt ge) (simplify new file mode 100644 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr25530.c @@ -0,0 +1,14 @@ +new file mode 100644 +--- /dev/null ++++ b/gcc/testsuite/gcc.dg/pr25530.c +@@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +int +f (unsigned t) +{ + return (t / 2) * 2; +} + +/* { dg-final { scan-tree-dump "\& -2" "optimized" } } */