From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 49CC6385828F for ; Wed, 17 Jan 2024 15:53:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49CC6385828F Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 49CC6385828F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.113.20.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705506787; cv=none; b=uIt7/L+WabDUfD+sMeQIEuxDM6KuRWfj0rNgqXJpJBfl2XsgL3FN6pmdXAUkxmsFps16SLmINjk4+A+ZIVd5vUnyt4/pX9PLQdpgUAbgW+KPDuqiGIX7bsRUu6jixj1mZHzpY7pdVjqEjnGpsN5PEY4+IvbJbRq5VOA9qA9arCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705506787; c=relaxed/simple; bh=8lTqw7yv2o2x6uonZWsE+DzNE8fk6DenGHqbrAmLj60=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=DC3hO9uzPjKz9o8MTvngdomRmfZaOidpdaIN4oG8PqVAYRPJGh4CGUTUhiHnwHWuJwetWnB+qQi7LTJYp0pWvG7/mP5fl7xL3oIA8wNIGjh1+c+WC67e6A8cKR6uqhzvrXyr9Ky0fFrjb+7ZAxspytliZTtQeD1EmXWxuHyLnBM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id EB8B0283B5E; Wed, 17 Jan 2024 16:53:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1705506781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n3U+jU/M9QoL+Udt0gg/VZZH/O4XNaqwRIpa3V0irhs=; b=bfx7nAhXBT1bjGCs/6oYCzhLj58SUt370xQOfy3/Yb5sXiNu58EJQs0hYWODu8V9Iqf6To 1jigvVY1r+oKXd/I5FeeteAxme+SxWmHScbc/zX+RhJlcQ4fsJ3HXbU9J4+lqbxtPvmtvU tXR+2Y/LtWaXtKlgp8cO12f9+3oMhFs= Date: Wed, 17 Jan 2024 16:53:01 +0100 From: Jan Hubicka To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: Add -falign-all-functions Message-ID: References: <93nnq110-3974-p060-sp9p-q2pn0641687p@fhfr.qr> <72ssp99q-2447-6685-8307-n06499051o12@fhfr.qr> <78r5nsrq-opq6-0spr-5043-n1n092q52995@fhfr.qr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <78r5nsrq-opq6-0spr-5043-n1n092q52995@fhfr.qr> X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,JMQ_SPF_NEUTRAL,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > On Wed, 17 Jan 2024, Jan Hubicka wrote: > > > > > > > I meant the new option might be named -fmin-function-alignment= > > > rather than -falign-all-functions because of how it should > > > override all other options. > > > > I was also pondering about both names. -falign-all-functions has the > > advantage that it is similar to all the other alignment flags that are > > all called -falign-XXX > > > > but both options are finte for me. > > > > > > Otherwise is there an updated patch to look at? > > > > I will prepare one. So shall I drop the max-skip support for alignment > > and rename the flag? > > Yes. OK, here is updated version. Bootstrapped/regtested on x86_64-linux, OK? gcc/ChangeLog: * common.opt (flimit-function-alignment): Reorder so file is alphabetically ordered. (flimit-function-alignment): New flag. * doc/invoke.texi (-fmin-function-alignment): Document (-falign-jumps,-falign-labels): Document that this is an optimization bypassed in cold code. * varasm.cc (assemble_start_function): Honor -fmin-function-alignment. diff --git a/gcc/common.opt b/gcc/common.opt index 5f0a101bccb..6e85853f086 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 43fd3c3a3cd..456374d9446 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -546,6 +546,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 @@ -14177,6 +14178,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}. @@ -14240,6 +14244,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. @@ -14262,6 +14268,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. @@ -14275,6 +14283,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. @@ -14371,7 +14387,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..ccf97a5a496 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -1939,11 +1939,16 @@ 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 < flag_min_function_alignment) + align = flag_min_function_alignment; + if (align > 0) { ASM_OUTPUT_ALIGN (asm_out_file, align); } /* Handle a user-specified function alignment. Note that we still need to align to DECL_ALIGN, as above, because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */