From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id D62F83858C27 for ; Tue, 31 Aug 2021 23:33:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D62F83858C27 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 17VNUWP3027586 for ; Tue, 31 Aug 2021 16:33:31 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3asf15m0ga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 31 Aug 2021 16:33:31 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 31 Aug 2021 16:33:29 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Tue, 31 Aug 2021 16:33:29 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id DF6203F703F; Tue, 31 Aug 2021 16:33:28 -0700 (PDT) From: To: CC: Andrew Pinski Subject: [PATCH] Fix target/101934: aarch64 memset code creates unaligned stores for -mstrict-align Date: Tue, 31 Aug 2021 16:33:24 -0700 Message-ID: <1630452804-3339-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: 3caOao62mbuwWfeHRNpOx5whvJnWljJW X-Proofpoint-GUID: 3caOao62mbuwWfeHRNpOx5whvJnWljJW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-08-31_09,2021-08-31_01,2020-04-07_01 X-Spam-Status: No, score=-14.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Tue, 31 Aug 2021 23:33:43 -0000 From: Andrew Pinski The problem here is the aarch64_expand_setmem code did not check STRICT_ALIGNMENT if it is creating an overlapping store. This patch adds that check and the testcase works. gcc/ChangeLog: PR target/101934 * config/aarch64/aarch64.c (aarch64_expand_setmem): Check STRICT_ALIGNMENT before creating an overlapping store. gcc/testsuite/ChangeLog: PR target/101934 * gcc.target/aarch64/memset-strict-align-1.c: New test. --- gcc/config/aarch64/aarch64.c | 4 +-- .../aarch64/memset-strict-align-1.c | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/memset-strict-align-1.c diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 3213585a588..26d59ba1e13 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -23566,8 +23566,8 @@ aarch64_expand_setmem (rtx *operands) /* Do certain trailing copies as overlapping if it's going to be cheaper. i.e. less instructions to do so. For instance doing a 15 byte copy it's more efficient to do two overlapping 8 byte copies than - 8 + 4 + 2 + 1. */ - if (n > 0 && n < copy_limit / 2) + 8 + 4 + 2 + 1. Only do this when -mstrict-align is not supplied. */ + if (n > 0 && n < copy_limit / 2 && !STRICT_ALIGNMENT) { next_mode = smallest_mode_for_size (n, MODE_INT); int n_bits = GET_MODE_BITSIZE (next_mode).to_constant (); diff --git a/gcc/testsuite/gcc.target/aarch64/memset-strict-align-1.c b/gcc/testsuite/gcc.target/aarch64/memset-strict-align-1.c new file mode 100644 index 00000000000..5cdc8a44968 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/memset-strict-align-1.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-Os -mstrict-align" } */ + +struct s { char x[95]; }; +void foo (struct s *); +void bar (void) { struct s s1 = {}; foo (&s1); } + +/* memset (s1 = {}, sizeof = 95) should be expanded out + such that there are no overlap stores when -mstrict-align + is in use. + so 2 pair 16 bytes stores (64 bytes). + 1 16 byte stores + 1 8 byte store + 1 4 byte store + 1 2 byte store + 1 1 byte store + */ + +/* { dg-final { scan-assembler-times "stp\tq" 2 } } */ +/* { dg-final { scan-assembler-times "str\tq" 1 } } */ +/* { dg-final { scan-assembler-times "str\txzr" 1 } } */ +/* { dg-final { scan-assembler-times "str\twzr" 1 } } */ +/* { dg-final { scan-assembler-times "strh\twzr" 1 } } */ +/* { dg-final { scan-assembler-times "strb\twzr" 1 } } */ + +/* Also one store pair for the frame-pointer and the LR. */ +/* { dg-final { scan-assembler-times "stp\tx" 1 } } */ + -- 2.17.1