From patchwork Fri Jul 7 11:28:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 785438 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 3x3sn04ZCjz9s7F for ; Fri, 7 Jul 2017 21:28:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="cM/V2Xf0"; 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:content-type :content-transfer-encoding:mime-version; q=dns; s=default; b=MKn FLwMNktanJi28t03b9UE53BOcLkeB7tyBgHhLcC4mMhlfnaRpqs/rygq0ULmxfCq 6u2Tr9eVXpFjxFq4ZF6GyH02UHLtoW/ip80+rucVxIVCHIUk7Yqg+iUhFNDXAURY SGBedscH1o3mhGepOJHPxiT/esYYYxrsIYLbbTd0= 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:content-type :content-transfer-encoding:mime-version; s=default; bh=PYOeBEPop fLgTiY77HHQ1DN1Z2Q=; b=cM/V2Xf0DQQnediKAIKrR4uaGF5lPEjJGjVmihKFC 4yT/tpGTWdQcn7NfnGUt9WObOFDbOG2fTXzpnr+WpTQhwgafn9Q/nx8ctC/DjzZ3 acP2NddrDP9EygNLK/HkpWYjajpr45JAW0IoCugLjYWSmHrCzH1LdhVe275qd/Xy vM= Received: (qmail 73976 invoked by alias); 7 Jul 2017 11:28:19 -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 73606 invoked by uid 89); 7 Jul 2017 11:28:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 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=0.13, Hx-spam-relays-external:sk:EUR02-A, H*RU:sk:EUR02-A, HX-HELO:sk:EUR02-A X-HELO: EUR02-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr00084.outbound.protection.outlook.com (HELO EUR02-AM5-obe.outbound.protection.outlook.com) (40.107.0.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Jul 2017 11:28:15 +0000 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com (10.175.46.18) by AM4PR08MB2660.eurprd08.prod.outlook.com (10.171.190.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1240.13; Fri, 7 Jul 2017 11:28:12 +0000 Received: from AM5PR0802MB2610.eurprd08.prod.outlook.com ([fe80::b567:13a:e52:92de]) by AM5PR0802MB2610.eurprd08.prod.outlook.com ([fe80::b567:13a:e52:92de%17]) with mapi id 15.01.1240.013; Fri, 7 Jul 2017 11:28:12 +0000 From: Wilco Dijkstra To: GCC Patches , James Greenhalgh CC: nd Subject: [PATCH][AArch64] Improve aarch64_legitimate_constant_p Date: Fri, 7 Jul 2017 11:28:11 +0000 Message-ID: authentication-results: arm.com; dkim=none (message not signed) header.d=none; arm.com; dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR08MB2660; 7:pT0m/kLU6iEVBTERlHlzcLAE42sCOmpTggLDUVcuaPXqDsrrEAlAsDgzYEWzAtHToLm+6rfupdvms0eazMGbDldG49OI2sqONhsiBIq/CKm+hWTl8A8NVX36GgKlfUKM+cmJRO/ovhaZzfuWy/aEqapdnzN6Ht3BcSeJAV/NdfRjdNmV+zZIVAP5LmvSB2j3iigBaouwkwNkVhqyfPOtTd168i37QGA+Ued29a93qirZOVAe3nYcFX2egu0DW8p2GQFubAJbrZ4cK6LksHfHW4F1Dd6UsyNILj5IFAvfNTClr/+ZAle/31d5JSTEPNMV4nJ/gGHlY2LrstCGTYUQMqvIr4zO1rzCESxRAhl3IlwD1wuQpuQuxhooI4ThOUWWz55QqavPs0k/JIzoJOJWP6SQQ4lZApaCGK6vwbUCDayOSzj6l+EFtqA3fppHJV6QmSX48tADQ2t33TL61pmxc6gr3P7EHz947UQR/7E7Ly7WhwjefP+JLzxzV8aWeE8//j7m9CgFrkIZsP7/0FrQvtAod8ZUXx1Hvk+Tj41a5a1VGJWyZKaMVjzYcX1iZjRI1neqg89MdGiqZ6qbCV+Abt1zh1UVF4bigbSgpkiajhFHK3qb11bXHuyMqtg3JjOobNclgCOg8TQSxu5Hwu1N1qaXXtI+W5cdhIHQIlYWNVVuK9t/hYkeSYcWYma37UfbCpaH4co0xKHNWYqqoUJDJ38xFNPeFszNf7Md4DvJg9dJuabsMEASsfQ/56wPfCS1VcO3s5BrAEKyybM7tiSh94GQerPhyyFThgUZ+bCrcAA= x-ms-office365-filtering-correlation-id: 7c13b85f-2401-4228-7db4-08d4c52b407b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(48565401081)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM4PR08MB2660; x-ms-traffictypediagnostic: AM4PR08MB2660: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(133145235818549); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(100000703101)(100105400095)(93006095)(93001095)(10201501046)(6055026)(6041248)(20161123564025)(20161123560025)(20161123558100)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR08MB2660; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR08MB2660; x-forefront-prvs: 0361212EA8 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39840400002)(39410400002)(39400400002)(39450400003)(39860400002)(39850400002)(377424004)(3280700002)(3660700001)(305945005)(74316002)(6506006)(7696004)(2906002)(38730400002)(50986999)(54356999)(5660300001)(99286003)(6436002)(9686003)(55016002)(66066001)(7736002)(3846002)(478600001)(53936002)(6116002)(102836003)(2900100001)(72206003)(33656002)(189998001)(6636002)(14454004)(4326008)(86362001)(5250100002)(25786009)(81166006)(8676002)(8936002)(15760500002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB2660; H:AM5PR0802MB2610.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jul 2017 11:28:11.9691 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2660 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