From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 9B621385781A; Thu, 16 Sep 2021 07:29:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B621385781A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9001] Fix target/101934: aarch64 memset code creates unaligned stores for -mstrict-align X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 0287b697b018125e97c2121796bd71cd7fab5f29 X-Git-Newrev: f00530266f89b28e8286cdd2f587e046a27d2193 Message-Id: <20210916072928.9B621385781A@sourceware.org> Date: Thu, 16 Sep 2021 07:29:28 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Sep 2021 07:29:28 -0000 https://gcc.gnu.org/g:f00530266f89b28e8286cdd2f587e046a27d2193 commit r11-9001-gf00530266f89b28e8286cdd2f587e046a27d2193 Author: Andrew Pinski Date: Tue Aug 31 04:41:14 2021 +0000 Fix target/101934: aarch64 memset code creates unaligned stores for -mstrict-align 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. (cherry picked from commit a45786e9a31f995087d8cb42bc3a4fe06911e588) Diff: --- gcc/config/aarch64/aarch64.c | 4 ++-- .../gcc.target/aarch64/memset-strict-align-1.c | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index ae769fd79cf..66c7802a579 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -23598,8 +23598,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 } } */ +