]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
x86-64: Emit the TLS call after debug marker
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 26 Aug 2025 22:29:25 +0000 (15:29 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 27 Aug 2025 04:13:27 +0000 (21:13 -0700)
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.tools@gmail.com>
gcc/config/i386/i386-features.cc
gcc/testsuite/gcc.target/i386/pr121668-1a.c [new file with mode: 0644]

index cdb2a0b34b27707af0afb71d37eb33b8630b7739..93e20947edf3e82b8cdab69dd0129cc7dd086f77 100644 (file)
@@ -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))));
              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 (file)
index 0000000..eb55308
--- /dev/null
@@ -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 } } } } */