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

--- Comment #18 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:2ecaeee92414e6687ef6ce1f63fd16fcff3c5961

commit r16-3290-g2ecaeee92414e6687ef6ce1f63fd16fcff3c5961
Author: H.J. Lu <hjl.to...@gmail.com>
Date:   Sat Aug 16 14:04:33 2025 -0700

    x86: Place the TLS call before all register setting BBs

    We can't place a TLS call before a conditional jump in a basic block like

    (code_label 13 11 14 4 2 (nil) [1 uses])
    (note 14 13 16 4 [bb 4] NOTE_INSN_BASIC_BLOCK)
    (jump_insn 16 14 17 4 (set (pc)
            (if_then_else (le (reg:CCNO 17 flags)
                    (const_int 0 [0]))
                (label_ref 27)
                (pc))) "x.c":10:21 discrim 1 1462 {*jcc}
         (expr_list:REG_DEAD (reg:CCNO 17 flags)
            (int_list:REG_BR_PROB 628353713 (nil)))
     -> 27)

    since the TLS call will clobber flags register nor place a TLS call in a
    basic block if any live caller-saved registers aren't dead at the end of
    the basic block:

    ;; live  in      6 [bp] 7 [sp] 16 [argp] 17 [flags] 19 [frame] 104
    ;; live  gen     0 [ax] 102 106 108 116 117 118 120
    ;; live  kill    5 [di]

    Instead, we should place such call before all register setting basic
    blocks which dominate the current basic block.

    Keep track the replaced GNU and GNU2 TLS instructions.  Use these info to
    place the __tls_get_addr call and mark FLAGS register as dead.

    gcc/

            PR target/121572
            * config/i386/i386-features.cc (replace_tls_call): Add a bitmap
            argument and put the updated TLS instruction in the bitmap.
            (ix86_get_dominator_for_reg): New.
            (ix86_check_flags_reg): Likewise.
            (ix86_emit_tls_call): Likewise.
            (ix86_place_single_tls_call): Add 2 bitmap arguments for updated
            GNU and GNU2 TLS instructions.  Call ix86_emit_tls_call to emit
            TLS instruction.  Correct debug dump for before instruction.

    gcc/testsuite/

            PR target/121572
            * gcc.target/i386/pr121572-1a.c: New test.
            * gcc.target/i386/pr121572-1b.c: Likewise.
            * gcc.target/i386/pr121572-2a.c: Likewise.
            * gcc.target/i386/pr121572-2b.c: Likewise.

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

Reply via email to