[Bug target/116174] New: Alignment request is added before endbr with -fcf-protection=branch

2024-08-01 Thread gcc at breakpoint dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116174

Bug ID: 116174
   Summary: Alignment request is added before endbr with
-fcf-protection=branch
   Product: gcc
   Version: 14.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gcc at breakpoint dot cc
  Target Milestone: ---

The file lib_str.c:

char *stpcpy(char *dest, const char *src)
{
while ((*dest++ = *src++) != '\0')
/* nothing */;
return --dest;
}


 gcc -nostdinc -fno-common -fno-PIE \
 -fcf-protection=branch -fno-jump-tables -m64 -falign-jumps=1
-falign-loops=1 \
 -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern \
 -mfunction-return=thunk-extern -O2 \
 -S -o lib_str.s lib_str.c
-

Output:
.text
.p2align 4
.globl  stpcpy
.type   stpcpy, @function
stpcpy: 
.p2align 5
endbr64
.L2:
movzbl  (%rsi), %eax
…
--

The problem is that this .p2align macro before endbr64 results in 16 nops (11
byte nop + 5 byte nop) before endbr on function entry.

I see this with 
- gcc version 14.1.0 (Debian 14.1.0-5) 
- gcc version 15.0.0 20240717 (experimental) [master r15-2089-gecc2c3cb723]
(Debian 20240717-1) 

I don't see this with gcc-13.

Sebastian

[Bug target/116174] [14/15 regression] Alignment request is added before endbr with -fcf-protection=branch

2024-08-02 Thread gcc at breakpoint dot cc via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116174

--- Comment #3 from Sebastian Andrzej Siewior  ---
bisect says:

commit b644126237a1aa8599f767a5e0bbada1d7286f44
Author: liuhongt 
Date:   Wed May 29 11:14:26 2024 +0800

Align tight&hot loop without considering max skipping bytes.

When hot loop is small enough to fix into one cacheline, we should align
the loop with ceil_log2 (loop_size) without considering maximum
skipp bytes. It will help code prefetch.