On Thu, Aug 8, 2024 at 6:53 PM H.J. Lu <hjl.to...@gmail.com> wrote:
>
> When we emit .p2align to align BB_HEAD, we must update BB_HEAD.  Otherwise
> ENDBR will be inserted as the wrong place.
>
> gcc/
>
>         PR target/116174
>         * config/i386/i386.cc (ix86_align_loops): Update BB_HEAD when
>         aligning BB_HEAD
>
> gcc/testsuite/
>
>         PR target/116174
>         * gcc.target/i386/pr116174.c: New test.
>
> Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
> ---
>  gcc/config/i386/i386.cc                  |  7 +++++--
>  gcc/testsuite/gcc.target/i386/pr116174.c | 12 ++++++++++++
>  2 files changed, 17 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr116174.c
>
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 77c441893b4..ec6cc5e3548 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -23528,8 +23528,11 @@ ix86_align_loops ()
>
>           if (padding_p && detect_tight_loop_p)
>             {
> -             emit_insn_before (gen_max_skip_align (GEN_INT (ceil_log2 
> (size)),
> -                                                   GEN_INT (0)), label);
> +             rtx_insn *align =
> +               emit_insn_before (gen_max_skip_align (GEN_INT (ceil_log2 
> (size)),
> +                                                     GEN_INT (0)), label);
> +             if (BB_HEAD (bb) == label)
> +               BB_HEAD (bb) = align;
>               /* End of function.  */
>               if (!tbb || tbb == EXIT_BLOCK_PTR_FOR_FN (cfun))
>                 break;
> diff --git a/gcc/testsuite/gcc.target/i386/pr116174.c 
> b/gcc/testsuite/gcc.target/i386/pr116174.c
> new file mode 100644
> index 00000000000..8877d0b51af
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr116174.c
> @@ -0,0 +1,12 @@
> +/* { dg-do compile { target *-*-linux* } } */
> +/* { dg-options "-O2 -fcf-protection=branch" } */
> +
> +char *
> +foo (char *dest, const char *src)
> +{
> +  while ((*dest++ = *src++) != '\0')
> +    /* nothing */;
> +  return --dest;
> +}
> +
> +/* { dg-final { scan-assembler "\t\.cfi_startproc\n\tendbr(32|64)\n" } } */
> --
> 2.45.2
>

PING.

-- 
H.J.

Reply via email to