From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91245 invoked by alias); 13 Apr 2017 11:16:19 -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 91084 invoked by uid 89); 13 Apr 2017 11:16:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=lifted, Hauthentication-results:gcc.gnu.org, H*RU:sk:EUR02-H, Hx-spam-relays-external:sk:EUR02-H X-HELO: EUR02-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr10052.outbound.protection.outlook.com (HELO EUR02-HE1-obe.outbound.protection.outlook.com) (40.107.1.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Apr 2017 11:16:10 +0000 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com (10.175.46.18) by AM5PR0802MB2388.eurprd08.prod.outlook.com (10.175.43.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.10; Thu, 13 Apr 2017 11:16:08 +0000 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com ([10.175.46.18]) by AM5PR0802MB2610.eurprd08.prod.outlook.com ([10.175.46.18]) with mapi id 15.01.1034.011; Thu, 13 Apr 2017 11:16:08 +0000 From: Wilco Dijkstra To: Jakub Jelinek , Sudi Das CC: GCC Patches , nd , Richard Earnshaw , James Greenhalgh Subject: Re: [PATCH][GCC] Simplification of 1U << (31 - x) Date: Thu, 13 Apr 2017 11:16:00 -0000 Message-ID: authentication-results: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; x-microsoft-exchange-diagnostics: 1;AM5PR0802MB2388;7:KFDfOyXn/TY3JC5uOsSF0BQxtQbPDRtRAqFzBdky5FnQP9ShP7mEPZr/ckMsEAQZGrTlVnYlAd1DTsIDFgGFdGHSPgtGGxxRxBpo+/mzmLi+/lDbLymIYoQ7L1Zte8Lb7tqsDEXe9RzIJHcWF1DAbABB33s/Gel7KSm1l3y11X9FRrCU29ytIRtUdA5un4bZAmUHuVnttzBQzEVHf10/bkny38Iyo69v0LwWZJ04WkrUd4v2B5JnK+KWLHOz5H7wgonraHlLlX0hM8QTDpUgMA0NmOQFHW17ez3xy2PkJg46svtWb1yVB7M4Pz3Aod2ery0don7YlJCYJiY8uNFIeg== x-ms-office365-filtering-correlation-id: f5372d3e-d9be-4055-b996-08d4825e7c0b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081);SRVR:AM5PR0802MB2388; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(20161123562025)(20161123564025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(6072148);SRVR:AM5PR0802MB2388;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2388; x-forefront-prvs: 02760F0D1C x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(39860400002)(39840400002)(39450400003)(39410400002)(39400400002)(39850400002)(53754006)(24454002)(33656002)(50986999)(102836003)(53936002)(54356999)(6246003)(55016002)(6116002)(54906002)(5660300001)(3846002)(99286003)(9686003)(122556002)(66066001)(7696004)(189998001)(2900100001)(6436002)(7736002)(77096006)(6506006)(74316002)(6636002)(229853002)(3660700001)(3280700002)(25786009)(81166006)(86362001)(8676002)(38730400002)(4326008)(2906002)(305945005)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM5PR0802MB2388;H:AM5PR0802MB2610.eurprd08.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Apr 2017 11:16:08.2880 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2388 X-SW-Source: 2017-04/txt/msg00622.txt.bz2 >On Wed, Apr 12, 2017 at 09:29:55AM +0000, Sudi Das wrote: > > Hi all > >=20 > > This is a fix for PR 80131=20 > > Currently the code A << (B - C) is not simplified. >> However at least a more specific case of 1U << (C -x) where C =3D precis= ion(type) - 1 can be simplified to (1 << C) >> x. > > Is that always a win though? Yes assuming left and right shift have the same performance. > Some constants have higher costs than others on various targets, some > significantly higher. This change might be beneficial only > if if C is as expensive as 1, then you get rid of a one (typically cheap) > operation. Most targets can create the constant cheaply. Targets that can't would need= 2 instructions (move+shift) or a literal load. That's not worse compared to t= he original sequence (3 operations). The constant can be shared or lifted out = of a loop, so we're saving 1 subtract per use of the sequence. > Which makes me wonder whether this should be done at GIMPLE time and not > at RTL time (expansion or combine etc.) when one can compare the RTX cost= s. > Or do this at match.pd as canonicalization and then have RTL transformati= on > to rewrite such (1U << C) >> X as 1U << (C - X) if the latter is faster (= or > shorter). I can't see why that would be useful for just this pattern. There are lots = more useful cases where GCC should simplify immediates to fit the target but it doesn't= currently. For example it changes x < 0x100000 to x <=3D 0xfffff which is worse on man= y targets. Wilco