From patchwork Tue Aug 1 10:19:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 796160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-459489-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Wq6LN3yD"; dkim-atps=neutral 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 3xMC4V00fpz9tWW for ; Tue, 1 Aug 2017 20:20:09 +1000 (AEST) 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:content-transfer-encoding:mime-version; q=dns; s= default; b=CP/vX0Uc22orHDeAcsFviwoL33XDhtZyJiUdAV616SXmBEqeXW8f3 Cml4W5Ycs5APDk1VGw4g3ldlTCESevPphV4pB8Xhbq+W6TsZJiKye1GZVILdqfyA YqEMMohfyNS03tLL95rkTcdzl5t9jEBcSBOHoJyGq+9dH3Ux2yU97k= 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:content-transfer-encoding:mime-version; s=default; bh=oWso4dcgJyp6ei7+0N2ZDYo1HNI=; b=Wq6LN3yD8/0lplfBzOiwfOyS1rhS 5dkDWIRTMHvMAXyUEM6gTMz8snhhlL1BZ9fsPq1Lv/7vXK8SowgvVlZnMXWRuX0t YUaYw5/V1gmj8juiWDjXmunf89+DysFZgExA3JyaDFrtpKUbGHP1XblyC6f1sXrv oAprT8QwzaFONpQ= Received: (qmail 32565 invoked by alias); 1 Aug 2017 10:20: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 32531 invoked by uid 89); 1 Aug 2017 10:20:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=013, Hx-languages-length:3204 X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com Received: from mail-db5eur01on0058.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (104.47.2.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Aug 2017 10:19:59 +0000 Received: from HE1PR0801MB2058.eurprd08.prod.outlook.com (10.168.95.23) by AM4PR08MB2657.eurprd08.prod.outlook.com (10.171.190.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1304.22; Tue, 1 Aug 2017 10:19:56 +0000 Received: from HE1PR0801MB2058.eurprd08.prod.outlook.com ([fe80::896b:eb4a:ed05:60f1]) by HE1PR0801MB2058.eurprd08.prod.outlook.com ([fe80::896b:eb4a:ed05:60f1%18]) with mapi id 15.01.1304.022; Tue, 1 Aug 2017 10:19:56 +0000 From: Wilco Dijkstra To: GCC Patches , James Greenhalgh CC: nd Subject: Re: [PATCH][AArch64] Improve aarch64_legitimate_constant_p Date: Tue, 1 Aug 2017 10:19:55 +0000 Message-ID: References: , , In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR08MB2657; 7:Ouf04XJwMENE/sAK8PGPeQxZoknDBq8M6bDu4fwKkRN3xwKZa6270XgpENykV3oatOvD+WE9uCJcb5sFZFaotl967XY1z3DYNHoKwdBuE6JYuBWjulAbg8yHal2AybNVhUX7/HwDOR6AkCpKilm7ogpDlysHnq9E15rTJUCGGU0gJZUkImprZEmuggtpNJpUzP3JP9vT1xxQsj79DEnJQfnpJ07k0b6albeD3OUQSH1lBpP5LlQQIA+k9XYp1lqnBSVXTnwDq52IWXWnPNDEJ6YW8hOu8ub3FVBOZIbYHInCrYKhc0W+MOCfM3xotNuUQSQvU1T3Hpoo+Bt7jCfwFhU9jGAgdSk5hAnWNGDx2guDkEHggCKlG1iegKVkfK1Bj6+WjUdwGy1Wcelo6SE+dhpV6xGaoLcgIOF3IN8YgUTMIEIRyPZmkGfgtFbKqfd9ZCPHSyF9wt/5XMV9zjo2O7haS+osF1LCwghfYbiyoFrniaBfN4ct2N3q9/yg9Fp4r61Wb5wnNlhcKC4eMn8gtO+VjPU/ayLkZuhjVzxaTgKw2sErZRcVhjLwHt5k8a2SSQlCc0o8UHxy224wCYFLlx8JAtXrV8/OWcd3yN0Bk4Ev+Bk9SsqGWKw6M/v2tpWqJIjuFaeYiqwEW1XokSmCsJb4vINzT0ngU2uN4smg/deNQg+Ydk0cWj0t7e3mHT0cpuW/XXGbVHPII/Lc1SxOBz1LCneYs1FmME4xUnFSOnav13s0NIksUiKCuCZ44T85cAfU3GJDSc2zsJUkZjmTSx4CiP66IKNIGdkTyenw/VE= x-ms-office365-filtering-correlation-id: 04ab7bc5-560c-4f68-40dd-08d4d8c6db4e x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM4PR08MB2657; x-ms-traffictypediagnostic: AM4PR08MB2657: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(93006095)(93001095)(3002001)(10201501046)(6055026)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(20161123560025)(20161123558100)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR08MB2657; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR08MB2657; x-forefront-prvs: 0386B406AA x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(39450400003)(39840400002)(39410400002)(39400400002)(39850400002)(54534003)(189002)(377424004)(199003)(4326008)(2950100002)(33656002)(14454004)(189998001)(7736002)(97736004)(305945005)(101416001)(8936002)(74316002)(50986999)(5660300001)(7696004)(3280700002)(81156014)(81166006)(8676002)(5250100002)(72206003)(76176999)(54356999)(3660700001)(68736007)(6246003)(106356001)(478600001)(38730400002)(6506006)(9686003)(6636002)(2900100001)(105586002)(2906002)(3846002)(102836003)(6116002)(25786009)(86362001)(66066001)(6436002)(229853002)(53936002)(99286003)(55016002)(15760500002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB2657; H:HE1PR0801MB2058.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Aug 2017 10:19:55.9295 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2657 ping     This patch further improves aarch64_legitimate_constant_p.  Allow all integer, floating point and vector constants.  Allow label references and non-anchor symbols with an immediate offset.  This allows such constants to be rematerialized, resulting in smaller code and fewer stack spills. SPEC2006 codesize reduces by 0.08%, SPEC2017 by 0.13%. Bootstrap OK, OK for commit? ChangeLog: 2017-07-07  Wilco Dijkstra          * config/aarch64/aarch64.c (aarch64_legitimate_constant_p):         Return true for more constants, symbols and label references.         (aarch64_valid_floating_const): Remove unused function. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index a2eca64a9c13e44d223b5552c079ef4e09659e84..810c17416db01681e99a9eb8cc9f5af137ed2054 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -10173,49 +10173,46 @@ aarch64_legitimate_pic_operand_p (rtx x)    return true;  }   -/* Return true if X holds either a quarter-precision or -     floating-point +0.0 constant.  */ -static bool -aarch64_valid_floating_const (machine_mode mode, rtx x) -{ -  if (!CONST_DOUBLE_P (x)) -    return false; - -  if (aarch64_float_const_zero_rtx_p (x)) -    return true; - -  /* We only handle moving 0.0 to a TFmode register.  */ -  if (!(mode == SFmode || mode == DFmode)) -    return false; - -  return aarch64_float_const_representable_p (x); -} +/* Implement TARGET_LEGITIMATE_CONSTANT_P hook.  Return true for constants +   that should be rematerialized rather than spilled.  */    static bool  aarch64_legitimate_constant_p (machine_mode mode, rtx x)  { +  /* Support CSE and rematerialization of common constants.  */ +  if (CONST_INT_P (x) || CONST_DOUBLE_P (x) || GET_CODE (x) == CONST_VECTOR) +    return true; +    /* Do not allow vector struct mode constants.  We could support       0 and -1 easily, but they need support in aarch64-simd.md.  */ -  if (TARGET_SIMD && aarch64_vect_struct_mode_p (mode)) +  if (aarch64_vect_struct_mode_p (mode))      return false;   -  /* This could probably go away because -     we now decompose CONST_INTs according to expand_mov_immediate.  */ -  if ((GET_CODE (x) == CONST_VECTOR -       && aarch64_simd_valid_immediate (x, mode, false, NULL)) -      || CONST_INT_P (x) || aarch64_valid_floating_const (mode, x)) -       return !targetm.cannot_force_const_mem (mode, x); +  /* Do not allow wide int constants - this requires support in movti.  */ +  if (CONST_WIDE_INT_P (x)) +    return false;   -  if (GET_CODE (x) == HIGH -      && aarch64_valid_symref (XEXP (x, 0), GET_MODE (XEXP (x, 0)))) -    return true; +  /* Do not allow const (plus (anchor_symbol, const_int)).  */ +  if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS) +  { +    x = XEXP (XEXP (x, 0), 0); +    if (SYMBOL_REF_P (x) && SYMBOL_REF_ANCHOR_P (x)) +      return false; +  } + +  if (GET_CODE (x) == HIGH) +    x = XEXP (x, 0);      /* Treat symbols as constants.  Avoid TLS symbols as they are complex,       so spilling them is better than rematerialization.  */    if (SYMBOL_REF_P (x) && !SYMBOL_REF_TLS_MODEL (x))      return true;   -  return aarch64_constant_address_p (x); +  /* Label references are always constant.  */ +  if (GET_CODE (x) == LABEL_REF) +    return true; + +  return false;  }    rtx