On Wed, Aug 27, 2025 at 6:30 AM H.J. Lu <hjl.to...@gmail.com> wrote: > > For a basic block with only a debug marker: > > (note 3 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK) > (note 2 3 5 2 NOTE_INSN_FUNCTION_BEG) > (debug_insn 5 2 16 2 (debug_marker) "x.c":6:3 -1 (nil)) > > emit the TLS call after debug marker. > > gcc/ > > PR target/121668 > * config/i386/i386-features.cc (ix86_emit_tls_call): Emit the > TLS call after debug marker. > > gcc/testsuite/ > > PR target/121668 > * gcc.target/i386/pr121668-1a.c: New test. > > Signed-off-by: H.J. Lu <hjl.to...@gmail.com> > --- > gcc/config/i386/i386-features.cc | 26 +++++++++++++++++---- > gcc/testsuite/gcc.target/i386/pr121668-1a.c | 13 +++++++++++ > 2 files changed, 34 insertions(+), 5 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/i386/pr121668-1a.c > > diff --git a/gcc/config/i386/i386-features.cc > b/gcc/config/i386/i386-features.cc > index cdb2a0b34b2..93e20947edf 100644 > --- a/gcc/config/i386/i386-features.cc > +++ b/gcc/config/i386/i386-features.cc > @@ -3806,10 +3806,19 @@ ix86_emit_tls_call (rtx tls_set, x86_cse_kind kind, > basic_block bb, > (code_label 78 11 77 3 14 (nil) [1 uses]) > (note 77 78 54 3 [bb 3] NOTE_INSN_BASIC_BLOCK) > > + or a basic block with only a debug marker: > + > + (note 3 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK) > + (note 2 3 5 2 NOTE_INSN_FUNCTION_BEG) > + (debug_insn 5 2 16 2 (debug_marker) "x.c":6:3 -1 (nil)) > + > */ > - gcc_assert (NOTE_P (insn) > - && (NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG > - || NOTE_KIND (insn) == NOTE_INSN_BASIC_BLOCK)); > + gcc_assert (DEBUG_INSN_P (insn) > + || (NOTE_P (insn) > + && ((NOTE_KIND (insn) > + == NOTE_INSN_FUNCTION_BEG) > + || (NOTE_KIND (insn) > + == NOTE_INSN_BASIC_BLOCK))));
Maybe we should just gcc_assert (!NONDEBUG_INSN_P (insn))? > insn = NULL; > break; > } > @@ -3854,12 +3863,19 @@ ix86_emit_tls_call (rtx tls_set, x86_cse_kind kind, > basic_block bb, > (note 4 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK) > (note 2 4 26 2 NOTE_INSN_FUNCTION_BEG) > > - or after NOTE_INSN_BASIC_BLOCK a basic block with only > - a label: > + or after NOTE_INSN_BASIC_BLOCK in a basic block with > + only a label: > > (code_label 78 11 77 3 14 (nil) [1 uses]) > (note 77 78 54 3 [bb 3] NOTE_INSN_BASIC_BLOCK) > > + or after debug marker in a basic block with only a > + debug marker: > + > + (note 3 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK) > + (note 2 3 5 2 NOTE_INSN_FUNCTION_BEG) > + (debug_insn 5 2 16 2 (debug_marker) "x.c":6:3 -1 (nil)) > + > */ > insn = insn ? PREV_INSN (insn) : BB_END (bb); > *after_p = insn; > diff --git a/gcc/testsuite/gcc.target/i386/pr121668-1a.c > b/gcc/testsuite/gcc.target/i386/pr121668-1a.c > new file mode 100644 > index 00000000000..eb553081eb3 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr121668-1a.c > @@ -0,0 +1,13 @@ > +/* { dg-do compile { target *-*-linux* } } */ > +/* { dg-options "-Og -g -fpic -fplt -mtls-dialect=gnu" } */ > + > +typedef int caml_domain_state; > +thread_local caml_domain_state caml_state; > +void > +caml_empty_mark_stack () > +{ > + while (caml_state) > + caml_state = 0; > +} > + > +/* { dg-final { scan-assembler-times "call\[ \t\]__tls_get_addr@PLT" 1 { > target { ! ia32 } } } } */ > -- > 2.51.0 > -- BR, Hongtao