On Thu, Aug 08, 2024 at 06:53:10PM -0700, H.J. Lu 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 <[email protected]>
> ---
> 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 =
= can't go at the end of line.
> + 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;
This is wrong. As documented, BB_HEAD needs to be either a CODE_LABEL, or
NOTE_INSN_BASIC_BLOCK.
E.g. emit-rtl.cc says
/* Should not happen as first in the BB is always either NOTE or
LABEL. */
Jakub