public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/110724] New: Unnecessary alignment on branch to unconditional branch targets
@ 2023-07-18 17:11 javier.martinez.bugzilla at gmail dot com
  2023-07-18 17:38 ` [Bug middle-end/110724] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: javier.martinez.bugzilla at gmail dot com @ 2023-07-18 17:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110724
           Summary: Unnecessary alignment on branch to unconditional
                    branch targets
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: javier.martinez.bugzilla at gmail dot com
  Target Milestone: ---

https://godbolt.org/z/f7qMxxfMj

void duff(int * __restrict to, const int * __restrict from, const int count)
{
    int n = (count+7) / 8;
    switch(count%8)
    {
       case 0: do { *to++ = *from++;
       case 7:      *to++ = *from++;
       case 6:      *to++ = *from++;
       case 5:      *to++ = *from++;
       case 4:      *to++ = *from++;
       case 3:      *to++ = *from++;
       case 2:      *to++ = *from++;
       [[likely]] case 1:      *to++ = *from++;
        } while (--n>0);
    }
}

Trunk with O3:
        jle     .L1
        [...]
        lea     rax, [rax+4]
        jmp     .L5            # <-- no fall-through to ret
        .p2align 4,,7          # <-- unnecessary alignment
        .p2align 3
.L1:
        ret


I believe this 16-byte alignment is done to put the branch target at the
beginning of a front-end instruction fetch block. That however seems
unnecessary when the branch target is itself an unconditional branch, as the
instructions to follow will not retire.

In this example the degrade is code size / instruction caching only, as there
is no possible fall-through to .L1 that would cause nop's to be consumed.
Changing the C++ attribute to [[unlikely]] introduces fall-through, and GCC
seems to remove the padding, which is great.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-19  8:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-18 17:11 [Bug rtl-optimization/110724] New: Unnecessary alignment on branch to unconditional branch targets 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
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

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).