From patchwork Mon Oct 16 12:27:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 153365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3422574vqb; Mon, 16 Oct 2023 05:27:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKveraQ/RfRLKh1NrKlTZ75F2m46334usw4vyj2opXj9ezDyXtbD3bEaUJ/kz3SI35IcIK X-Received: by 2002:ac8:5ad5:0:b0:418:15ab:85b8 with SMTP id d21-20020ac85ad5000000b0041815ab85b8mr43369511qtd.13.1697459267751; Mon, 16 Oct 2023 05:27:47 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d2-20020a05622a15c200b00418194af9ecsi5226899qty.51.2023.10.16.05.27.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 05:27:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="vP7v6J/n"; dkim=pass header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b="vP7v6J/n"; arc=fail (previous hop failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 839B73858032 for ; Mon, 16 Oct 2023 12:27:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2041.outbound.protection.outlook.com [40.107.21.41]) by sourceware.org (Postfix) with ESMTPS id E43D03858C2A for ; Mon, 16 Oct 2023 12:27:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E43D03858C2A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E43D03858C2A Authentication-Results: server2.sourceware.org; arc=fail smtp.remote-ip=40.107.21.41 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697459241; cv=fail; b=i1T6ph4j8vs8yX0A0nCDwgDJEdrxqV7JzScdN1m9fTt+JQf35B1f5KA/dpBgkgWqc+/L0GoyRCDv2aiQBl7auKp8lTo2NxmINH8/6TxM7I/uHm6VuYc201OFLtxUWMK7oNNqaeFmsVtFTNBWmtuvzU6UQ9Ek8JyFEkF7qfTZ2Nc= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1697459241; c=relaxed/simple; bh=wndXF/7x2VIykXJGweNIaVi1G5ruPf4oFu7v0SSy3PQ=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=u9/CsCHfscGxfWY0WJEBd9aiMth5mU858XkJSjkJDRxXwKkai6MS5OojSWLQJbz1hXxoyeRgX0qraK4TGTwGZmUl0pziN9+FhuWNKsR22p1KSZEPIXnEr8J4MITcBx83Ais2X5UBJ6A7HoIJH0EzvtADf0dmEMnnQmF3ar/jTDY= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zmlSwyT9UXA4MyDCdQKutwlWw8X5LZXcX7Dz7ZrpR4g=; b=vP7v6J/ny03jjrGFrygjG/eF13AwhWhjg0KEy4BmfHqk0XpQH7Z/8Hoyy99+zPAUdjWPVYbCVM5qXmYu2T3SSPacJYG6THYxAshBMl8XaydmQUN4+g/CM/7CiYb96y0DZEb5J8S9CjdqKj6C35ByUUy7zfJw9uu+tFTn9kDVopQ= Received: from AM6P194CA0035.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::48) by PA6PR08MB10420.eurprd08.prod.outlook.com (2603:10a6:102:3d2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 12:27:15 +0000 Received: from AMS0EPF000001AD.eurprd05.prod.outlook.com (2603:10a6:209:90:cafe::5a) by AM6P194CA0035.outlook.office365.com (2603:10a6:209:90::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 12:27:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AMS0EPF000001AD.mail.protection.outlook.com (10.167.16.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 12:27:15 +0000 Received: ("Tessian outbound fb5c0777b309:v211"); Mon, 16 Oct 2023 12:27:14 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8d166c920e003cab X-CR-MTA-TID: 64aa7808 Received: from 9d6c38f3529a.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D2FFE73E-A8DA-4476-BDE0-EE5D114B0754.1; Mon, 16 Oct 2023 12:27:08 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 9d6c38f3529a.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 16 Oct 2023 12:27:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lMr5gwNWeTBqGgqlDqqPhKzCt2/8lFYvs5idz3myzVhRZpCOcEysbKf6POIT+YHpNkpxA7kAAWOVC/aiODIE0/gRYJyA8pO+AX5F7u/CMxyzOqhOYdVdXrC95ZYxQ86JcTxozKNOuz76bLZCl1TaYimBZ+FFPKbbl5eHbow/ekeBPrHRzf40+H0jrrbXmkbpN73OJa5MWXPTKS4QzdJMyo0eXKW3IVgSc2odt89KEZu2wxMTjvr6gE1rURZaatDwRUe7MUWIi9vqZq9RhEDbbLVu8padrls0yrtuMu5Lh2HnM5gAyIGcYeSkCjIDaWtqaAMCeYkj+tchmNnTuOQpHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zmlSwyT9UXA4MyDCdQKutwlWw8X5LZXcX7Dz7ZrpR4g=; b=O5/0jz64jSBmr6CurtcIh1zADO/p9HmB6cxmLBngK8KbZsN3OdnJZiU3mxH/MrmECoH8tzRJJP7BKn1TcYoLHH6pYrOv6YD97QSpq99FvvlOiF9X5/15484loPUa7jIPibSjdfHzBwd4hhCWTBPc5tC3LCmibzVfY4uDSFFNhpErgg+aOoxZ4SXPB9dTr4lGAM5MZXcM91186IAg23GTncRYwaMRkkF0LEFfqxeyD7cYKlEha1KkLa+1Lv4OD6VWRvwbnh+s1t/ce6DfIQW1NKOE1ZdpsP7mEI6am0gdg+cnH3QgEmqFlZmfJrWz5jPrv9qZqgpw3ifuFshK0oboog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zmlSwyT9UXA4MyDCdQKutwlWw8X5LZXcX7Dz7ZrpR4g=; b=vP7v6J/ny03jjrGFrygjG/eF13AwhWhjg0KEy4BmfHqk0XpQH7Z/8Hoyy99+zPAUdjWPVYbCVM5qXmYu2T3SSPacJYG6THYxAshBMl8XaydmQUN4+g/CM/7CiYb96y0DZEb5J8S9CjdqKj6C35ByUUy7zfJw9uu+tFTn9kDVopQ= Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by GV2PR08MB9302.eurprd08.prod.outlook.com (2603:10a6:150:d4::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Mon, 16 Oct 2023 12:27:05 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::31cd:30d1:37a7:3e8]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::31cd:30d1:37a7:3e8%4]) with mapi id 15.20.6886.034; Mon, 16 Oct 2023 12:27:05 +0000 From: Wilco Dijkstra To: GCC Patches CC: Richard Sandiford , Richard Earnshaw Subject: [PATCH v2] AArch64: Add inline memmove expansion Thread-Topic: [PATCH v2] AArch64: Add inline memmove expansion Thread-Index: AQHaACsZ3TFocMu4B0Ow6liA9vXqVg== Date: Mon, 16 Oct 2023 12:27:05 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: PAWPR08MB8982:EE_|GV2PR08MB9302:EE_|AMS0EPF000001AD:EE_|PA6PR08MB10420:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c917573-a839-43d1-ad4c-08dbce433b07 x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 0i9hAhtaI/x8w85Fy4FmUMh3HasU8zPbxXh8fnsgOEerG6ro9yfubuYnvyJ5WmtJreEjrTorJSdxkAXqoeVe+GR6hL4rxzjBISxWAgEAKIBlowTkjeoFs/1VNt5yLt1t1KCr4gLjFUxXmipdCfG+zDtfBdfHFpAsouwfwLFmziiFWxI/8XjqN09cega080+cG+ipUvjxuwX3H7VyqWGyRh+Lgdtg/TY/82gyyOSXp1ZxPHavxttvwgvu1zeoKW1Tepqzwk0OUgzPX5IahubakPJ70/LTGI4vIM13eQ9ViAPipp7k1aEsujRk+eGYd92ISDsZvL5ugqnnVm+e90MyvNBMoFWx52ADk/nhBbBA7lp3u7GRQTSvfgVQ9R0HE+7wBUeu/TluT/eqec7MqzaiEI9/csgmMU+zvjaYWCIZiJgCQpnFSewRY0tIWHXaxybOy9fHyIlulPwih+MLUNFhpS2CwM1bhn/c42yfutTUoRJDlvFUjPyt766VPULhs9PrsmHKszfLtqeZn21WSzBRuOH2L0CEA4T/ytOI0YBGwVQbQ3ssXBSuDKVnWRiXe5sUGbKsxhTxVt9aHmaXcf736SZZ0tJ91h4wD4xdu6GNiTg= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAWPR08MB8982.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(136003)(366004)(376002)(346002)(39860400002)(396003)(230922051799003)(451199024)(186009)(64100799003)(1800799009)(55016003)(84970400001)(122000001)(38070700005)(38100700002)(83380400001)(9686003)(26005)(6506007)(71200400001)(7696005)(66446008)(316002)(76116006)(66946007)(6916009)(478600001)(66556008)(91956017)(64756008)(66476007)(54906003)(30864003)(2906002)(33656002)(41300700001)(86362001)(8676002)(8936002)(4326008)(52536014)(5660300002); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB9302 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AMS0EPF000001AD.eurprd05.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 1bd58eeb-87f6-4594-9556-08dbce433581 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qc3D+pEn0oUSt4SuHoXUvXq51Qn/AqIthl9n9Yvz0vpB/tjurucwO3IJZgr5RMthb5ncozZy/tpfecsCte30NRUCCMmUfAI702SBkQvDQuEKIi5F4Ph3z6RsFRzECcJEP+IJaPjSb03CAKRoKSgF7r4WCrSr9TMIlT5KQUj5o3kkm+Fn6SoHdeXFFsiF4BLcckHi3PYdRrLcYiZwtOjXVXnfmvRS2MtXLRzhEiejOEmke3pCEQSJE8lh51Co8Xp1VORqd3H6q+6NDm97npgt5yAsUOLmEzw/MNWFJSiEMwKlJiRAqDalYZoiV1NigPqnjWJrQ8lBFo6gMHEIERSRDWsxAl5kvv+/57jfse0Ak7D9xfM7VTRl87ur+/D5PS+I8WKBXVCFeXUWkYiK7QYjayhHHWVxZZoAn9v7xuY5STDGKwSRDESXi3UqBdtKyVCDxi0OYQ6CJTs/i8vFqedqy6kQPtvI1uxKB+Jx1/RZ962ZWaSxhQZU5b2Z19Kx0U136FOa7xboy86dQA87SroqOWhqMrR/lNrN2X0u40LDaWrITrkPYwcUuiXKk2Mulol2Ev1iJ49E/3mgheP16WWgmnhDzgG07oUI7s5Bup1hGnMK2bCFC/OpKlZxsjMxHcl49DAC1wccRk8LsCIl+6PIODHyptr0dRM5qiyqVkzs8MzfwTcXcx/yrEpX8PVVpePBAebGyJMdyJLE3BconSct8fSfZ5uWRnA5uP1iWyUK5Hs= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(4636009)(136003)(396003)(376002)(346002)(39860400002)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(82310400011)(46966006)(36840700001)(40470700004)(84970400001)(55016003)(40480700001)(40460700003)(478600001)(70586007)(54906003)(70206006)(6916009)(47076005)(83380400001)(36860700001)(86362001)(356005)(82740400003)(9686003)(41300700001)(26005)(6506007)(316002)(7696005)(336012)(33656002)(5660300002)(81166007)(4326008)(52536014)(30864003)(8936002)(8676002)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 12:27:15.0921 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c917573-a839-43d1-ad4c-08dbce433b07 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF000001AD.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA6PR08MB10420 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779915049197318074 X-GMAIL-MSGID: 1779915049197318074 v2: further cleanups, improved comments Add support for inline memmove expansions. The generated code is identical as for memcpy, except that all loads are emitted before stores rather than being interleaved. The maximum size is 256 bytes which requires at most 16 registers. Passes regress/bootstrap, OK for commit? gcc/ChangeLog/ * config/aarch64/aarch64.opt (aarch64_mops_memmove_size_threshold): Change default. * config/aarch64/aarch64.md (cpymemdi): Add a parameter. (movmemdi): Call aarch64_expand_cpymem. * config/aarch64/aarch64.cc (aarch64_copy_one_block): Rename function, simplify, support storing generated loads/stores. (aarch64_expand_cpymem): Support expansion of memmove. * config/aarch64/aarch64-protos.h (aarch64_expand_cpymem): Add bool arg. gcc/testsuite/ChangeLog/ * gcc.target/aarch64/memmove.c: Add new test. diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h index 60a55f4bc1956786ea687fc7cad7ec9e4a84e1f0..0d39622bd2826a3fde54d67b5c5da9ee9286cbbd 100644 --- a/gcc/config/aarch64/aarch64-protos.h +++ b/gcc/config/aarch64/aarch64-protos.h @@ -769,7 +769,7 @@ bool aarch64_emit_approx_sqrt (rtx, rtx, bool); tree aarch64_vector_load_decl (tree); void aarch64_expand_call (rtx, rtx, rtx, bool); bool aarch64_expand_cpymem_mops (rtx *, bool); -bool aarch64_expand_cpymem (rtx *); +bool aarch64_expand_cpymem (rtx *, bool); bool aarch64_expand_setmem (rtx *); bool aarch64_float_const_zero_rtx_p (rtx); bool aarch64_float_const_rtx_p (rtx); diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 2fa5d09de85d385c1165e399bcc97681ef170916..e19e2d1de2e5b30eca672df05d9dcc1bc106ecc8 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -25238,52 +25238,37 @@ aarch64_progress_pointer (rtx pointer) return aarch64_move_pointer (pointer, GET_MODE_SIZE (GET_MODE (pointer))); } -/* Copy one MODE sized block from SRC to DST, then progress SRC and DST by - MODE bytes. */ +/* Copy one block of size MODE from SRC to DST at offset OFFSET. */ static void -aarch64_copy_one_block_and_progress_pointers (rtx *src, rtx *dst, - machine_mode mode) +aarch64_copy_one_block (rtx *load, rtx *store, rtx src, rtx dst, + int offset, machine_mode mode) { - /* Handle 256-bit memcpy separately. We do this by making 2 adjacent memory - address copies using V4SImode so that we can use Q registers. */ - if (known_eq (GET_MODE_BITSIZE (mode), 256)) + /* Emit explict load/store pair instructions for 32-byte copies. */ + if (known_eq (GET_MODE_SIZE (mode), 32)) { mode = V4SImode; + rtx src1 = adjust_address (src, mode, offset); + rtx src2 = adjust_address (src, mode, offset + 16); + rtx dst1 = adjust_address (dst, mode, offset); + rtx dst2 = adjust_address (dst, mode, offset + 16); rtx reg1 = gen_reg_rtx (mode); rtx reg2 = gen_reg_rtx (mode); - /* "Cast" the pointers to the correct mode. */ - *src = adjust_address (*src, mode, 0); - *dst = adjust_address (*dst, mode, 0); - /* Emit the memcpy. */ - emit_insn (aarch64_gen_load_pair (mode, reg1, *src, reg2, - aarch64_progress_pointer (*src))); - emit_insn (aarch64_gen_store_pair (mode, *dst, reg1, - aarch64_progress_pointer (*dst), reg2)); - /* Move the pointers forward. */ - *src = aarch64_move_pointer (*src, 32); - *dst = aarch64_move_pointer (*dst, 32); + *load = aarch64_gen_load_pair (mode, reg1, src1, reg2, src2); + *store = aarch64_gen_store_pair (mode, dst1, reg1, dst2, reg2); return; } rtx reg = gen_reg_rtx (mode); - - /* "Cast" the pointers to the correct mode. */ - *src = adjust_address (*src, mode, 0); - *dst = adjust_address (*dst, mode, 0); - /* Emit the memcpy. */ - emit_move_insn (reg, *src); - emit_move_insn (*dst, reg); - /* Move the pointers forward. */ - *src = aarch64_progress_pointer (*src); - *dst = aarch64_progress_pointer (*dst); + *load = gen_move_insn (reg, adjust_address (src, mode, offset)); + *store = gen_move_insn (adjust_address (dst, mode, offset), reg); } /* Expand a cpymem/movmem using the MOPS extension. OPERANDS are taken from the cpymem/movmem pattern. IS_MEMMOVE is true if this is a memmove rather than memcpy. Return true iff we succeeded. */ bool -aarch64_expand_cpymem_mops (rtx *operands, bool is_memmove = false) +aarch64_expand_cpymem_mops (rtx *operands, bool is_memmove) { if (!TARGET_MOPS) return false; @@ -25302,51 +25287,48 @@ aarch64_expand_cpymem_mops (rtx *operands, bool is_memmove = false) return true; } -/* Expand cpymem, as if from a __builtin_memcpy. Return true if - we succeed, otherwise return false, indicating that a libcall to - memcpy should be emitted. */ - +/* Expand cpymem/movmem, as if from a __builtin_memcpy/memmove. + OPERANDS are taken from the cpymem/movmem pattern. IS_MEMMOVE is true + if this is a memmove rather than memcpy. Return true if we succeed, + otherwise return false, indicating that a libcall should be emitted. */ bool -aarch64_expand_cpymem (rtx *operands) +aarch64_expand_cpymem (rtx *operands, bool is_memmove) { - int mode_bits; + int mode_bytes; rtx dst = operands[0]; rtx src = operands[1]; unsigned align = UINTVAL (operands[3]); rtx base; - machine_mode cur_mode = BLKmode; - bool size_p = optimize_function_for_size_p (cfun); + machine_mode cur_mode = BLKmode, next_mode; /* Variable-sized or strict-align copies may use the MOPS expansion. */ if (!CONST_INT_P (operands[2]) || (STRICT_ALIGNMENT && align < 16)) - return aarch64_expand_cpymem_mops (operands); + return aarch64_expand_cpymem_mops (operands, is_memmove); unsigned HOST_WIDE_INT size = UINTVAL (operands[2]); - /* Try to inline up to 256 bytes. */ - unsigned max_copy_size = 256; - unsigned mops_threshold = aarch64_mops_memcpy_size_threshold; + /* Set inline limits for memmove/memcpy. MOPS has a separate threshold. */ + unsigned max_copy_size = TARGET_SIMD ? 256 : 128; + unsigned mops_threshold = is_memmove ? aarch64_mops_memmove_size_threshold + : aarch64_mops_memcpy_size_threshold; + + /* Reduce the maximum size with -Os. */ + if (optimize_function_for_size_p (cfun)) + max_copy_size /= 4; /* Large copies use MOPS when available or a library call. */ if (size > max_copy_size || (TARGET_MOPS && size > mops_threshold)) - return aarch64_expand_cpymem_mops (operands); + return aarch64_expand_cpymem_mops (operands, is_memmove); - int copy_bits = 256; + unsigned copy_max = 32; - /* Default to 256-bit LDP/STP on large copies, however small copies, no SIMD - support or slow 256-bit LDP/STP fall back to 128-bit chunks. */ + /* Default to 32-byte LDP/STP on large copies, however small copies, no SIMD + support or slow LDP/STP fall back to 16-byte chunks. */ if (size <= 24 || !TARGET_SIMD || (aarch64_tune_params.extra_tuning_flags & AARCH64_EXTRA_TUNE_NO_LDP_STP_QREGS)) - copy_bits = 128; - - /* Emit an inline load+store sequence and count the number of operations - involved. We use a simple count of just the loads and stores emitted - rather than rtx_insn count as all the pointer adjustments and reg copying - in this function will get optimized away later in the pipeline. */ - start_sequence (); - unsigned nops = 0; + copy_max = 16; base = copy_to_mode_reg (Pmode, XEXP (dst, 0)); dst = adjust_automodify_address (dst, VOIDmode, base, 0); @@ -25354,69 +25336,60 @@ aarch64_expand_cpymem (rtx *operands) base = copy_to_mode_reg (Pmode, XEXP (src, 0)); src = adjust_automodify_address (src, VOIDmode, base, 0); - /* Convert size to bits to make the rest of the code simpler. */ - int n = size * BITS_PER_UNIT; + const int max_ops = 40; + rtx load[max_ops], store[max_ops]; - while (n > 0) + int nops, offset; + + for (nops = 0, offset = 0; size > 0; nops++) { /* Find the largest mode in which to do the copy in without over reading or writing. */ opt_scalar_int_mode mode_iter; FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_INT) - if (GET_MODE_BITSIZE (mode_iter.require ()) <= MIN (n, copy_bits)) + if (GET_MODE_SIZE (mode_iter.require ()) <= MIN (size, copy_max)) cur_mode = mode_iter.require (); - gcc_assert (cur_mode != BLKmode); + gcc_assert (cur_mode != BLKmode && nops < max_ops); - mode_bits = GET_MODE_BITSIZE (cur_mode).to_constant (); + mode_bytes = GET_MODE_SIZE (cur_mode).to_constant (); /* Prefer Q-register accesses for the last bytes. */ - if (mode_bits == 128 && copy_bits == 256) + if (mode_bytes == 16 && copy_max == 32) cur_mode = V4SImode; - aarch64_copy_one_block_and_progress_pointers (&src, &dst, cur_mode); - /* A single block copy is 1 load + 1 store. */ - nops += 2; - n -= mode_bits; + aarch64_copy_one_block (&load[nops], &store[nops], src, dst, offset, cur_mode); + size -= mode_bytes; + offset += mode_bytes; /* Emit trailing copies using overlapping unaligned accesses - (when !STRICT_ALIGNMENT) - this is smaller and faster. */ - if (n > 0 && n < copy_bits / 2 && !STRICT_ALIGNMENT) + (when !STRICT_ALIGNMENT) - this is smaller and faster. */ + if (size > 0 && size < copy_max / 2 && !STRICT_ALIGNMENT) { - machine_mode next_mode = smallest_mode_for_size (n, MODE_INT); - int n_bits = GET_MODE_BITSIZE (next_mode).to_constant (); - gcc_assert (n_bits <= mode_bits); - src = aarch64_move_pointer (src, (n - n_bits) / BITS_PER_UNIT); - dst = aarch64_move_pointer (dst, (n - n_bits) / BITS_PER_UNIT); - n = n_bits; + next_mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT); + int n_bytes = GET_MODE_SIZE (next_mode).to_constant (); + gcc_assert (n_bytes <= mode_bytes); + offset -= n_bytes - size; + size = n_bytes; } } - rtx_insn *seq = get_insns (); - end_sequence (); - /* MOPS sequence requires 3 instructions for the memory copying + 1 to move - the constant size into a register. */ - unsigned mops_cost = 3 + 1; - - /* If MOPS is available at this point we don't consider the libcall as it's - not a win even on code size. At this point only consider MOPS if - optimizing for size. For speed optimizations we will have chosen between - the two based on copy size already. */ - if (TARGET_MOPS) - { - if (size_p && mops_cost < nops) - return aarch64_expand_cpymem_mops (operands); - emit_insn (seq); - return true; - } - /* A memcpy libcall in the worst case takes 3 instructions to prepare the - arguments + 1 for the call. When MOPS is not available and we're - optimizing for size a libcall may be preferable. */ - unsigned libcall_cost = 4; - if (size_p && libcall_cost < nops) - return false; + /* Memcpy interleaves loads with stores, memmove emits all loads first. */ + int i, j, m, inc; + inc = is_memmove ? nops : 3; + if (nops == inc + 1) + inc = nops / 2; + for (i = 0; i < nops; i += inc) + { + m = inc; + if (i + m > nops) + m = nops - i; - emit_insn (seq); + for (j = 0; j < m; j++) + emit_insn (load[i + j]); + for (j = 0; j < m; j++) + emit_insn (store[i + j]); + } return true; } diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index 1cb3a01d6791a48dc0b08df5783d97805448c7f2..18dd629c2456041b1185eae6d39de074709b2a39 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -1629,7 +1629,7 @@ (define_expand "cpymemdi" (match_operand:DI 3 "immediate_operand")] "" { - if (aarch64_expand_cpymem (operands)) + if (aarch64_expand_cpymem (operands, false)) DONE; FAIL; } @@ -1673,17 +1673,9 @@ (define_expand "movmemdi" (match_operand:BLK 1 "memory_operand") (match_operand:DI 2 "general_operand") (match_operand:DI 3 "immediate_operand")] - "TARGET_MOPS" + "" { - rtx sz_reg = operands[2]; - /* For constant-sized memmoves check the threshold. - FIXME: We should add a non-MOPS memmove expansion for smaller, - constant-sized memmove to avoid going to a libcall. */ - if (CONST_INT_P (sz_reg) - && INTVAL (sz_reg) < aarch64_mops_memmove_size_threshold) - FAIL; - - if (aarch64_expand_cpymem_mops (operands, true)) + if (aarch64_expand_cpymem (operands, true)) DONE; FAIL; } diff --git a/gcc/config/aarch64/aarch64.opt b/gcc/config/aarch64/aarch64.opt index f5a518202a157b5b5bc2b2aa14ac1177fded7d66..0ac9d8c578d706e7bf0f0ae399d84544f0c619dc 100644 --- a/gcc/config/aarch64/aarch64.opt +++ b/gcc/config/aarch64/aarch64.opt @@ -327,7 +327,7 @@ Target Joined UInteger Var(aarch64_mops_memcpy_size_threshold) Init(256) Param Constant memcpy size in bytes above which to start using MOPS sequence. -param=aarch64-mops-memmove-size-threshold= -Target Joined UInteger Var(aarch64_mops_memmove_size_threshold) Init(0) Param +Target Joined UInteger Var(aarch64_mops_memmove_size_threshold) Init(256) Param Constant memmove size in bytes above which to start using MOPS sequence. -param=aarch64-mops-memset-size-threshold= diff --git a/gcc/testsuite/gcc.target/aarch64/memmove.c b/gcc/testsuite/gcc.target/aarch64/memmove.c new file mode 100644 index 0000000000000000000000000000000000000000..6926a97761eb2578d3f1db7e6eb19dba17b888be --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/memmove.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void +copy1 (int *x, int *y) +{ + __builtin_memmove (x, y, 12); +} + +void +copy2 (int *x, int *y) +{ + __builtin_memmove (x, y, 128); +} + +void +copy3 (int *x, int *y) +{ + __builtin_memmove (x, y, 255); +} + +/* { dg-final { scan-assembler-not {\tb\tmemmove} } } */