From patchwork Mon Jul 3 06:17:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 783301 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 3x1H4n12x5z9s7F for ; Mon, 3 Jul 2017 16:18:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="s56QjWa/"; 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 :content-type:mime-version; q=dns; s=default; b=WaajxkfOeiZRT/1V 710FOoPu8R6mWJptzaCIGCeJ8kARCG5rneJmCUamfzII2MX4UjOtaHWwD0A8tVFL myYG2M7O7V0GkDKFzlJcQ1f+qcJciJURtNvHwhaWJfogni7rQhpqbQitPRln5oHV yfMNSrL4Sj1uSqzLjleU6k001yU= 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:mime-version; s=default; bh=BKLomKudyXDsBJTC7ZoJs8 TWugY=; b=s56QjWa/M86yFmi8pL9ROcEnGP8MeDlXI3OcbzU38tZwkk1RdniLVe EYsJy73E/6qytUD4wiwSYF7n6xnyqzMGVgeaVtvBxn6OrLlKtxY0UmShadLhD5mT fvwZSXFxH4F6cmX8DV79eDdr72ixKsPGvPnBJzQ0syVl2HvSXmGqs= Received: (qmail 34889 invoked by alias); 3 Jul 2017 06:18:00 -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 34870 invoked by uid 89); 3 Jul 2017 06:17:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, UNSUBSCRIBE_BODY autolearn=ham version=3.3.2 spammy=earnshaw, Earnshaw, HX-MS-Has-Attach:yes, HX-MS-Exchange-CrossTenant-originalarrivaltime:Jul X-HELO: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-he1eur01on0063.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (104.47.0.63) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Jul 2017 06:17:55 +0000 Received: from VI1PR0801MB2031.eurprd08.prod.outlook.com (10.173.74.140) by AM4PR08MB2659.eurprd08.prod.outlook.com (10.171.190.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1220.11; Mon, 3 Jul 2017 06:17:52 +0000 Received: from VI1PR0801MB2031.eurprd08.prod.outlook.com ([fe80::a9ee:7f10:b6a1:339a]) by VI1PR0801MB2031.eurprd08.prod.outlook.com ([fe80::a9ee:7f10:b6a1:339a%18]) with mapi id 15.01.1220.015; Mon, 3 Jul 2017 06:17:51 +0000 From: Tamar Christina To: Richard Sandiford CC: GCC Patches , nd , James Greenhalgh , Richard Earnshaw , Marcus Shawcroft Subject: Re: [PATCH][GCC][AARCH64]Bad code-gen for structure/block/unaligned memory access Date: Mon, 3 Jul 2017 06:17:51 +0000 Message-ID: References: <87a85ic3i1.fsf@linaro.org>, In-Reply-To: authentication-results: linaro.org; dkim=none (message not signed) header.d=none; linaro.org; dmarc=none action=none header.from=arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR08MB2659; 7:qT1+tGdHFP9Qk2KnPp7x2KIvjNQdCV1/Kt+lw0cqk3b32ljOKUBEh4YvoVC4wCQXIzKgPLifeiJJeJ7HLuRjM3e/R1E28yvN5ooyGoe4JrjP7C7gu7s36B8jmn6p7kCo91BaUScVk+ZaMTLWHZIz0pMbL1NbGuV7WJ4N6FCkCN/U1JUrC9/9Sl3kj7sHKIqJOmVj+UBpK5EGvG2d20jpOwBKYH2A3FDkmCq46T/ViqOCMkU8k5W1bI4udMnF7e06Xl4iu2DUlWTzioUE5ZCvF3iGC4vknIb8jKh9AYt8FFtZF64C4nBYGg5xEkZMakaaHDqcrTDY7I/wSFhbPUiAcATT8wP+PrTkpNwejFG/TDkum6tnLq+ckvcAC6Js7hzOiVMYCA+esaWoTWkJ6fdbax3o0f1wJZM1VkdoHuUiRubKRcGs8dSHmMIuP3lWIRwMO9mdVpY9Y+XfTL/7AQeRry4qvCxMPBqv6C+iHSKnLfcjBU6Q5L0hVpTtH39SaLePufQC0X5zfbaMf9VI/SLZ9iMRot9Z34iQAc8CPw5AjF4mWUVGirUB3J0S2ux9q8ak+D2bAbDeiNUr1ld+TzTliOYlCzSefGfK90X+mB6Fk9o/0FTKT5FHU3/H9RVXH6yD6Q9Ok7xgGSMi9LEXlYvOE6RmhTULwIVpKr2UeJspyyAUfvxA77DwWCJgdRvsipaZK0NpqaslYhJVLntixMGtBEznxee/22YPw9FgMB4PhvlYzZQUIwv+RmEH15aaRJO4FfzqW7y+quRgoc0E6GZ/LkMAs935N+vkG8fnYuT2RVQ= x-ms-office365-filtering-correlation-id: 931aaeb2-a825-4ccc-a44f-08d4c1db3c4c 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)(49563074)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM4PR08MB2659; x-ms-traffictypediagnostic: AM4PR08MB2659: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(22074186197030)(236129657087228)(183786458502308)(148574349560750)(167848164394848); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(102415395)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(100000703101)(100105400095)(3002001)(93006095)(93001095)(6055026)(6041248)(20161123555025)(20161123560025)(20161123558100)(20161123564025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM4PR08MB2659; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM4PR08MB2659; x-forefront-prvs: 035748864E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(39410400002)(39840400002)(39400400002)(39850400002)(39450400003)(53754006)(377454003)(38730400002)(110136004)(74316002)(6246003)(4326008)(229853002)(86362001)(7736002)(2950100002)(5660300001)(8676002)(3660700001)(7696004)(6916009)(99936001)(54356999)(3280700002)(81166006)(50986999)(76176999)(55016002)(33656002)(99286003)(102836003)(6116002)(25786009)(3846002)(2900100001)(2906002)(189998001)(54906002)(9686003)(8936002)(6506006)(5250100002)(72206003)(66066001)(6436002)(53936002)(53546010)(14454004)(478600001)(305945005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR08MB2659; H:VI1PR0801MB2031.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: 03 Jul 2017 06:17:51.8018 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR08MB2659 X-IsSubscribed: yes Hi All, Sorry I just realized I never actually sent the updated patch... So here it is :) Regards, Tamar diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index ab1bdc0233afe7a3c41501cb724a5c4c719123b8..1cf6c4b891571745f740d7dbd03754bbba9264a6 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -13466,7 +13466,6 @@ aarch64_copy_one_block_and_progress_pointers (rtx *src, rtx *dst, /* Expand movmem, as if from a __builtin_memcpy. Return true if we succeed, otherwise return false. */ - bool aarch64_expand_movmem (rtx *operands) { @@ -13498,16 +13497,55 @@ aarch64_expand_movmem (rtx *operands) base = copy_to_mode_reg (Pmode, XEXP (src, 0)); src = adjust_automodify_address (src, VOIDmode, base, 0); + /* Optimize routines for MEM to REG copies. + This particular function only handles copying to two + destination types: 1) a regular register and 2) the stack. + When writing to a regular register we may end up writting too much in cases + where the register already contains a live value or when no data padding is + happening so we disallow it. */ + if (n < 8 && !REG_P (XEXP (operands[0], 0))) + { + machine_mode mov_mode, dest_mode + = smallest_mode_for_size (n * BITS_PER_UNIT, MODE_INT); + rtx result = gen_reg_rtx (dest_mode); + emit_insn (gen_move_insn (result, GEN_INT (0))); + + unsigned int shift_cnt = 0; + for (; n > shift_cnt; shift_cnt += GET_MODE_SIZE (mov_mode)) + { + int nearest = 0; + /* Find the mode to use. */ + for (unsigned max = 1; max <= (n - shift_cnt); max *= 2) + nearest = max; + + mov_mode = smallest_mode_for_size (nearest * BITS_PER_UNIT, MODE_INT); + rtx reg = gen_reg_rtx (mov_mode); + + src = adjust_address (src, mov_mode, 0); + emit_insn (gen_move_insn (reg, src)); + src = aarch64_progress_pointer (src); + + reg = gen_rtx_ZERO_EXTEND (dest_mode, reg); + reg = gen_rtx_ASHIFT (dest_mode, reg, + GEN_INT (shift_cnt * BITS_PER_UNIT)); + result = gen_rtx_IOR (dest_mode, reg, result); + } + + dst = adjust_address (dst, dest_mode, 0); + emit_insn (gen_move_insn (dst, result)); + return true; + } + /* Simple cases. Copy 0-3 bytes, as (if applicable) a 2-byte, then a 1-byte chunk. */ if (n < 4) { if (n >= 2) - { - aarch64_copy_one_block_and_progress_pointers (&src, &dst, HImode); - n -= 2; - } + { + aarch64_copy_one_block_and_progress_pointers (&src, &dst, HImode); + n -= 2; + } if (n == 1) aarch64_copy_one_block_and_progress_pointers (&src, &dst, QImode); diff --git a/gcc/expr.c b/gcc/expr.c index 2d8868e52cefdfdc2d81135811cbf1cb3e6ff82b..7eca579e769acb131bd0db344815e344fdc948f2 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -2743,7 +2743,9 @@ copy_blkmode_to_reg (machine_mode mode, tree src) n_regs = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; dst_words = XALLOCAVEC (rtx, n_regs); - bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD); + bitsize = BITS_PER_WORD; + if (SLOW_UNALIGNED_ACCESS (word_mode, TYPE_ALIGN (TREE_TYPE (src)))) + bitsize = MIN (TYPE_ALIGN (TREE_TYPE (src)), BITS_PER_WORD); /* Copy the structure BITSIZE bits at a time. */ for (bitpos = 0, xbitpos = padding_correction;