public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kito at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/88345] -Os overrides -falign-functions=N on the command line
Date: Thu, 01 Sep 2022 07:24:17 +0000	[thread overview]
Message-ID: <bug-88345-4-AhFCy4UZEQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-88345-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88345

Kito Cheng <kito at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kito at gcc dot gnu.org

--- Comment #7 from Kito Cheng <kito at gcc dot gnu.org> ---
We are hitting this issue on RISC-V, and got some complain from linux kernel
developers, but in different form as the original report, we found cold
function or any function is marked as cold by `-fguess-branch-probability` are
all not honor to the -falign-functions=N setting, that become problem on some
linux kernel feature since they want to control the minimal alignment to make
sure they can atomically update the instruction which require align to 4 byte.

However current GCC behavior can't guarantee that even -falign-functions=4 is
given, there is 3 option in my mind:

1. Fix -falign-functions=N, let it work as expect on -Os and all cold functions
2. Force align to 4 byte if -fpatchable-function-entry is given, that's should
be doable by adjust RISC-V's FUNCTION_BOUNDARY
3. Adjust RISC-V's FUNCTION_BOUNDARY to let it honor to -falign-functions=N
4. Adding a -malign-functions=N...Okay, I know that suck idea, x86 already
deprecated that.

But I think ideally this should fixed by 1 option if possible.

Testcase from RISC-V kernel guy:
```
/* { dg-do compile } */
/* { dg-options "-march=rv64gc -mabi=lp64d -O1 -falign-functions=128" } */
/* { dg-final { scan-assembler-times ".align 7" 2 } } */

// Using 128 byte align rather than 4 byte align since it easier to observe.

__attribute__((__cold__)) void a() {} // This function isn't align to 128 byte
void b() {} // This function align to 128 byte.
```

Proposed fix:
```
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 49d5cda122f..6f8ed85fea9 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -1907,8 +1907,7 @@ assemble_start_function (tree decl, const char *fnname)
      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.  */
   if (! DECL_USER_ALIGN (decl)
-      && align_functions.levels[0].log > align
-      && optimize_function_for_speed_p (cfun))
+      && align_functions.levels[0].log > align)
     {
 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
       int align_log = align_functions.levels[0].log;

```

  parent reply	other threads:[~2022-09-01  7:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-88345-4@http.gcc.gnu.org/bugzilla/>
2020-09-11 10:52 ` koen.zandberg at inria dot fr
2022-09-01  7:24 ` kito at gcc dot gnu.org [this message]
2023-01-12 11:34 ` mark at kernel dot org
2023-01-12 16:11 ` egallager at gcc dot gnu.org
2023-01-13 12:56 ` mark at kernel dot org
2023-01-17 16:26 ` ktkachov at gcc dot gnu.org
2023-01-17 16:37 ` kito at gcc dot gnu.org
2023-01-23 14:15 ` mark at kernel dot org
2023-09-12 11:47 ` rguenth at gcc dot gnu.org
2023-09-12 12:35 ` matz at gcc dot gnu.org
2023-11-22 13:20 ` hubicka at gcc dot gnu.org
2023-12-06  9:38 ` hubicka at gcc dot gnu.org
2023-12-06 13:38 ` matz at gcc dot gnu.org
2023-12-06 17:20 ` hubicka at ucw dot cz
2023-12-06 18:02 ` matz at gcc dot gnu.org
2023-12-07 10:49 ` jamborm at gcc dot gnu.org
2024-01-01 20:22 ` hubicka at gcc dot gnu.org
2024-01-24 17:13 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-88345-4-AhFCy4UZEQ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).