From patchwork Thu Jul 23 03:47:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hurugalawadi, Naveen" X-Patchwork-Id: 499201 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 72B4B140A98 for ; Thu, 23 Jul 2015 13:48:09 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=TQ7acfrT; 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=Icq8Ix58GiofVISc JBrF2kE/nBxKK5tTKaF/Ag+UJLwjPCLmr1FW8pXIMtDkjes7cvtg4s547zc/VBHO peYojWZQpPfbNySKFNP+3ZTEriE9gRzCwKpA4v7CbQPpg4WUmPy/FBOZdDZHBa5h g7CE8uUIji5MS+W+ebR4G+q/8WY= 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=pTXp/q//SxG+lgtBETxXlh PfJUY=; b=TQ7acfrTjtt3p5exKKeWrjGZLze16SoRD0c+kynqu7+ET3rV8E3svP HvND9BvDfYhrl0Wf6J74ifikWItTQBEo9imOtYs+gA+7c3Y3tn8zqkXrfFux0VBQ q+aTgMor4U+jIZOZtBpiiqdta9FqWdanDDb37fSdbA21d1XDnLUwQ= Received: (qmail 55417 invoked by alias); 23 Jul 2015 03:48:00 -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 55408 invoked by uid 89); 23 Jul 2015 03:47:59 -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-bl2-obe.outbound.protection.outlook.com Received: from mail-bl2on0092.outbound.protection.outlook.com (HELO na01-bl2-obe.outbound.protection.outlook.com) (65.55.169.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Thu, 23 Jul 2015 03:47:58 +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; Thu, 23 Jul 2015 03:47:54 +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.0225.018; Thu, 23 Jul 2015 03:47:54 +0000 From: "Hurugalawadi, Naveen" To: Richard Biener CC: "marc.glisse@inria.fr" , GCC Patches Subject: Re: [PR25529] Convert (unsigned t * 2)/2 into unsigned (t & 0x7FFFFFFF) Date: Thu, 23 Jul 2015 03:47:53 +0000 Message-ID: References: , In-Reply-To: authentication-results: inria.fr; dkim=none (message not signed) header.d=none; x-microsoft-exchange-diagnostics: 1; SN2PR0701MB1021; 5:mTxiBSyZhym7e78H6E9UylkrL4V5n0sBdiAJNGxzeKrsVLmTBT/JSrVqDWdAABCTp3AkavsWEF+LRisU0oAuKkjcqhyXEy0iv4E6okYkxLufk9Svmbk91irVmf4R9tZphnjCOPlCHg/ctlv4q89VfA==; 24:/3uQDqBZ7Vy5mFcTerq391vgKAgSVt1codTz+Q69tDCJrrRsfL4A8b4DYcTEUyxl8G+Op5a4EyRVYTIrbtOoG2YnctH8NsA0nm/cvHYd7+I=; 20:ofPmbAo9A53imexX8UJeeDMiz3yqbhJTUUa6F3tsPXA6OsVCoMAzt/QDHsC+IBu+ZRRilSfBx+s3ATSv2mt5Tg== 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: 06469BCC91 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(164054003)(377424004)(77096005)(110136002)(5002640100001)(2656002)(74316001)(189998001)(62966003)(102836002)(2950100001)(5001960100002)(77156002)(92566002)(66066001)(2900100001)(5890100001)(33656002)(50986999)(93886004)(76176999)(46102003)(99286002)(5003600100002)(87936001)(86362001)(40100003)(19580405001)(122556002)(19580395003)(99936001)(76576001)(106116001)(54356999); 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: 23 Jul 2015 03:47:53.9983 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR0701MB1021 >> so using wi::mask is prefered here. Thanks for your review and comments. Please find attached the modified patch as per your comments. Please let me know if this version is okay? Thanks, Naveen 2015-07-22 Naveen H.S gcc/testsuite/ChangeLog: PR middle-end/25529 * gcc.dg/pr25529.c: New test. gcc/ChangeLog: PR middle-end/25529 * match.pd (exact_div (mult @0 INTEGER_CST@1) @1) : New simplifier. (trunc_div (mult @0 integer_pow2p@1) @1) : New simplifier. diff --git a/gcc/match.pd b/gcc/match.pd index 9a66f52..9c8080f 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -29,7 +29,8 @@ along with GCC; see the file COPYING3. If not see integer_each_onep integer_truep real_zerop real_onep real_minus_onep CONSTANT_CLASS_P - tree_expr_nonnegative_p) + tree_expr_nonnegative_p + integer_pow2p) /* Operator lists. */ (define_operator_list tcc_comparison @@ -280,6 +281,20 @@ 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 (t * 2)/2 -> t. */ +(simplify + (exact_div (mult @0 INTEGER_CST@1) @1) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) + @0)) + +/* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF. */ +(simplify + (trunc_div (mult @0 integer_pow2p@1) @1) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + (bit_and @0 { wide_int_to_tree + (type, wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (@1), + false, TYPE_PRECISION (type))); }))) + /* X % Y is smaller than Y. */ (for cmp (lt ge) (simplify diff --git a/gcc/testsuite/gcc.dg/pr25529.c b/gcc/testsuite/gcc.dg/pr25529.c new file mode 100644 index 0000000..4d9fe9e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr25529.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 "\& 2147483647" "optimized" } } */