https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121694

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by H.J. Lu <h...@gcc.gnu.org>:

https://gcc.gnu.org/g:62843b3453ee30f77ceb7e09769e0cea9920a2cd

commit r16-3458-g62843b3453ee30f77ceb7e09769e0cea9920a2cd
Author: H.J. Lu <hjl.to...@gmail.com>
Date:   Wed Aug 27 19:14:13 2025 -0700

    x86-64: Improve source operand check for TLS_CALL

    Source operands of 2 TLS_CALL 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.  Use the UNSPEC_TLSDESC
    symbol

    (unspec:DI [(symbol_ref:DI ("caml_state") [flags 0x10])] UNSPEC_TLSDESC))

    to check if 2 TLS_CALL patterns have the same source.

    For TLS64_COMBINE, use both UNSPEC_TLSDESC and UNSPEC_DTPOFF unspecs to
    check if 2 TLS64_COMBINE patterns have the same source.

    gcc/

            PR target/121694
            * config/i386/i386-features.cc (redundant_pattern): Add
            tlsdesc_val.
            (pass_x86_cse): Likewise.
            (pass_x86_cse::tls_set_insn_from_symbol): New member function.
            (pass_x86_cse::candidate_gnu2_tls_p): Set tlsdesc_val.  For
            TLS64_COMBINE, match both UNSPEC_TLSDESC and UNSPEC_DTPOFF
            symbols.  For TLS64_CALL, match the UNSPEC_TLSDESC sumbol.
            (pass_x86_cse::x86_cse): Initialize the tlsdesc_val field in
            load.  Pass the tlsdesc_val field to ix86_place_single_tls_call
            for X86_CSE_TLSDESC.

    gcc/testsuite/

            PR target/121694
            * gcc.target/i386/pr121668-1b.c: New test.
            * gcc.target/i386/pr121694-1a.c: Likewise.
            * gcc.target/i386/pr121694-1b.c: Likewise.

    Signed-off-by: H.J. Lu <hjl.to...@gmail.com>

Reply via email to