From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1075) id 31865385841A; Wed, 24 Jan 2024 17:13:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31865385841A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706116423; bh=UsniTETPkgOoS1VwXDaXEjF6BzgkOAO0jr8d6Oxh+w8=; h=From:To:Subject:Date:From; b=j/Ch9nBY2OjkqZbUFB+85VsgrxOdJd68xveFamlnIk+oGMRi8GAXhMFIWhOV/MkI0 Il+ARvaSUH/1ruSDiaiCmIPyW8zCrbFk9tvxQiAUSU+1TAxWDXl8LLAkbwIbrZlA9K IbjO9i/yE2h40J75ALtBLfY85WLfjUTZfEev8/Jg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jan Hubicka To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8395] Add -fmin-function-alignmnet X-Act-Checkin: gcc X-Git-Author: Jan Hubicka X-Git-Refname: refs/heads/master X-Git-Oldrev: dfa17fd3b1a50cab51803e8a63c5c7b7db173523 X-Git-Newrev: 0f5a9a00e3ab1fe96142f304cfbcf3f63b15f326 Message-Id: <20240124171343.31865385841A@sourceware.org> Date: Wed, 24 Jan 2024 17:13:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0f5a9a00e3ab1fe96142f304cfbcf3f63b15f326 commit r14-8395-g0f5a9a00e3ab1fe96142f304cfbcf3f63b15f326 Author: Jan Hubicka Date: Wed Jan 24 18:13:17 2024 +0100 Add -fmin-function-alignmnet -falign-functions is ignored in cold code, since it is an optimization intended to improve instruction prefetch. In some case it is necessary to force alignment for all functions, so this patch adds -fmin-function-alignment for this purpose. gcc/ChangeLog: PR middle-end/88345 * common.opt: (flimit-function-alignment): Reorder alphabeticaly (fmin-function-alignment): New parameter. * doc/invoke.texi: (-fmin-function-alignment): Document. (-falign-functions,-falign-loops,-falign-labels): Mention that aglinments are ignored in cold code. * varasm.cc (assemble_start_function): Handle min-function-alignment. Diff: --- gcc/common.opt | 10 +++++++--- gcc/doc/invoke.texi | 18 +++++++++++++++++- gcc/varasm.cc | 5 +++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/gcc/common.opt b/gcc/common.opt index 7dc380cc153..51c4a17da83 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1040,9 +1040,6 @@ Align the start of functions. falign-functions= Common RejectNegative Joined Var(str_align_functions) Optimization -flimit-function-alignment -Common Var(flag_limit_function_alignment) Optimization Init(0) - falign-jumps Common Var(flag_align_jumps) Optimization Align labels which are only reached by jumping. @@ -2277,6 +2274,10 @@ fmessage-length= Common RejectNegative Joined UInteger -fmessage-length= Limit diagnostics to characters per line. 0 suppresses line-wrapping. +fmin-function-alignment= +Common Joined RejectNegative UInteger Var(flag_min_function_alignment) Optimization +Align the start of every function. + fmodulo-sched Common Var(flag_modulo_sched) Optimization Perform SMS based modulo scheduling before the first scheduling pass. @@ -2601,6 +2602,9 @@ starts and when the destructor finishes. flifetime-dse= Common Joined RejectNegative UInteger Var(flag_lifetime_dse) Optimization IntegerRange(0, 2) +flimit-function-alignment +Common Var(flag_limit_function_alignment) Optimization Init(0) + flive-patching Common RejectNegative Alias(flive-patching=,inline-clone) Optimization diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5f904cf1ef2..6ec56493e59 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -547,6 +547,7 @@ Objective-C and Objective-C++ Dialects}. -falign-jumps[=@var{n}[:@var{m}:[@var{n2}[:@var{m2}]]]] -falign-labels[=@var{n}[:@var{m}:[@var{n2}[:@var{m2}]]]] -falign-loops[=@var{n}[:@var{m}:[@var{n2}[:@var{m2}]]]] +-fmin-function-alignment=[@var{n}] -fno-allocation-dce -fallow-store-data-races -fassociative-math -fauto-profile -fauto-profile[=@var{path}] -fauto-inc-dec -fbranch-probabilities @@ -14234,6 +14235,9 @@ Align the start of functions to the next power-of-two greater than or equal to @var{n}, skipping up to @var{m}-1 bytes. This ensures that at least the first @var{m} bytes of the function can be fetched by the CPU without crossing an @var{n}-byte alignment boundary. +This is an optimization of code performance and alignment is ignored for +functions considered cold. If alignment is required for all functions, +use @option{-fmin-function-alignment}. If @var{m} is not specified, it defaults to @var{n}. @@ -14297,6 +14301,8 @@ Enabled at levels @option{-O2}, @option{-O3}. Align loops to a power-of-two boundary. If the loops are executed many times, this makes up for any execution of the dummy padding instructions. +This is an optimization of code performance and alignment is ignored for +loops considered cold. If @option{-falign-labels} is greater than this value, then its value is used instead. @@ -14319,6 +14325,8 @@ Enabled at levels @option{-O2}, @option{-O3}. Align branch targets to a power-of-two boundary, for branch targets where the targets can only be reached by jumping. In this case, no dummy operations need be executed. +This is an optimization of code performance and alignment is ignored for +jumps considered cold. If @option{-falign-labels} is greater than this value, then its value is used instead. @@ -14332,6 +14340,14 @@ The maximum allowed @var{n} option value is 65536. Enabled at levels @option{-O2}, @option{-O3}. +@opindex fmin-function-alignment=@var{n} +@item -fmin-function-alignment +Specify minimal alignment of functions to the next power-of-two greater than or +equal to @var{n}. Unlike @option{-falign-functions} this alignment is applied +also to all functions (even those considered cold). The alignment is also not +affected by @option{-flimit-function-alignment} + + @opindex fno-allocation-dce @item -fno-allocation-dce Do not remove unused C++ allocations in dead code elimination. @@ -14428,7 +14444,7 @@ To use the link-time optimizer, @option{-flto} and optimization options should be specified at compile time and during the final link. It is recommended that you compile all the files participating in the same link with the same options and also specify those options at -link time. +link time. For example: @smallexample diff --git a/gcc/varasm.cc b/gcc/varasm.cc index d2c879b7da4..fa17eff551e 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -1939,6 +1939,11 @@ assemble_start_function (tree decl, const char *fnname) /* Tell assembler to move to target machine's alignment for functions. */ align = floor_log2 (align / BITS_PER_UNIT); + /* Handle forced alignment. This really ought to apply to all functions, + since it is used by patchable entries. */ + if (flag_min_function_alignment) + align = MAX (align, floor_log2 (flag_min_function_alignment)); + if (align > 0) { ASM_OUTPUT_ALIGN (asm_out_file, align);