public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "javier.martinez.bugzilla at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/110724] Unnecessary alignment on branch to unconditional branch targets
Date: Tue, 18 Jul 2023 19:07:30 +0000	[thread overview]
Message-ID: <bug-110724-4-hwbD5dCvEU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110724-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Javier Martinez <javier.martinez.bugzilla at gmail dot com> ---
The generic tuning of 16:11:8 looks reasonable to me, I do not argue against
it.



From Anger Fog’s Optimizing subroutines in assembly language:

> Most microprocessors fetch code in aligned 16-byte or 32-byte blocks.
> If an important subroutine entry or jump label happens to be near the
> end of a 16-byte block then the microprocessor will only get a few 
> useful bytes of code when fetching that block of code. It may have
> to fetch the next 16 bytes too before it can decode the first instructions
> after the label. This can be avoided by aligning important subroutine
> entries and loop entries by 16. Aligning by 8 will assure that at least 8
> bytes of code can be loaded with the first instruction fetch, which may
> be sufficient if the instructions are small.



This looks like the reason behind the alignment. That section of the book
goes on to explain the inconvenience (execution of nops) of alignment on labels
reachable by other means than branching - which I presume lead to the :m and
:m2 tuning values, the distinction between -falign-labels and -falign-jumps,
and the reason padding is removed when my label is reachable by fall-through
with [[unlikely]].



All this is fine. 

My thesis is that this alignment strategy is always unnecessary in one specific
circumstance - when the branch target is itself an unconditional branch of size
1, as in:



.L1:

      ret 



Because the ret instruction will never cross a block boundary, and the
instructions following the ret must not execute, so there is no front-end stall
to avoid.

  parent reply	other threads:[~2023-07-18 19:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18 17:11 [Bug rtl-optimization/110724] New: " javier.martinez.bugzilla at gmail dot com
2023-07-18 17:38 ` [Bug middle-end/110724] " pinskia at gcc dot gnu.org
2023-07-18 17:48 ` pinskia at gcc dot gnu.org
2023-07-18 19:07 ` javier.martinez.bugzilla at gmail dot com [this message]
2023-07-18 20:00 ` [Bug target/110724] " pinskia at gcc dot gnu.org
2023-07-18 20:02 ` pinskia at gcc dot gnu.org
2023-07-19  6:46 ` rguenth at gcc dot gnu.org
2023-07-19  8:26 ` javier.martinez.bugzilla at gmail dot com

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-110724-4-hwbD5dCvEU@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).