From patchwork Tue Aug 23 14:50:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 661898 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 3sJYKF0bpjz9sDf for ; Wed, 24 Aug 2016 00:50:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ENZXRMoK; 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 :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=EBur8+fUXpAU/KuBNjXKeDZ01gJmHhwN8DQ/ztvl/uQtGM+V5aOXo O6z7iMduGd5jxvVEoRKk1UJ31TK4UQBSd9Wjk0MKlB9Hg2H1XLRah6Ki5nM+eyXk EpBLMKc7XrCT3vA7QJ9CkE8HWckd03WMcvcCHRXeQf/z0YEGRcNe7c= 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 :mime-version:content-type:content-transfer-encoding; s=default; bh=gbVnayYGYdkV9PDQGiXm5cDcCGw=; b=ENZXRMoKo72sMXux0Hxa7JHmaOqn erBUAZzAKTEHieVpA7rM75oGRdsIT9IxlSxPOwKhxN6MUPJtbgcarFS5A3qmf8vr 3TA5PJcIv2xWYsxquCxNq04DsDN/2kacuzgAgv2Bx3gerN8uZKAI9dCf2RNRNA1J DIYhNWyNMs7ducQ= Received: (qmail 27259 invoked by alias); 23 Aug 2016 14:50:47 -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 26033 invoked by uid 89); 23 Aug 2016 14:50:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=enhance, 24000, 6000, intval X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Aug 2016 14:50:36 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01lp0181.outbound.protection.outlook.com [213.199.154.181]) (Using TLS) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-16-IfuBk0NPMMqlvYDfOmn5qA-1; Tue, 23 Aug 2016 15:50:29 +0100 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com (10.175.46.18) by AM5PR0802MB2387.eurprd08.prod.outlook.com (10.175.43.149) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.21; Tue, 23 Aug 2016 14:50:15 +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.0557.027; Tue, 23 Aug 2016 14:50:15 +0000 From: Wilco Dijkstra To: Richard Earnshaw , GCC Patches CC: nd Subject: Re: [PATCH][AArch64] Add legitimize_address_displacement hook Date: Tue, 23 Aug 2016 14:50:15 +0000 Message-ID: References: , , In-Reply-To: x-ms-office365-filtering-correlation-id: 6f58eabf-c033-48da-dc64-08d3cb64cb24 x-microsoft-exchange-diagnostics: 1; AM5PR0802MB2387; 20:Xzz4EimUTHSdvfbEKxa5lWG9CPceyXWGqUjLXS5Cj7vFOMESB3lFIvyoNcY7oGIksbfeTcgCepE9uLri+6EBV+Bfe5yN3CY3IfSaey7UwzYU9zK5b3A+eymkaODVIy9ylsWp9tZjyX2iESFPV5jBekSwNH/uXVntEOZpzgzjAtQ= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2387; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:AM5PR0802MB2387; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2387; x-forefront-prvs: 004395A01C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(377424004)(54534003)(199003)(24454002)(189002)(575784001)(10400500002)(2950100001)(105586002)(106116001)(77096005)(2900100001)(5002640100001)(106356001)(122556002)(11100500001)(5660300001)(450100001)(4326007)(68736007)(33656002)(97736004)(3280700002)(19580395003)(50986999)(76176999)(189998001)(5001770100001)(92566002)(76576001)(66066001)(3660700001)(19580405001)(54356999)(86362001)(81156014)(8676002)(74316002)(7846002)(87936001)(81166006)(102836003)(305945005)(7696003)(101416001)(8936002)(3846002)(6116002)(586003)(9686002)(7736002)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0802MB2387; H:AM5PR0802MB2610.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Aug 2016 14:50:15.2869 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2387 X-MC-Unique: IfuBk0NPMMqlvYDfOmn5qA-1 ping   Richard Earnshaw wrote: > OK.  But please enhance the comment with some explanation as to WHY > you've chosen to use just two base pairings rather than separate bases > for each access size. OK here is the updated patch which also handles unaligned accesses which further improves the benefit: This patch adds legitimize_address_displacement hook so that stack accesses with large offsets are split into a more efficient sequence.  Unaligned and TI/TFmode use a 256-byte range, byte and halfword accesses use a 4KB range, wider accesses use a 16KB range to maximise the available addressing range and increase opportunities to share the base address. int f(int x) {   int arr[8192];   arr[4096] = 0;   arr[6000] = 0;   arr[7000] = 0;   arr[8191] = 0;   return arr[x]; } Now generates:         sub     sp, sp, #32768         add     x1, sp, 16384         str     wzr, [x1]         str     wzr, [x1, 7616]         str     wzr, [x1, 11616]         str     wzr, [x1, 16380]         ldr     w0, [sp, w0, sxtw 2]         add     sp, sp, 32768         ret instead of:         sub     sp, sp, #32768         mov     x2, 28000         add     x1, sp, 16384         mov     x3, 32764         str     wzr, [x1]         mov     x1, 24000         add     x1, sp, x1         str     wzr, [x1]         add     x1, sp, x2         str     wzr, [x1]         add     x1, sp, x3         str     wzr, [x1]         ldr     w0, [sp, w0, sxtw 2]         add     sp, sp, 32768         ret Bootstrap, GCC regression OK. ChangeLog: 2016-08-10  Wilco Dijkstra      gcc/         * config/aarch64/aarch64.c (aarch64_legitimize_address_displacement):         New function.         (TARGET_LEGITIMIZE_ADDRESS_DISPLACEMENT): Define. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 9a5fc199128b1326d0fb2afe0833aa6a5ce62ddf..b8536175a84b76f8c2939e61f1379ae279b20d43 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -4173,6 +4173,24 @@ aarch64_legitimate_address_p (machine_mode mode, rtx x,    return aarch64_classify_address (&addr, x, mode, outer_code, strict_p);  }   +/* Split an out-of-range address displacement into a base and offset. +   Use 4KB range for 1- and 2-byte accesses and a 16KB range otherwise +   to increase opportunities for sharing the base address of different sizes. +   For TI/TFmode and unaligned accesses use a 256-byte range.  */ +static bool +aarch64_legitimize_address_displacement (rtx *disp, rtx *off, machine_mode mode) +{ +  HOST_WIDE_INT mask = GET_MODE_SIZE (mode) < 4 ? 0xfff : 0x3fff; + +  if (mode == TImode || mode == TFmode || +      (INTVAL (*disp) & (GET_MODE_SIZE (mode) - 1)) != 0) +     mask = 0xff; + +  *off = GEN_INT (INTVAL (*disp) & ~mask); +  *disp = GEN_INT (INTVAL (*disp) & mask); +  return true; +} +  /* Return TRUE if rtx X is immediate constant 0.0 */  bool  aarch64_float_const_zero_rtx_p (rtx x) @@ -14137,6 +14155,10 @@ aarch64_optab_supported_p (int op, machine_mode mode1, machine_mode,  #undef TARGET_LEGITIMATE_CONSTANT_P  #define TARGET_LEGITIMATE_CONSTANT_P aarch64_legitimate_constant_p   +#undef TARGET_LEGITIMIZE_ADDRESS_DISPLACEMENT +#define TARGET_LEGITIMIZE_ADDRESS_DISPLACEMENT \ +  aarch64_legitimize_address_displacement +  #undef TARGET_LIBGCC_CMP_RETURN_MODE  #define TARGET_LIBGCC_CMP_RETURN_MODE aarch64_libgcc_cmp_return_mode