aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2025-08-22 05:56:42 -0700
committerH.J. Lu <hjl.tools@gmail.com>2025-08-22 06:12:36 -0700
commite12208722dabdad25cc13bb580991b5bf511a104 (patch)
treee5fe6d51d20709a2f7baea52d421d2901ea975c6 /gcc
parent60fca68165bb66943ac0f70e28b3d9f2df93c219 (diff)
downloadgcc-e12208722dabdad25cc13bb580991b5bf511a104.zip
gcc-e12208722dabdad25cc13bb580991b5bf511a104.tar.gz
gcc-e12208722dabdad25cc13bb580991b5bf511a104.tar.bz2
Emit the TLS call after NOTE_INSN_FUNCTION_BEG
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/i386/i386-features.cc20
-rw-r--r--gcc/testsuite/gcc.target/i386/pr121635-1a.c21
-rw-r--r--gcc/testsuite/gcc.target/i386/pr121635-1b.c7
3 files changed, 44 insertions, 4 deletions
diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
index 514d2a5..cdb2a0b 100644
--- a/gcc/config/i386/i386-features.cc
+++ b/gcc/config/i386/i386-features.cc
@@ -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
index 0000000..4db7def
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr121635-1a.c
@@ -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
index 0000000..4095fb5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr121635-1b.c
@@ -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 } } } } */