From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0D4F3385773C; Tue, 18 Jul 2023 19:07:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D4F3385773C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689707251; bh=VZvs9wlOPpAYF226gs5Mv4KmlIYgJXu1Cc8ci6wN834=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qNhp1Xb/YJ1AmkLrTCnSkG71LyhryluiEu7FC5NMsC7TKc/tMd/icHvx8VJo5azJU pfUM3TeLZ0Gk8FY+pGDrb24OD+4pRSOy0jaiaP5GUk9wVzbx/UmTAIC64ZtL77IJqG cF6gvPzu/F7JTBXQUgvvfYGCIhbObt5gtWM5w7OM= From: "javier.martinez.bugzilla at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: javier.martinez.bugzilla at gmail dot com X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110724 --- Comment #3 from Javier Martinez --- The generic tuning of 16:11:8 looks reasonable to me, I do not argue against it. =E2=80=A8=E2=80=A8From Anger Fog=E2=80=99s Optimizing subroutines in assemb= ly language: =E2=80=A8> Most microprocessors fetch code in aligned 16-byte or 32-byte bl= ocks. > 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=20 > 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. =E2=80=A8=E2=80=A8This looks like the reason behind the alignment. That sec= tion of the book goes on to explain the inconvenience (execution of nops) of alignment on la= bels 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]]. =E2=80=A8=E2=80=A8All this is fine.=20 My thesis is that this alignment strategy is always unnecessary in one spec= ific circumstance - when the branch target is itself an unconditional branch of = size 1, as in: =E2=80=A8=E2=80=A8.L1:=E2=80=A8 ret=20 =E2=80=A8=E2=80=A8Because the ret instruction will never cross a block boun= dary, and the instructions following the ret must not execute, so there is no front-end s= tall to avoid.=