From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1923) id 05E3C3858000; Thu, 1 Dec 2022 13:24:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05E3C3858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669901072; bh=h2bJ2pA8YKcPxlJeJiBeg4obPAsfsMLDK5jyUEQeqEA=; h=From:To:Subject:Date:From; b=A8btVGe5GDEEnvgVe6deqvQ2PIBpTUqmfAWVOM8ntk/dJcB1sAahd1JDrcaRaPFnp aBYQXq9hGuwMKfDWfX0d8543QPNhK3Sh+zLISJz44qtKRO6BJ82zLiaOlUV5GTq2Kx pThIQfoEkOU9XQ+FPVRqJ4PmmLYNbYVDDsfg4pyI= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Philipp Tomsich To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/vrull/heads/for-upstream)] Add new flag 'falign-arrays' X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Christoph_M=C3=BCllner?= X-Git-Refname: refs/vendors/vrull/heads/for-upstream X-Git-Oldrev: 64014fe4975b7950b5d27a882bc0254838ab7266 X-Git-Newrev: 85b75e273cf56a9fcd114987eb9eff150fa3010d Message-Id: <20221201132432.05E3C3858000@sourceware.org> Date: Thu, 1 Dec 2022 13:24:32 +0000 (GMT) List-Id: https://gcc.gnu.org/g:85b75e273cf56a9fcd114987eb9eff150fa3010d commit 85b75e273cf56a9fcd114987eb9eff150fa3010d Author: Christoph Müllner Date: Fri Nov 11 17:28:42 2022 +0100 Add new flag 'falign-arrays' This patch introduces a command line flag to define a minimum alignment for arrays. This allows to enable more and/or more efficient expansions of mem*/str* functions. Signed-off-by: Christoph Müllner Diff: --- gcc/common.opt | 3 +++ gcc/doc/invoke.texi | 8 ++++++++ gcc/stor-layout.cc | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/gcc/common.opt b/gcc/common.opt index 26e9d1cc4e7..e25226e05df 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1017,6 +1017,9 @@ faggressive-loop-optimizations Common Var(flag_aggressive_loop_optimizations) Optimization Init(1) Aggressively optimize loops using language constraints. +falign-arrays +Common Var(flag_align_arrays) Optimization Init(0) + falign-functions Common Var(flag_align_functions) Optimization Align the start of functions. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a4695454158..150c1dd395f 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -525,6 +525,7 @@ Objective-C and Objective-C++ Dialects}. @item Optimization Options @xref{Optimize Options,,Options that Control Optimization}. @gccoptlist{-faggressive-loop-optimizations @gol +-falign-arrays @gol -falign-functions[=@var{n}[:@var{m}:[@var{n2}[:@var{m2}]]]] @gol -falign-jumps[=@var{n}[:@var{m}:[@var{n2}[:@var{m2}]]]] @gol -falign-labels[=@var{n}[:@var{m}:[@var{n2}[:@var{m2}]]]] @gol @@ -13386,6 +13387,13 @@ function boundary. The @option{-fipa-strict-aliasing} option is enabled by default and is effective only in combination with @option{-fstrict-aliasing}. +@item -falign-arrays +@opindex falign-arrays + +If this option is enabled, the compiler increases the minimum +alignment of arrays to @code{STACK_BOUNDARY}, meaning the minimum +alignment of the stack pointer is used. + @item -falign-functions @itemx -falign-functions=@var{n} @itemx -falign-functions=@var{n}:@var{m} diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc index 88923c4136b..c7ed706cd58 100644 --- a/gcc/stor-layout.cc +++ b/gcc/stor-layout.cc @@ -43,6 +43,7 @@ along with GCC; see the file COPYING3. If not see #include "attribs.h" #include "debug.h" #include "calls.h" +#include "flags.h" /* Data type for the expressions representing sizes of data types. It is the first integer type laid out. */ @@ -2567,6 +2568,11 @@ layout_type (tree type) using machine-dependent criteria if any. */ unsigned align = TYPE_ALIGN (element); + + /* Apply minimum alignment for arrays. */ + if (flag_align_arrays) + align = MAX (align, STACK_BOUNDARY); + if (TYPE_USER_ALIGN (type)) align = MAX (align, TYPE_ALIGN (type)); else