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

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Kyrylo Tkachov <[email protected]>:

https://gcc.gnu.org/g:a0f92a2e71bfe49085d9a3a5fbc219a7efd7411b

commit r17-5804-ga0f92a2e71bfe49085d9a3a5fbc219a7efd7411b
Author: Kyrylo Tkachov <[email protected]>
Date:   Thu Oct 15 20:03:45 2026 +0200

    target, aarch64: Add hooks for shared jump tables [PR middle-end/126236]

    The copies of a tablejump can share one jump table only if every copy
    reaches the table and computes the same destinations from it.  Most ports
    address the table through its label, with absolute entries or entries
    relative to that label, and need nothing more.  Some dispatch sequences
    depend on the table following the jump instead.

    Add TARGET_CAN_SHARE_JUMP_TABLE_P so that a port can refuse sharing for a
    particular dispatch under the current function's target options.  It is
    queried before duplication only.  It defaults to true.  A port that cannot
    share tables at all defines it as the new hook_bool_rtx_insn_false.  Output
    and late verification do not query it.

    AArch64 addr_diff_vec entries are relative to a synthetic text label.  The
    casesi output sequence currently defines that label at each dispatch.  If
    several dispatches share one table, they define the same assembler symbol
more
    than once.

    The base label belongs to the table:

      dispatch A --\
      dispatch B ----> .LrtxN: -> table N
      dispatch C --/

    Add TARGET_ASM_JUMP_TABLE_BASE and call it once per shared table while
final
    still has the function section selected.  Only a port whose dispatch output
    would otherwise define the base of the entries needs it.

    Preserve the existing AArch64 path for an unshared table.  Its casesi
output
    still defines the base label and uses ADR.  Once a table is shared, the
hook
    emits the base label and each dispatch refers to it.  Shared copies can be
more
    than ADR's range from the base label, so use ADRP and ADD outside the tiny
code
    model and account for the extra instruction in the length attribute.

    No pass creates shared tables in this patch.

    gcc/ChangeLog:

            PR middle-end/126236
            * target.def (asm_out.jump_table_base): New hook.
            (can_share_jump_table_p): Likewise.
            * hooks.cc (hook_bool_rtx_insn_false): New function.
            * hooks.h (hook_bool_rtx_insn_false): Declare.
            * doc/tm.texi.in (Dispatch Tables): Document the hooks.
            * doc/tm.texi: Regenerate.
            * doc/md.texi (Standard Names): Refer to
            TARGET_CAN_SHARE_JUMP_TABLE_P.
            * final.cc (final_scan_insn_1): Call the jump-table base hook
before
            switching away from the function section or invoking target table
            output.
            * config/aarch64/aarch64.cc (aarch64_far_jump_table_base_p): New
            function.
            (aarch64_output_casesi): Emit the base label here for an unshared
            table.  Use ADRP and ADD for a shared table outside the tiny code
            model.
            (aarch64_casesi_far_base_p): New function.
            (aarch64_asm_jump_table_base): New function.
            (TARGET_ASM_JUMP_TABLE_BASE): Define.
            * config/aarch64/aarch64-protos.h (aarch64_casesi_far_base_p):
            Declare.
            * config/aarch64/aarch64.md (length): Account for the longer base
            sequence.

    Signed-off-by: Kyrylo Tkachov <[email protected]>

Reply via email to