From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gcc-patches:master commit in: 16.0.0/gentoo/
Date: Tue, 26 Aug 2025 23:42:54 +0000 (UTC) [thread overview]
Message-ID: <1756251769.716d0a7b2b116dc499a01370f879e6aa35a113eb.sam@gentoo> (raw)
commit: 716d0a7b2b116dc499a01370f879e6aa35a113eb
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 26 23:41:56 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Aug 26 23:42:49 2025 +0000
URL: https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=716d0a7b
16.0.0: add two more TLS patches
One is for the OCaml ICE and one is an optimisation improvement.
Bug: https://bugs.gentoo.org/961977
Signed-off-by: Sam James <sam <AT> gentoo.org>
...6-64-Emit-the-TLS-call-after-debug-marker.patch | 105 +++++++++
...er-compare-source-operands-of-tls_dynamic.patch | 234 +++++++++++++++++++++
16.0.0/gentoo/README.history | 2 +
3 files changed, 341 insertions(+)
diff --git a/16.0.0/gentoo/87_all_PR121668-x86-64-Emit-the-TLS-call-after-debug-marker.patch b/16.0.0/gentoo/87_all_PR121668-x86-64-Emit-the-TLS-call-after-debug-marker.patch
new file mode 100644
index 0000000..ace990f
--- /dev/null
+++ b/16.0.0/gentoo/87_all_PR121668-x86-64-Emit-the-TLS-call-after-debug-marker.patch
@@ -0,0 +1,105 @@
+From ca5a4b3eea207904c64e638a4ecefd347f386abb Mon Sep 17 00:00:00 2001
+Message-ID: <ca5a4b3eea207904c64e638a4ecefd347f386abb.1756251629.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Tue, 26 Aug 2025 15:29:25 -0700
+Subject: [PATCH 1/2] x86-64: Emit the TLS call after debug marker
+
+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 | 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 cdb2a0b34b27..93e20947edf3 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))));
+ 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 000000000000..eb553081eb31
+--- /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 } } } } */
+
+base-commit: a43c30cb6f451d60b7e19be09da075ab0ff5830f
+--
+2.51.0
+
diff --git a/16.0.0/gentoo/88_all-x86-64-Better-compare-source-operands-of-tls_dynamic.patch b/16.0.0/gentoo/88_all-x86-64-Better-compare-source-operands-of-tls_dynamic.patch
new file mode 100644
index 0000000..44865e7
--- /dev/null
+++ b/16.0.0/gentoo/88_all-x86-64-Better-compare-source-operands-of-tls_dynamic.patch
@@ -0,0 +1,234 @@
+From ec4cc64262841e49967c2bf69dcd095985c2e304 Mon Sep 17 00:00:00 2001
+Message-ID: <ec4cc64262841e49967c2bf69dcd095985c2e304.1756251629.git.sam@gentoo.org>
+In-Reply-To: <ca5a4b3eea207904c64e638a4ecefd347f386abb.1756251629.git.sam@gentoo.org>
+References: <ca5a4b3eea207904c64e638a4ecefd347f386abb.1756251629.git.sam@gentoo.org>
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Tue, 26 Aug 2025 15:31:34 -0700
+Subject: [PATCH 2/2] x86-64: Better compare source operands of
+ *tls_dynamic_gnu2_call_64_di
+
+Source operands of 2 *tls_dynamic_gnu2_call_64_di patterns in
+
+(insn 10 9 11 3 (set (reg:DI 100)
+ (unspec:DI [
+ (symbol_ref:DI ("caml_state") [flags 0x10] <var_decl 0x7fe10e1d9e40 caml_state>)
+ ] UNSPEC_TLSDESC)) "x.c":7:16 1674 {*tls_dynamic_gnu2_lea_64_di}
+ (nil))
+(insn 11 10 12 3 (parallel [
+ (set (reg:DI 99)
+ (unspec:DI [
+ (symbol_ref:DI ("caml_state") [flags 0x10] <var_decl 0x7fe10e1d9e40 caml_state>)
+ (reg:DI 100)
+ (reg/f:DI 7 sp)
+ ] UNSPEC_TLSDESC))
+ (clobber (reg:CC 17 flags))
+ ]) "x.c":7:16 1676 {*tls_dynamic_gnu2_call_64_di}
+ (expr_list:REG_DEAD (reg:DI 100)
+ (expr_list:REG_UNUSED (reg:CC 17 flags)
+ (nil))))
+
+and
+
+(insn 19 17 20 4 (set (reg:DI 104)
+ (unspec:DI [
+ (symbol_ref:DI ("caml_state") [flags 0x10] <var_decl 0x7fe10e1d9e40 caml_state>)
+ ] UNSPEC_TLSDESC)) "x.c":6:10 discrim 1 1674 {*tls_dynamic_gnu2_lea_64_di}
+ (nil))
+(insn 20 19 21 4 (parallel [
+ (set (reg:DI 103)
+ (unspec:DI [
+ (symbol_ref:DI ("caml_state") [flags 0x10] <var_decl 0x7fe10e1d9e40 caml_state>)
+ (reg:DI 104)
+ (reg/f:DI 7 sp)
+ ] UNSPEC_TLSDESC))
+ (clobber (reg:CC 17 flags))
+ ]) "x.c":6:10 discrim 1 1676 {*tls_dynamic_gnu2_call_64_di}
+ (expr_list:REG_DEAD (reg:DI 104)
+ (expr_list:REG_UNUSED (reg:CC 17 flags)
+ (nil))))
+
+are the same even though rtx_equal_p returns false since (reg:DI 100)
+and (reg:DI 104) are set from the same symbol. Add x86_cse_rtx_equal_p
+to compare source operands of *tls_dynamic_gnu2_call_64_di patterns and
+return true if only source operands differ and they are set from the
+same symbol.
+
+gcc/
+
+ * config/i386/i386-features.cc
+ (pass_x86_cse::x86_cse_rtx_equal_p): New.
+ (pass_x86_cse::tls_set_insn_from_symbol): Likewise.
+ (pass_x86_cse::candidate_gnu2_tls_p): Call
+ tls_set_insn_from_symbol.
+ (pass_x86_cse::x86_cse): Call x86_cse_rtx_equal_p, instead of
+ rtx_equal_p, to compare 2 values.
+
+gcc/testsuite/
+
+ * gcc.target/i386/pr121668-1b.c: New test.
+
+Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
+---
+ gcc/config/i386/i386-features.cc | 116 +++++++++++++++-----
+ gcc/testsuite/gcc.target/i386/pr121668-1b.c | 6 +
+ 2 files changed, 95 insertions(+), 27 deletions(-)
+ create mode 100644 gcc/testsuite/gcc.target/i386/pr121668-1b.c
+
+diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
+index 93e20947edf3..ce77e91c1203 100644
+--- a/gcc/config/i386/i386-features.cc
++++ b/gcc/config/i386/i386-features.cc
+@@ -4168,8 +4168,95 @@ private:
+ bool candidate_gnu_tls_p (rtx_insn *, attr_tls64);
+ bool candidate_gnu2_tls_p (rtx, attr_tls64);
+ bool candidate_vector_p (rtx);
++ bool x86_cse_rtx_equal_p (const_rtx, const_rtx);
++ rtx_insn *tls_set_insn_from_symbol (const_rtx, rtx *);
+ }; // class pass_x86_cse
+
++/* Return true if X and Y are equal. */
++
++bool
++pass_x86_cse::x86_cse_rtx_equal_p (const_rtx x, const_rtx y)
++{
++ if (kind == X86_CSE_TLSDESC
++ && GET_CODE (x) == UNSPEC
++ && XINT (x, 1) == UNSPEC_TLSDESC
++ && SYMBOL_REF_P (XVECEXP (x, 0, 0)))
++ {
++ /* Compare
++
++ (unspec:DI [
++ (symbol_ref:DI ("caml_state") [flags 0x10] <var_decl 0x7fffe99d9e40 caml_state>)
++ (reg:DI 100)
++ (reg/f:DI 7 sp)
++ ] UNSPEC_TLSDESC)
++
++ against
++
++ (unspec:DI [
++ (symbol_ref:DI ("caml_state") [flags 0x10] <var_decl 0x7fffe99d9e40 caml_state>)
++ (reg:DI 104)
++ (reg/f:DI 7 sp)
++ ] UNSPEC_TLSDESC)
++
++ If (reg:DI 100) and (reg:DI 104) are defined from the same source,
++ they are equal. */
++
++ if (GET_CODE (y) != UNSPEC
++ || XINT (y, 1) != UNSPEC_TLSDESC
++ || !SYMBOL_REF_P (XVECEXP (y, 0, 0))
++ || !rtx_equal_p (XVECEXP (x, 0, 0), XVECEXP (y, 0, 0)))
++ return false;
++
++ x = XVECEXP (x, 0, 1);
++ y = XVECEXP (y, 0, 1);
++ if (rtx_equal_p (x, y))
++ return true;
++
++ rtx tls_symbol = nullptr;
++ return (tls_set_insn_from_symbol (x, &tls_symbol)
++ && tls_symbol
++ && tls_set_insn_from_symbol (y, &tls_symbol));
++ }
++
++ return rtx_equal_p (x, y);
++}
++
++/* Return the instruction which sets REG from one symbol and store the
++ symbol in *TLS_SYMBOL_P if *TLS_SYMBOL_P is nullptr. */
++
++rtx_insn *
++pass_x86_cse::tls_set_insn_from_symbol (const_rtx reg, rtx *tls_symol_p)
++{
++ rtx_insn *set_insn = nullptr;
++ rtx tls_symbol = *tls_symol_p;
++ for (df_ref ref = DF_REG_DEF_CHAIN (REGNO (reg));
++ ref;
++ ref = DF_REF_NEXT_REG (ref))
++ {
++ if (DF_REF_IS_ARTIFICIAL (ref))
++ return nullptr;
++
++ set_insn = DF_REF_INSN (ref);
++ if (get_attr_tls64 (set_insn) != TLS64_LEA)
++ return nullptr;
++
++ rtx tls_set = PATTERN (set_insn);
++ rtx tls_src = XVECEXP (SET_SRC (tls_set), 0, 0);
++ if (tls_symbol == nullptr)
++ {
++ if (!SYMBOL_REF_P (tls_src))
++ return nullptr;
++
++ tls_symbol = tls_src;
++ *tls_symol_p = tls_src;
++ }
++ else if (!rtx_equal_p (tls_symbol, tls_src))
++ return nullptr;
++ }
++
++ return set_insn;
++}
++
+ /* Return true and output def_insn, val, mode, scalar_mode and kind if
+ INSN is UNSPEC_TLS_GD or UNSPEC_TLS_LD_BASE. */
+
+@@ -4283,32 +4370,7 @@ pass_x86_cse::candidate_gnu2_tls_p (rtx set, attr_tls64 tls64)
+
+ */
+
+- df_ref ref;
+- rtx_insn *set_insn = nullptr;
+- for (ref = DF_REG_DEF_CHAIN (REGNO (src));
+- ref;
+- ref = DF_REF_NEXT_REG (ref))
+- {
+- if (DF_REF_IS_ARTIFICIAL (ref))
+- break;
+-
+- set_insn = DF_REF_INSN (ref);
+- tls64 = get_attr_tls64 (set_insn);
+- if (tls64 != TLS64_LEA)
+- {
+- set_insn = nullptr;
+- break;
+- }
+-
+- rtx tls_set = PATTERN (set_insn);
+- rtx tls_src = XVECEXP (SET_SRC (tls_set), 0, 0);
+- if (!rtx_equal_p (tls_symbol, tls_src))
+- {
+- set_insn = nullptr;
+- break;
+- }
+- }
+-
++ rtx_insn *set_insn = tls_set_insn_from_symbol (src, &tls_symbol);
+ if (!set_insn)
+ return false;
+
+@@ -4436,7 +4498,7 @@ pass_x86_cse::x86_cse (void)
+ /* Non all 0s/1s vector load must be in the same
+ basic block if it is in a recursive call. */
+ || !recursive_call_p)
+- && rtx_equal_p (load->val, val))
++ && x86_cse_rtx_equal_p (load->val, val))
+ {
+ /* Record instruction. */
+ bitmap_set_bit (load->insns, INSN_UID (insn));
+diff --git a/gcc/testsuite/gcc.target/i386/pr121668-1b.c b/gcc/testsuite/gcc.target/i386/pr121668-1b.c
+new file mode 100644
+index 000000000000..54a277506f83
+--- /dev/null
++++ b/gcc/testsuite/gcc.target/i386/pr121668-1b.c
+@@ -0,0 +1,6 @@
++/* { dg-do compile { target *-*-linux* } } */
++/* { dg-options "-Og -g -fpic -fplt -mtls-dialect=gnu2" } */
++
++#include "pr121668-1a.c"
++
++/* { dg-final { scan-assembler-times "call\[ \t\]\\*caml_state@TLSCALL\\(%(?:r|e)ax\\)" 1 { target { ! ia32 } } } } */
+--
+2.51.0
+
diff --git a/16.0.0/gentoo/README.history b/16.0.0/gentoo/README.history
index 44873fe..3ea56ff 100644
--- a/16.0.0/gentoo/README.history
+++ b/16.0.0/gentoo/README.history
@@ -1,6 +1,8 @@
13 ????
U 86_all_PR120933-i386-default-to-mtls-dialect-gnu2-if-appropriate.patch
+ + 87_all_PR121668-x86-64-Emit-the-TLS-call-after-debug-marker.patch
+ + 88_all-x86-64-Better-compare-source-operands-of-tls_dynamic.patch
12 24 August 2025
next reply other threads:[~2025-08-26 23:42 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 23:42 Sam James [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-11-09 22:42 [gentoo-commits] proj/gcc-patches:master commit in: 16.0.0/gentoo/ Sam James
2025-11-08 2:34 Sam James
2025-11-07 22:58 Sam James
2025-11-06 14:03 Sam James
2025-11-04 14:16 Sam James
2025-11-03 21:10 Sam James
2025-11-03 19:52 Sam James
2025-11-03 14:35 Sam James
2025-11-03 14:33 Sam James
2025-11-03 8:59 Sam James
2025-11-03 8:53 Sam James
2025-11-02 8:32 Sam James
2025-10-27 1:46 Sam James
2025-10-23 15:58 Sam James
2025-10-21 0:33 Sam James
2025-10-19 22:41 Sam James
2025-10-18 18:22 Sam James
2025-10-13 2:49 Sam James
2025-10-09 7:31 Sam James
2025-10-09 2:26 Sam James
2025-10-09 2:26 Sam James
2025-10-05 23:05 Sam James
2025-10-05 22:50 Sam James
2025-10-02 11:05 Sam James
2025-10-02 11:04 Sam James
2025-10-02 4:55 Sam James
2025-10-02 1:18 Sam James
2025-10-02 0:40 Sam James
2025-10-02 0:36 Sam James
2025-10-02 0:30 Sam James
2025-09-17 18:41 Sam James
2025-09-17 3:04 Sam James
2025-09-16 19:23 Sam James
2025-09-14 11:26 Sam James
2025-09-13 13:16 Sam James
2025-09-07 22:42 Sam James
2025-09-06 2:42 Sam James
2025-09-05 12:44 Sam James
2025-09-01 8:04 Sam James
2025-08-31 22:43 Sam James
2025-08-30 14:06 Sam James
2025-08-30 8:05 Sam James
2025-08-30 6:57 Sam James
2025-08-30 0:12 Sam James
2025-08-29 21:26 Sam James
2025-08-29 21:02 Sam James
2025-08-29 20:24 Sam James
2025-08-29 20:18 Sam James
2025-08-29 18:38 Sam James
2025-08-29 12:15 Sam James
2025-08-28 17:57 Sam James
2025-08-28 5:27 Sam James
2025-08-27 4:19 Sam James
2025-08-26 4:48 Sam James
2025-08-26 0:56 Sam James
2025-08-25 3:55 Sam James
2025-08-24 23:42 Sam James
2025-08-21 16:11 Sam James
2025-08-20 20:45 Sam James
2025-08-20 14:10 Sam James
2025-08-20 1:16 Sam James
2025-08-20 1:10 Sam James
2025-08-19 16:30 Sam James
2025-08-18 23:52 Sam James
2025-08-18 23:08 Sam James
2025-08-17 22:45 Sam James
2025-08-17 21:01 Sam James
2025-08-17 16:30 Sam James
2025-08-17 15:44 Sam James
2025-08-17 15:10 Sam James
2025-08-16 23:06 Sam James
2025-08-05 0:23 Sam James
2025-07-30 22:35 Sam James
2025-07-30 0:44 Sam James
2025-07-30 0:44 Sam James
2025-07-25 18:49 Sam James
2025-07-23 11:22 Sam James
2025-07-22 23:56 Sam James
2025-07-21 14:02 Sam James
2025-07-21 1:12 Sam James
2025-07-14 16:03 Sam James
2025-07-14 4:09 Sam James
2025-07-14 2:55 Sam James
2025-07-14 2:55 Sam James
2025-07-14 2:40 Sam James
2025-07-13 23:11 Sam James
2025-07-13 1:09 Sam James
2025-07-12 15:24 Sam James
2025-07-12 15:23 Sam James
2025-07-10 12:34 Sam James
2025-07-10 1:22 Sam James
2025-07-10 0:50 Sam James
2025-07-07 20:49 Sam James
2025-07-06 22:41 Sam James
2025-07-03 1:29 Sam James
2025-06-30 6:26 Sam James
2025-06-29 23:49 Sam James
2025-06-29 0:29 Sam James
2025-06-19 16:59 Sam James
2025-06-19 0:58 Sam James
2025-06-19 0:58 Sam James
2025-06-18 21:17 Sam James
2025-06-18 9:53 Sam James
2025-06-18 9:06 Sam James
2025-06-13 12:03 Sam James
2025-06-12 20:34 Sam James
2025-06-12 14:05 Sam James
2025-06-12 7:27 Sam James
2025-06-12 5:46 Sam James
2025-06-11 5:05 Sam James
2025-06-11 3:19 Sam James
2025-06-01 22:39 Sam James
2025-05-31 18:48 Sam James
2025-05-11 22:52 Sam James
2025-05-10 15:28 Sam James
2025-05-09 23:29 Sam James
2025-05-05 14:39 Sam James
2025-05-05 13:05 Sam James
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1756251769.716d0a7b2b116dc499a01370f879e6aa35a113eb.sam@gentoo \
--to=sam@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox