]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Emit the TLS call after NOTE_INSN_FUNCTION_BEG
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 22 Aug 2025 12:56:42 +0000 (05:56 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 22 Aug 2025 13:12:36 +0000 (06:12 -0700)
For the beginning basic block:

(note 4 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 4 26 2 NOTE_INSN_FUNCTION_BEG)

emit the TLS call after NOTE_INSN_FUNCTION_BEG.

gcc/

PR target/121635
* config/i386/i386-features.cc (ix86_emit_tls_call): Emit the
TLS call after NOTE_INSN_FUNCTION_BEG.

gcc/testsuite/

PR target/121635
* gcc.target/i386/pr121635-1a.c: New test.
* gcc.target/i386/pr121635-1b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
gcc/config/i386/i386-features.cc
gcc/testsuite/gcc.target/i386/pr121635-1a.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr121635-1b.c [new file with mode: 0644]

index 514d2a5d3784d65d4b13774e276b5ff701b9cb81..cdb2a0b34b27707af0afb71d37eb33b8630b7739 100644 (file)
@@ -3796,14 +3796,20 @@ ix86_emit_tls_call (rtx tls_set, x86_cse_kind kind, basic_block bb,
        {
          if (insn == BB_END (bb))
            {
-             /* This must be a basic block with only a label:
+             /* This must be the beginning basic block:
+
+                (note 4 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
+                (note 2 4 26 2 NOTE_INSN_FUNCTION_BEG)
+
+                or 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)
 
               */
              gcc_assert (NOTE_P (insn)
-                         && NOTE_KIND (insn) == NOTE_INSN_BASIC_BLOCK);
+                         && (NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG
+                             || NOTE_KIND (insn) == NOTE_INSN_BASIC_BLOCK));
              insn = NULL;
              break;
            }
@@ -3842,8 +3848,14 @@ ix86_emit_tls_call (rtx tls_set, x86_cse_kind kind, basic_block bb,
            }
          else
            {
-             /* Emit the TLS call after NOTE_INSN_BASIC_BLOCK in a
-                basic block with only a label:
+             /* Emit the TLS call after NOTE_INSN_FUNCTION_BEG in the
+                beginning basic block:
+
+                (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:
 
                 (code_label 78 11 77 3 14 (nil) [1 uses])
                 (note 77 78 54 3 [bb 3] NOTE_INSN_BASIC_BLOCK)
diff --git a/gcc/testsuite/gcc.target/i386/pr121635-1a.c b/gcc/testsuite/gcc.target/i386/pr121635-1a.c
new file mode 100644 (file)
index 0000000..4db7def
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-O2 -fpic -fplt -mtls-dialect=gnu" } */
+
+extern int get_cordz_mean_interval ();
+extern thread_local long cordz_next_sample, kIntervalIfDisabled;
+extern bool cordz_should_profile_slow (void);
+inline bool
+cordz_should_profile (void)
+{
+  return cordz_should_profile_slow ();
+}
+bool
+cordz_should_profile_slow (void)
+{
+  int mean_interval = get_cordz_mean_interval ();
+  if (mean_interval)
+    cordz_next_sample = kIntervalIfDisabled;
+  return cordz_next_sample || cordz_should_profile ();
+}
+
+/* { dg-final { scan-assembler-times "call\[ \t\]__tls_get_addr@PLT" 2 { target { ! ia32 } } } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr121635-1b.c b/gcc/testsuite/gcc.target/i386/pr121635-1b.c
new file mode 100644 (file)
index 0000000..4095fb5
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile { target *-*-linux* } } */
+/* { dg-options "-O2 -fpic -fplt -mtls-dialect=gnu2" } */
+
+#include "pr121635-1a.c"
+
+/* { dg-final { scan-assembler-times "call\[ \t\]\\*cordz_next_sample@TLSCALL\\(%(?:r|e)ax\\)" 1 { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-times "call\[ \t\]\\*kIntervalIfDisabled@TLSCALL\\(%(?:r|e)ax\\)" 1 { target { ! ia32 } } } } */