From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6AD3715827B for ; Tue, 26 Aug 2025 23:42:57 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 55F94340FA3 for ; Tue, 26 Aug 2025 23:42:57 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 4A9E2110560; Tue, 26 Aug 2025 23:42:56 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 44128110560 for ; Tue, 26 Aug 2025 23:42:56 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E3F35340EAF for ; Tue, 26 Aug 2025 23:42:55 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 10C4934DC for ; Tue, 26 Aug 2025 23:42:54 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1756251769.716d0a7b2b116dc499a01370f879e6aa35a113eb.sam@gentoo> Subject: [gentoo-commits] proj/gcc-patches:master commit in: 16.0.0/gentoo/ X-VCS-Repository: proj/gcc-patches X-VCS-Files: 16.0.0/gentoo/87_all_PR121668-x86-64-Emit-the-TLS-call-after-debug-marker.patch 16.0.0/gentoo/88_all-x86-64-Better-compare-source-operands-of-tls_dynamic.patch 16.0.0/gentoo/README.history X-VCS-Directories: 16.0.0/gentoo/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 716d0a7b2b116dc499a01370f879e6aa35a113eb X-VCS-Branch: master Date: Tue, 26 Aug 2025 23:42:54 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: c6ec6949-bdff-4e4d-b09f-4cd5f7448bbd X-Archives-Hash: 99c8cc93269aaa52b1aeb441457a26d1 commit: 716d0a7b2b116dc499a01370f879e6aa35a113eb Author: Sam James gentoo org> AuthorDate: Tue Aug 26 23:41:56 2025 +0000 Commit: Sam James gentoo 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 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: +From: "H.J. Lu" +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 +--- + 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: +In-Reply-To: +References: +From: "H.J. Lu" +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] ) + ] 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] ) + (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] ) + ] 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] ) + (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 +--- + 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] ) ++ (reg:DI 100) ++ (reg/f:DI 7 sp) ++ ] UNSPEC_TLSDESC) ++ ++ against ++ ++ (unspec:DI [ ++ (symbol_ref:DI ("caml_state") [flags 0x10] ) ++ (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