From patchwork Sun Mar 10 09:42:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 1053999 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-497630-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Yb55FctK"; 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 44HGVn6LR2z9sBr for ; Sun, 10 Mar 2019 20:42:39 +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:from :to:subject:date:message-id:content-type:mime-version; q=dns; s= default; b=N11pR6IYjAS1sqwTaKZwV8Tyh2CZ/4mO8h8ZbU8whzRYUNuuU7yHN CGZlrS8blhkDe3kXnWKRZCaLXnHZFRcr/9TRpCAkC/AIepG6bqcmyPK/PVi+Q8VR 0oKn4+8T7I/5NPmNtZuvnR9wruqTikHIQg9c07bSMaQcwtwDxNZYZ0= 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:subject:date:message-id:content-type:mime-version; s= default; bh=9ibVVKRGy8CbRiPkRGooDEJSr7c=; b=Yb55FctKI+v92oQ6n5RK qJga/SmulCprLklBPbT6zkgu+S2HrTungg6Py8CjT2VZX64l/IFyfn1TxeIOQJGi IcJNmR2bSLpD5gMsjS2/vMr7dswe6VRVMcpKRIPdep+RlB9S2oLN4HsRvglaFt8I BylGLxsyXcH7+1GXsaR2sWg= Received: (qmail 34878 invoked by alias); 10 Mar 2019 09:42:32 -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 34867 invoked by uid 89); 10 Mar 2019 09:42:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=bits_per_unit, upward, BITS_PER_UNIT, sk:arm-lin X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-oln040092066066.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (40.92.66.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 10 Mar 2019 09:42:29 +0000 Received: from VE1EUR01FT038.eop-EUR01.prod.protection.outlook.com (10.152.2.53) by VE1EUR01HT124.eop-EUR01.prod.protection.outlook.com (10.152.3.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1686.19; Sun, 10 Mar 2019 09:42:27 +0000 Received: from AM6PR07MB4037.eurprd07.prod.outlook.com (10.152.2.58) by VE1EUR01FT038.mail.protection.outlook.com (10.152.3.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1686.19 via Frontend Transport; Sun, 10 Mar 2019 09:42:26 +0000 Received: from AM6PR07MB4037.eurprd07.prod.outlook.com ([fe80::2929:d3a3:182e:4219]) by AM6PR07MB4037.eurprd07.prod.outlook.com ([fe80::2929:d3a3:182e:4219%2]) with mapi id 15.20.1709.011; Sun, 10 Mar 2019 09:42:26 +0000 From: Bernd Edlinger To: "gcc-patches@gcc.gnu.org" , Richard Biener , Richard Earnshaw , "Ramana Radhakrishnan" , Kyrill Tkachov , Eric Botcazou Subject: [PATCHv2] Fix not 8-byte aligned ldrd/strd on ARMv5 (PR 89544) Date: Sun, 10 Mar 2019 09:42:26 +0000 Message-ID: x-microsoft-original-message-id: <08d3c99b-da5c-bfe5-9237-793f34054a6f@hotmail.de> MIME-Version: 1.0 Hi, This patch is an update to the previous patch, which takes into account that the middle-end is not supposed to use the unaligned DI value directly which was passed in an unaligned stack slot due to the AAPCS parameter passing rules. The patch works by changing use_register_for_decl to return false if the incoming RTL is not sufficiently aligned on a STRICT_ALIGNMENT target, as if the address of the parameter was taken (which is TREE_ADDRESSABLE). So not taking the address of the parameter is a necessary condition for the wrong-code in PR 89544. It works together with this check in assign_parm_adjust_stack_rtl: /* If we can't trust the parm stack slot to be aligned enough for its ultimate type, don't use that slot after entry. We'll make another stack slot, if we need one. */ if (stack_parm && ((STRICT_ALIGNMENT && GET_MODE_ALIGNMENT (data->nominal_mode) > MEM_ALIGN (stack_parm)) ... stack_param = NULL This makes assign_parms use assign_parm_setup_stack instead of assign_parm_setup_reg, and the latter does assign a suitably aligned stack slot, because stack_param == NULL by now, and uses emit_block_move which avoids the issue with the back-end. Additionally, to prevent unnecessary performance regressions, assign_parm_find_stack_rtl is enhanced to make use of a possible larger alignment if the parameter was passed in an aligned stack slot without the ABI requiring it. Bootstrapped and reg-tested with all languages on arm-linux-gnueabihf. Is it OK for trunk? Thanks Bernd. 2019-03-05 Bernd Edlinger PR middle-end/89544 * function.c (use_register_for_decl): Avoid using unaligned stack values on strict alignment targets. (assign_parm_find_stack_rtl): Use larger alignment when possible. testsuite: 2019-03-05 Bernd Edlinger PR middle-end/89544 * gcc.target/arm/unaligned-argument-1.c: New test. * gcc.target/arm/unaligned-argument-2.c: New test. Index: gcc/function.c =================================================================== --- gcc/function.c (revision 269264) +++ gcc/function.c (working copy) @@ -2210,6 +2210,12 @@ use_register_for_decl (const_tree decl) if (DECL_MODE (decl) == BLKmode) return false; + if (STRICT_ALIGNMENT && TREE_CODE (decl) == PARM_DECL + && DECL_INCOMING_RTL (decl) && MEM_P (DECL_INCOMING_RTL (decl)) + && GET_MODE_ALIGNMENT (DECL_MODE (decl)) + > MEM_ALIGN (DECL_INCOMING_RTL (decl))) + return false; + /* If -ffloat-store specified, don't put explicit float variables into registers. */ /* ??? This should be checked after DECL_ARTIFICIAL, but tree-ssa @@ -2698,8 +2704,20 @@ assign_parm_find_stack_rtl (tree parm, struct assi intentionally forcing upward padding. Otherwise we have to come up with a guess at the alignment based on OFFSET_RTX. */ poly_int64 offset; - if (data->locate.where_pad != PAD_DOWNWARD || data->entry_parm) + if (data->locate.where_pad == PAD_NONE || data->entry_parm) align = boundary; + else if (data->locate.where_pad == PAD_UPWARD) + { + align = boundary; + if (poly_int_rtx_p (offset_rtx, &offset) + && STACK_POINTER_OFFSET == 0) + { + unsigned int offset_align = known_alignment (offset) * BITS_PER_UNIT; + if (offset_align == 0 || offset_align > STACK_BOUNDARY) + offset_align = STACK_BOUNDARY; + align = MAX (align, offset_align); + } + } else if (poly_int_rtx_p (offset_rtx, &offset)) { align = least_bit_hwi (boundary); Index: gcc/testsuite/gcc.target/arm/unaligned-argument-1.c =================================================================== --- gcc/testsuite/gcc.target/arm/unaligned-argument-1.c (revision 0) +++ gcc/testsuite/gcc.target/arm/unaligned-argument-1.c (working copy) @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-marm -march=armv6 -mno-unaligned-access -mfloat-abi=soft -mabi=aapcs -O3" } */ + +struct s { + int a, b; +} __attribute__((aligned(8))); + +struct s f0; + +void f(int a, int b, int c, int d, struct s f) +{ + f0 = f; +} + +/* { dg-final { scan-assembler-times "stmdb" 0 } } */ +/* { dg-final { scan-assembler-times "ldrd\[^\\n\]*\\\[sp\\\]" 1 } } */ +/* { dg-final { scan-assembler-times "ldrd" 1 } } */ +/* { dg-final { scan-assembler-times "strd" 1 } } */ Index: gcc/testsuite/gcc.target/arm/unaligned-argument-2.c =================================================================== --- gcc/testsuite/gcc.target/arm/unaligned-argument-2.c (revision 0) +++ gcc/testsuite/gcc.target/arm/unaligned-argument-2.c (working copy) @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-marm -march=armv6 -mno-unaligned-access -mfloat-abi=soft -mabi=aapcs -O3" } */ + +struct s { + int a, b; +} __attribute__((aligned(8))); + +struct s f0; + +void f(int a, int b, int c, int d, int e, struct s f) +{ + f0 = f; +} + +/* { dg-final { scan-assembler-times "stmdb" 1 } } */ +/* { dg-final { scan-assembler-times "ldrd\[^\\n\]*\\\[sp\\\]" 1 } } */ +/* { dg-final { scan-assembler-times "ldrd" 1 } } */ +/* { dg-final { scan-assembler-times "strd" 1 } } */