From patchwork Tue Aug 25 10:18:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Coplan X-Patchwork-Id: 1350976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=wc+7t2Kv; dkim=pass (1024-bit key) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-armh-onmicrosoft-com header.b=wc+7t2Kv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BbQ374yMQz9sTY for ; Tue, 25 Aug 2020 20:19:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE1153857003; Tue, 25 Aug 2020 10:19:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50047.outbound.protection.outlook.com [40.107.5.47]) by sourceware.org (Postfix) with ESMTPS id 4DDED385780F for ; Tue, 25 Aug 2020 10:19:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4DDED385780F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Alex.Coplan@arm.com 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=cpC1Z9zFsfVWM+LBQd6FK5SuMX46ZeqXCIykg7Y1JtQ=; b=wc+7t2Kvb70B2miliMyIDn90HIglzFT+6RCx8pGZyCXa6PGwOpmemibVRByz0r8J/2xh+/pcaPzfX+Mi/yRMwgUmz0YJ1Hrbn/e30yVr+T0nKaC4HVEXInomR/5Uofeax+MWhUFDsmwGa/tCqsqZeDuxkX2OD9NsxcB9NVzmGWU= Received: from AM6PR10CA0097.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::38) by HE1PR0801MB2076.eurprd08.prod.outlook.com (2603:10a6:3:4c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Tue, 25 Aug 2020 10:19:37 +0000 Received: from VE1EUR03FT054.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8c:cafe::b6) by AM6PR10CA0097.outlook.office365.com (2603:10a6:209:8c::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.25 via Frontend Transport; Tue, 25 Aug 2020 10:19:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; gcc.gnu.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;gcc.gnu.org; dmarc=bestguesspass 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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VE1EUR03FT054.mail.protection.outlook.com (10.152.19.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Tue, 25 Aug 2020 10:19:36 +0000 Received: ("Tessian outbound bac899b43a54:v64"); Tue, 25 Aug 2020 10:19:36 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ea804fe9a4e5a509 X-CR-MTA-TID: 64aa7808 Received: from 6ac449f47d93.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A3FE5872-FF8C-4230-806B-322A517D5CE4.1; Tue, 25 Aug 2020 10:18:59 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 6ac449f47d93.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 25 Aug 2020 10:18:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zqw9estAdypmecslyW0tAh6LY1BZY0z7yBvTMzl7+yW2GsXU6STqx+zPyN3aGykeEobf2TkXC8eMhOhbbOUtyZlesl/gfmBoQCqMfy+nYgFSU0Pr6R0Fs2o6CDKmf9Q8mFLmKfAWMQRNT4PEND32hoaqRgKqErQ84PBM549k9tJJfm2MDjMOq4WJ8/axZRs3WJ13OfDFsc87bfHqlf+REMC/wdxMMk3r+/2Dzrz9/SDylEj2x7qXAGqKWRgRE0YyecG+nxDrI3rVsg0lusrwjT3LTYnbKavDajWV3mUSNepb7Idd1dnKeWilQucvjKdGvvk5bujZSRciDtyGfhWY3Q== 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-SenderADCheck; bh=cpC1Z9zFsfVWM+LBQd6FK5SuMX46ZeqXCIykg7Y1JtQ=; b=TRmm1VVEZqykK/Vz+1JkiTORegL2Zh46wAukawTG5pUt7Ic+sBVpt7jefRF+6+mf/lWrlsXhYXGyVSMuCvvwy64oLm13lpHsAeBVNpMDdRVFhAjsAaHqOtQxPm8A554Au29KZKYp6G0ZQc8puKOGCn1wwDbCxXId/j7iqamMeJ/tEwDLRF3kDW/XnPJt9tANFG1fw012cE2kcPmWVqEbvYDiLti5dDrDUMokUUTePezELQaBfHqtq6YmSUrv5XL9ZqLDxmNsC8bxlAjWu3QhC49virm/AxUO9QTN0dqfaTgUX3y3uH42luvWaTMVNzfAZCpurwmaigC0Vih+iFGWwA== 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=cpC1Z9zFsfVWM+LBQd6FK5SuMX46ZeqXCIykg7Y1JtQ=; b=wc+7t2Kvb70B2miliMyIDn90HIglzFT+6RCx8pGZyCXa6PGwOpmemibVRByz0r8J/2xh+/pcaPzfX+Mi/yRMwgUmz0YJ1Hrbn/e30yVr+T0nKaC4HVEXInomR/5Uofeax+MWhUFDsmwGa/tCqsqZeDuxkX2OD9NsxcB9NVzmGWU= Authentication-Results-Original: gcc.gnu.org; dkim=none (message not signed) header.d=none;gcc.gnu.org; dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) by VI1PR0801MB1999.eurprd08.prod.outlook.com (2603:10a6:800:8a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Tue, 25 Aug 2020 10:18:57 +0000 Received: from VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::c194:c7c6:f09e:6f3d]) by VI1PR08MB4029.eurprd08.prod.outlook.com ([fe80::c194:c7c6:f09e:6f3d%7]) with mapi id 15.20.3326.019; Tue, 25 Aug 2020 10:18:57 +0000 Date: Tue, 25 Aug 2020 11:18:55 +0100 From: Alex Coplan To: gcc-patches@gcc.gnu.org Subject: [PATCH] lra: Canonicalize mult to shift in address reloads Message-ID: <20200825101855.clw3dgzfxsgudpzn@arm.com> Content-Disposition: inline User-Agent: NeoMutt/20171215 X-ClientProxiedBy: LO3P123CA0009.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::14) To VI1PR08MB4029.eurprd08.prod.outlook.com (2603:10a6:803:ec::14) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from arm.com (217.140.106.50) by LO3P123CA0009.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.24 via Frontend Transport; Tue, 25 Aug 2020 10:18:57 +0000 X-Originating-IP: [217.140.106.50] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9e7f1200-60d6-437c-6be8-08d848e05e7d X-MS-TrafficTypeDiagnostic: VI1PR0801MB1999:|HE1PR0801MB2076: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:1107;OLM:1107; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: dUn7301HevMCDL6Qm6swu52ap2RkARjdh45FmfGTiEvY6p/qa9nSF4d0oXDZdndBVqR4ENjJWapsRj+xORjzg6dLDqWtTluhwLVVxORcsepK8dlP11eHb1zvsVtVsu23VqMw27c1NRxFnFiJ3pG4bknep8dBu0tTSfDjpL5p2HtStg9zpmEYkMVejy+UbvsZzdHgAjyR445uChim3znFODp4Mq74YWpyBImSWU6OcLQi6lfWr+5ydZrI1UJbrV/DjdZ8VZPpEjZq4HicyRnkoBL251bCTTWCeoMptvU+d6OWppluwcY60CSBgtH57Uw5I6z+fvPxa8snv5jcaF0yud4FjS3ycn2QMmcaVq88GR20XtFiagsXS/9CArqnklx6tDxDirg2KhB0NwNPlAqzjlgAzKN/JIxQ9sIYnk2lmqjPXDhELmdBuwk5T3P8FKD+FPRosigrPUAWeAybHb2lFQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB4029.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(39860400002)(396003)(376002)(346002)(366004)(66556008)(956004)(2616005)(316002)(83380400001)(44832011)(54906003)(2906002)(66476007)(8936002)(186003)(33964004)(66946007)(66616009)(4326008)(8886007)(966005)(8676002)(478600001)(36756003)(16526019)(44144004)(26005)(235185007)(1076003)(86362001)(55016002)(6916009)(21480400003)(52116002)(7696005)(5660300002)(2700100001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: s4pJ4A7LZZMYOuOm7xUU5I6caQA5QtGqYPYxjdHMNUj/JmTeP8XJ/tWRZ7qpmQGZEtI0vZD4pjmzNs173RvyKdpA6vTNT8bPzN1pLYYvC4q4H7y+Q1ANZnc0tAeMjJFX76QzQVQCnjF2yMztTqsmGjZV43xQXJBZqT2yJHFpSWz75twCwpF1Ox9LWm6VqE03/pe5KuXjxdSwwkSop1XyDDHgvf3nDzjMvV5Xk6RI116V5l6igK/JkJQHJexXeLYzg9WncOo+dZnvNyMluGhQPwsnlkfeE0AtwqZ/X63gwvCklaFVFxA7RSxWvHeAa1r0SVJtShnnhwxUaZm83s4puC8h+SPXaEnw1Xb/5IyK/jivkTbrg+m2GK1d0VYSJA7iZKIiPksO7z5JYInkR9TDDgJLTi3pqi/Q+B7mDK/xVwj4jYAHOemiHf6AY76/T3RHf6vAgCCr0dDPV46MyfD0xi+yJkR95AJrQE1Knt5prDjeqTF+rOxYX/ufymxkNKusXdrYHUIOQP/tejmp9HI7OWRYKwQkY5B6TP+olNXmOkIOGKjT3XETZv1BUKRfhPUe/geaMN4FMy/cyFD2HMvDDzEc5G2QR8+sZksPPcdsawctDz1Jgwi6Bfzzn3SjlBKCsXghLMX1DfUVGkbezdIrAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1999 Original-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-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT054.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 99f3c038-a3ff-4d3d-9899-08d848e046e8 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mKU0+LaX5wI7to/YFrWc3isGu6oBAMTW8KpzSt8DV0+dUPAfQA4MB7KONkwvJjsa8GzutbQNDmIUwVDU/BOfuQSDUk2tCL/NJawpBI5UuwQWv0cT8ERb3zAQoL/90Dim09LiFAU2i2dZYsXsALqzSKffRb00OJCiK12CloTKIf1ve1ncMzxdxK+UVxPcldCNNrkxaNRQ+X3yFVFkEEh5o/erTOz+0b0THVfqo9mrdjWMBkxMU8NrorpY74bdWQJ6ToOIoTFqL+cORr8r1Uue4A5Ds2qhHrTSdlMKmSHL/KEQP2oLSbZojPgC18dVb0eJlIboMjKWUy8ThIRHnST3jiITvc75YCY96CjMZQ4PL1/lJ1pWGJqJaA3UOFAupFJ6jYwEYfAIHhLVmmxFqsIvjhOCvdo0zPU+CKrWSBudon2R0+Wyv7O9m1oKOZVSU/xGJ0euP1dxg5ikKTt0IkF70uJch0fGYOWmFbLNotPDWxwJ7ip/5r7U+i8QUY3lj0hE 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:(4636009)(346002)(376002)(136003)(39860400002)(396003)(46966005)(81166007)(70586007)(70206006)(16526019)(186003)(336012)(2906002)(5660300002)(21480400003)(36756003)(8676002)(83380400001)(55016002)(8936002)(1076003)(4326008)(7696005)(33964004)(44144004)(44832011)(82740400003)(47076004)(82310400002)(356005)(66616009)(107886003)(8886007)(966005)(26005)(316002)(2616005)(6916009)(235185007)(86362001)(54906003)(36906005)(478600001)(956004)(2700100001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2020 10:19:36.6944 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e7f1200-60d6-437c-6be8-08d848e05e7d 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: VE1EUR03FT054.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB2076 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello, Inside a (mem) RTX, it is canonical to write multiplications by powers of two using a (mult) [0]. For example, given the following C function: long f(long *p, long x) { return p[x]; } AArch64 GCC generates the following RTL insn (in final): (set (reg/i:DI 0 x0) (mem:DI (plus:DI (mult:DI (reg:DI 1 x1 [101]) (const_int 8 [0x8])) (reg:DI 0 x0 [100])) [1 *_3+0 S8 A64])) However, outside of a (mem), the canonical way to write multiplications by powers of two is using (ashift). E.g. for the following C function: long *g(long *p, long x) { return p + x; } AArch64 GCC generates: (set (reg/i:DI 0 x0) (plus:DI (ashift:DI (reg:DI 1 x1 [100]) (const_int 3 [0x3])) (reg:DI 0 x0 [99]))) Now I observed that LRA does not quite respect this RTL canonicalization rule. When compiling gcc/testsuite/gcc.dg/torture/pr34330.c with -Os -ftree-vectorize, the RTL in the dump "281r.ira" has the insn: (set (reg:SI 111 [ MEM[base: b_25(D), index: ivtmp.9_35, step: 4, offset: 0B] ]) (mem:SI (plus:DI (mult:DI (reg:DI 101 [ ivtmp.9 ]) (const_int 4 [0x4])) (reg/v/f:DI 105 [ b ])) [2 MEM[base: b_25(D), index: ivtmp.9_35, step: 4, offset: 0B]+0 S4 A32])) but LRA then proceeds to generate a reload, and we get the following non-canonical insn in "282r.reload": (set (reg:DI 7 x7 [121]) (plus:DI (mult:DI (reg:DI 5 x5 [orig:101 ivtmp.9 ] [101]) (const_int 4 [0x4])) (reg/v/f:DI 1 x1 [orig:105 b ] [105]))) This patch fixes LRA to ensure that we generate canonical RTL in this case. After the patch, we get the following insn in "282r.reload": (set (reg:DI 7 x7 [121]) (plus:DI (ashift:DI (reg:DI 5 x5 [orig:101 ivtmp.9 ] [101]) (const_int 2 [0x2])) (reg/v/f:DI 1 x1 [orig:105 b ] [105]))) The motivation here is to be able to remove several redundant patterns in the AArch64 backend. See the previous thread [1] for context. Testing: * Bootstrapped and regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu. * New unit test which checks that we're using the shift pattern (rather than the problematic mult pattern) on AArch64. OK for master? Thanks, Alex [0] : https://gcc.gnu.org/onlinedocs/gccint/Insn-Canonicalizations.html [1] : https://gcc.gnu.org/pipermail/gcc-patches/2020-August/552066.html --- gcc/ChangeLog: * lra-constraints.c (canonicalize_reload_addr): New. (curr_insn_transform): Use canonicalize_reload_addr to ensure we generate canonical RTL for an address reload. gcc/testsuite/ChangeLog: * gcc.target/aarch64/mem-shift-canonical.c: New test. diff --git a/gcc/lra-constraints.c b/gcc/lra-constraints.c index 421c453997b..630a4f167cd 100644 --- a/gcc/lra-constraints.c +++ b/gcc/lra-constraints.c @@ -570,6 +570,34 @@ init_curr_insn_input_reloads (void) curr_insn_input_reloads_num = 0; } +/* The canonical form of an rtx inside a MEM is not necessarily the same as the + canonical form of the rtx outside the MEM. Fix this up in the case that + we're reloading an address (and therefore pulling it outside a MEM). */ +static rtx canonicalize_reload_addr (rtx addr) +{ + const enum rtx_code code = GET_CODE (addr); + + if (code == PLUS) + { + rtx inner = XEXP (addr, 0); + if (GET_CODE (inner) == MULT && CONST_INT_P (XEXP (inner, 1))) + { + const HOST_WIDE_INT ci = INTVAL (XEXP (inner, 1)); + const int pwr2 = exact_log2 (ci); + if (pwr2 > 0) + { + /* Rewrite this to use a shift instead, which is canonical + when outside of a MEM. */ + XEXP (addr, 0) = gen_rtx_ASHIFT (GET_MODE (inner), + XEXP (inner, 0), + GEN_INT (pwr2)); + } + } + } + + return addr; +} + /* Create a new pseudo using MODE, RCLASS, ORIGINAL or reuse already created input reload pseudo (only if TYPE is not OP_OUT). Don't reuse pseudo if IN_SUBREG_P is true and the reused pseudo should be @@ -4362,12 +4390,19 @@ curr_insn_transform (bool check_only_p) { rtx addr = *loc; enum rtx_code code = GET_CODE (addr); - + bool align_p = false; + if (code == AND && CONST_INT_P (XEXP (addr, 1))) - /* (and ... (const_int -X)) is used to align to X bytes. */ - addr = XEXP (*loc, 0); + { + /* (and ... (const_int -X)) is used to align to X bytes. */ + align_p = true; + addr = XEXP (*loc, 0); + } + else + addr = canonicalize_reload_addr (addr); + lra_emit_move (new_reg, addr); - if (addr != *loc) + if (align_p) emit_move_insn (new_reg, gen_rtx_AND (GET_MODE (new_reg), new_reg, XEXP (*loc, 1))); } before = get_insns (); diff --git a/gcc/testsuite/gcc.target/aarch64/mem-shift-canonical.c b/gcc/testsuite/gcc.target/aarch64/mem-shift-canonical.c new file mode 100644 index 00000000000..36beed497a0 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/mem-shift-canonical.c @@ -0,0 +1,27 @@ +/* This test is a copy of gcc.dg/torture/pr34330.c: here we are looking for + specific patterns being matched in the AArch64 backend. */ + +/* { dg-do compile } */ +/* { dg-options "-Os -ftree-vectorize -dp" } */ + + +struct T +{ + int t; + struct { short s1, s2, s3, s4; } *s; +}; + +void +foo (int *a, int *b, int *c, int *d, struct T *e) +{ + int i; + for (i = 0; i < e->t; i++) + { + e->s[i].s1 = a[i]; + e->s[i].s2 = b[i]; + e->s[i].s3 = c[i]; + e->s[i].s4 = d[i]; + } +} + +/* { dg-final { scan-assembler-times "add_lsl_di" 3 } } */