From patchwork Tue Nov 14 16:02:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tamar Christina X-Patchwork-Id: 837912 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-466747-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="sw8APRHL"; 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 3ybsj23DMVz9sDB for ; Wed, 15 Nov 2017 03:02:29 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=tsgSJKs8R3FUKyAHFaN+0eecdgNcZI/nLrufr8zpgfue/n65P/ 5+iBeZtO8XRGP4gCZMdKDHXQ6duJGIU8ilqjByz62PM4MYlx06ISc/ZmThl7DPYt OMbvZaCR6fv3aeJKYVRhmkETf/6uSS0a7aPsFBbzuLfspAUBT9VP9DKjw= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=TBTtph88ktmHfeEaJxx9yS/pIvc=; b=sw8APRHLEAaFEQRu6wKC wzYiqDMGZCSwv2uVvO5IKPJpnzcrokL5Q5ByDxEpW8Yi9mE7vjrzDa6wbIMhm87C cNpwygXpkpdfXQBlm6m12WCp34yeltbtilkVo38El1EIUAdDrmgrOKJOMnAFMTaH nYWx7aFTjB3r+LjVejP33+o= Received: (qmail 5780 invoked by alias); 14 Nov 2017 16:02:21 -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 5771 invoked by uid 89); 14 Nov 2017 16:02:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, KAM_SHORT, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=U*bug-gdb, strh X-HELO: EUR01-DB5-obe.outbound.protection.outlook.com Received: from mail-db5eur01on0085.outbound.protection.outlook.com (HELO EUR01-DB5-obe.outbound.protection.outlook.com) (104.47.2.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Nov 2017 16:02:13 +0000 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Tamar.Christina@arm.com; Received: from arm.com (217.140.96.140) by AM2PR08MB0498.eurprd08.prod.outlook.com (2a01:111:e400:844f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Tue, 14 Nov 2017 16:02:08 +0000 Date: Tue, 14 Nov 2017 16:02:41 +0000 From: Tamar Christina To: gcc-patches@gcc.gnu.org Cc: nd@arm.com, law@redhat.com, rguenther@suse.de, ian@airs.com Subject: [PATCH][GCC][mid-end] Allow larger copies when target supports unaligned access [Patch (1/2)] Message-ID: <20171114160235.GA30036@arm.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-ClientProxiedBy: LNXP265CA0011.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::23) To AM2PR08MB0498.eurprd08.prod.outlook.com (2a01:111:e400:844f::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 181f7499-f712-4248-cef2-08d52b790f56 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(2017052603199)(49563074); SRVR:AM2PR08MB0498; X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0498; 3:PrPfR+qxiz3alcwfLQIWjT3erslUndtWZ6UbdwYw54ti6cARlaHuPHKck6PsQWEE9OH7ron0tKifqSN1iPJ9wkpd2qKEhfGTfGG6p00faLxFCMGoAKi8SgjNUxCYv6parKHhkSaXCPePPAZ+y5I7iESioqvTmIpXTLY5Esre5UqDMrRDS4rwwZ+Vndr+vNfrQ91GM/RiRNRRLEDrB3IrZ3SQbl0X0Ryo7px8gc/Hd4OdBhqRlFxSI2pRfGN6GIeG; 25:eX2a7J1aFiSgklhv4cuWrOV4iBZ9u9wdWGOGHGCvgFXr9LeRNud/E+B83I0bQECpIdrKQzbLhHXhIzwmK7psuRYZhQ1eAZLRLu7oQRwPJ7bfJHE1/Oc9BYOeCB56qEoADQZkIFroQ2MZTlxm+I22aYMF3bD+QN6i2Ywd8CdKjhvodsbGsfmryx7nSmkGVWMQJYb6deKBWGwBGijz7Ac88kOqHPbFY5VgN2nFqjc/P6QufRaebUmNl6t61iVCqBQq2f5G0ZQZBPyVUQISRAvautTEjzjoq7hP21VAbhFeOzygPbK2kY9CyCS0UF8mb5X2zsSxmxMEeJ//SmMxISBnui2MQarJa+bhjLNP22ptpEc=; 31:c+tJr8gKOBwhHWjRC8FqJ3pmqOdY2/hrNSFkFgjMFiLQItrwFFo+VCiqnX0ndJNM5YZf9Z5zIy1KSjanl5+QCuarGn8/PLyfaaVbl1USHPxCPIvFV1NxCU7OvuojPo+09EG+H8zrvfeC41CWpNGkZWQYfgeNoLB1mot47QLoVUDM5Fx/PbaLPzQIuFbE8CPOoDhHF00cN+yIbc0owuaJehm1nXUIsPY1sXfWn/n6R0k= X-MS-TrafficTypeDiagnostic: AM2PR08MB0498: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0498; 20:7G5uk1ZZItVd635eZp51w09KAs4AaiJfaRVwFnlyBU+gM5CMC6uLXX5QpMxFSus9cFuBeSRtYOi4QbN8dUN+7H6fqCbxYSgIj5vV4doueuG9RENQgk+yO2W/0KCqOLIeOjsnMN6o3VTUuUX1wn56AcoR1/dt2vrHzMDv07cAAaM=; 4:wtYLiRorn0gXXt6RW0N3pRQv2R/c0KglF+71zapTrtpncZvTDz128o1jo7m4goD7J4O19vH2bmcmUOnvoNbaYFrpiojUMQR9O3CFpoRVEsFAKj/EMtqkyHRUUhqgkHak/n9cqSvX5opg8OxMFMLnS9A2F0tbevuzB04BvJBDky/IYO2j9Mc1Y3sduJOCw80EkyKBMnFHC6fAfxny+Wb8GECM3o0C0ngNdycSVjH/5B8vlTbYW04/i+jZoqE/EUY3wltkSjqROGDWnekS58H7wFNyK4cKUfNadiF9im3Ud/myMf8YTTJlmGj2VBWwNILImeluD33/pDHgQYJE3aBNfIcUvzFulYMKbTC7WihbDJR05w/mwHnESuJI8PrKyZkx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(22074186197030)(183786458502308); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(102415395)(6040450)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231022)(100000703101)(100105400095)(6055026)(6041248)(20161123564025)(20161123562025)(20161123560025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM2PR08MB0498; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM2PR08MB0498; X-Forefront-PRVS: 04916EA04C X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(39860400002)(376002)(346002)(53754006)(377424004)(189002)(199003)(478600001)(6306002)(50986999)(36756003)(189998001)(58126008)(4326008)(1076002)(66066001)(25786009)(6116002)(33656002)(55016002)(97736004)(81166006)(6666003)(54356999)(3846002)(84326002)(4001150100001)(53936002)(5660300001)(6916009)(568964002)(2361001)(72206003)(7736002)(305945005)(86362001)(2906002)(101416001)(2476003)(16526018)(68736007)(966005)(4610100001)(21086003)(5890100001)(316002)(81156014)(16586007)(106356001)(83506002)(2351001)(8936002)(8676002)(105586002)(18370500001)(2700100001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR08MB0498; H:arm.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) X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0498; 23:FRYXIe+Sg5CLadQ7uaPTD9jH/pQA1mR7p5kJ0gGnPudBwv1Au8ffUDyQAn6aQbpBDJj6ys94U4KfxlqIi19QSM73Gd07zTeAol2kB4E3DfY62LWRbIrY0w9g9zZS5LXzWiYd8nl/+3aU9D8TS8FYl1TZiikKMFzwg2pHR3qPlOQPjGOLIqs6orVDp5Z0HqJRsCCvFtZMPARWI6fWuWFaLI5ycIxAy7TDpVZ1xeDW+g/qZSO2XcOrvHyYZL8mZy8WqmIPq65aw7NMnxn0lyeDviMx1E0+lPypgzoLbm4Eozz5B1m6CoS7F5NLo1pTAcPSvvVELsFPu/DUMOSjiHMwvE/gK5Op2Hvohs4aGLhiWJ2tSebcq6AdvzKphx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LE8f/chNppnTKAK/bHlSkw0RUGd/ZGXNjmuVwTjKYNQRXZ0vkKJIcy30u5raq0tVxCpNo5JfuZHwJW80v+5rGlLjDgkmuXbcZ5OHp/XVkBVgVRdi5QGjjZ9BwEbqYJ9Ol4P2ur9YHe09oyHuXXPv+A5hrZhyZmvGUBw2QEmzF3gYUmeMYkLyw7X7oE5RVZEaBfxNI3Sb6JVA4cBfTPprr22EnWHdUmSSxlOw+FZELfRJjFyfPcImi8jJBLGefNZzMmCPZPpuh+k/rtUKYzFtdd8yzhsfxcqOsMRI=; 5:VNWLQQu6SAkR1bOu3NJuJno6HHOPDRMZeCTGn/U/3Dv886v/wYS5umd/slLTJ942wn1f7YACFeOqhxwwB8t23+mx+96Kpyu1Iw4z3LyjO775LE2Ag4QD7/Nz8AYBS5cWYK7U+RYpxn58+FlPwj3VVoAtN5OEAUMteWKZ/TfndNM=; 24:rDW6LynTY3ST7qYi9m+sZPUtxHuEGADCHlEWVsWOtX5OjobIIULyiXtaxicm/7teccn6DhmneQ5m32lRFOUI/EfaRli0tvxwpUosE399NJw=; 7:FS2mZCjbTR2vsWodagzil3CuFVQZWYvY8+YR4jR4sHlGdaAISk4GRTThbkzUOlquOr9x0ZTRKhNc2aA6uCO/AxqM/P8B0CDhmh2MnqY8Dn/qMAeDRUS8v1xTflkdBMugX1qODFt0P0FEm09M+W5aBXmrb7pCf+HRh+DBkj8kHZiygeQFYVsxVBgVpt8CUHJmgPqTTewqji6M/JQEQqiKDkAKs1Zz3O7b6aOhs5/GrasPWrqVTzkpQvoQiL0TSxlS SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2017 16:02:08.8833 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 181f7499-f712-4248-cef2-08d52b790f56 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR08MB0498 X-IsSubscribed: yes Hi All, This patch allows larger bitsizes to be used as copy size when the target does not have SLOW_UNALIGNED_ACCESS. fun3: adrp x2, .LANCHOR0 add x2, x2, :lo12:.LANCHOR0 mov x0, 0 sub sp, sp, #16 ldrh w1, [x2, 16] ldrb w2, [x2, 18] add sp, sp, 16 bfi x0, x1, 0, 8 ubfx x1, x1, 8, 8 bfi x0, x1, 8, 8 bfi x0, x2, 16, 8 ret is turned into fun3: adrp x0, .LANCHOR0 add x0, x0, :lo12:.LANCHOR0 sub sp, sp, #16 ldrh w1, [x0, 16] ldrb w0, [x0, 18] strh w1, [sp, 8] strb w0, [sp, 10] ldr w0, [sp, 8] add sp, sp, 16 ret which avoids the bfi's for a simple 3 byte struct copy. Regression tested on aarch64-none-linux-gnu and x86_64-pc-linux-gnu and no regressions. This patch is just splitting off from the previous combined patch with AArch64 and adding a testcase. I assume Jeff's ACK from https://gcc.gnu.org/ml/gcc-patches/2017-08/msg01523.html is still valid as the code did not change. Thanks, Tamar gcc/ 2017-11-14 Tamar Christina * expr.c (copy_blkmode_to_reg): Fix bitsize for targets with fast unaligned access. * doc/sourcebuild.texi (no_slow_unalign): New. gcc/testsuite/ 2017-11-14 Tamar Christina * gcc.dg/struct-simple.c: New. * lib/target-supports.exp (check_effective_target_no_slow_unalign): New. diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi index 1646d0a99911aa7b2e66762e5907fbb0454ed00d..1df7a82fbd516b9bf07908bb800e441110b28ca4 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -2178,8 +2178,12 @@ Target supports @code{wchar_t} that is compatible with @code{char32_t}. @item comdat_group Target uses comdat groups. + +@item no_slow_unalign +Target does not have slow unaligned access. @end table + @subsubsection Local to tests in @code{gcc.target/i386} @table @code diff --git a/gcc/expr.c b/gcc/expr.c index 2f8432d92ccac17c0a548faf4a16eff0656cef1b..afcea8fef58155d0a899991c10cd485ba8af888d 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -2769,7 +2769,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 (targetm.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; diff --git a/gcc/testsuite/gcc.dg/struct-simple.c b/gcc/testsuite/gcc.dg/struct-simple.c new file mode 100644 index 0000000000000000000000000000000000000000..9f218851d897421b217b0926d29845b6192982fb --- /dev/null +++ b/gcc/testsuite/gcc.dg/struct-simple.c @@ -0,0 +1,52 @@ +/* { dg-do-run } */ +/* { dg-require-effective-target no_slow_unalign } */ +/* { dg-additional-options "-fdump-rtl-final" } */ + +/* Copyright 1996, 1999, 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . + + Please email any bugs, comments, and/or additions to this file to: + bug-gdb@prep.ai.mit.edu */ + +#include + +struct struct3 { char a, b, c; }; +struct struct3 foo3 = { 'A', 'B', 'C'}, L3; + +struct struct3 fun3() +{ + return foo3; +} + +#ifdef PROTOTYPES +void Fun3(struct struct3 foo3) +#else +void Fun3(foo3) + struct struct3 foo3; +#endif +{ + L3 = foo3; +} + +int main() +{ + struct struct3 x = fun3(); + + printf("a:%c, b:%c, c:%c\n", x.a, x.b, x.c); +} + +/* { dg-final { scan-rtl-dump-not {zero_extract:.+\[\s*foo3\s*\]} "final" } } */ + diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index b6f9e51c4817cf8235c8e33b14e2763308eb482a..690d8960002a3c38462bbe5524b419c205ba4da9 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -6037,6 +6037,30 @@ proc check_effective_target_unaligned_stack { } { return $et_unaligned_stack_saved } +# Return 1 if the target plus current options does not have +# slow unaligned access. +# +# This won't change for different subtargets so cache the result. + +proc check_effective_target_no_slow_unalign { } { + global et_no_slow_unalign_saved + global et_index + + if [info exists et_no_slow_unalign_saved($et_index)] { + verbose "check_effective_target_no_slow_unalign: using cached result" 2 + } else { + set et_no_slow_unalign_saved($et_index) 0 + if { [istarget x86_64-*-*] + || [istarget aarch64*-*-*] + } { + set et_no_slow_unalign_saved($et_index) 1 + } + } + verbose "check_effective_target_no_slow_unalign:\ + returning $et_no_slow_unalign_saved($et_index)" 2 + return $et_no_slow_unalign_saved($et_index) +} + # Return 1 if the target plus current options does not support a vector # alignment mechanism, 0 otherwise. #