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

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Richard Sandiford <rsand...@gcc.gnu.org>:

https://gcc.gnu.org/g:387dba05e4207fc3f9a2f2bcb09a343a999c76fc

commit r15-5443-g387dba05e4207fc3f9a2f2bcb09a343a999c76fc
Author: Richard Sandiford <richard.sandif...@arm.com>
Date:   Tue Nov 19 10:19:24 2024 +0000

    Avoid repeated calls to temporarily_undo_changes [PR117297]

    In an attempt to reduce compile time, rtl-ssa computes the cost
    of existing instructions lazily rather than eagerly.  However,
    this means that it might need to calculate the cost of an existing
    instruction while a change group is already in progress for the
    instruction.  rtl_ssa::insn_info::calculate_cost therefore temporarily
    undoes any in-progress changes in order to get back the original pattern
    and insn code.

    rtl-ssa's main use of insn costs is in rtl_ssa::changes_are_worthwhile,
    which calculates the cost of a change involving an arbitrary number
    of instructions.  Summing up the original cost of N instructions
    while those N instructions have in-progress changes could lead to
    O(N*N) rtl changes, since each lazy calculation might have to
    temporarily undo the changes to all N instructions.

    We can avoid that by converting the current temporarily_undo_changes/
    redo_changes pair into an RAII class and extending it to allow
    nested uses.  rtl_ssa::changes_are_worthwhile can then undo the
    in-progress changes once, before computing the original cost of all
    the instructions.

    gcc/
            PR rtl-optimization/117297
            * recog.h (temporarily_undo_changes, redo_changes): Delete in
            favor of...
            (undo_recog_changes): ...this new RAII class.
            * fwprop.cc (should_replace_address): Update accordingly.
            (fwprop_propagation::check_mem): Likewise.
            (try_fwprop_subst_note): Likewise.
            (try_fwprop_subst_pattern): Likewise.
            * rtl-ssa/insns.cc (insn_info::calculate_cost): Likewise.
            * rtl-ssa/changes.cc (rtl_ssa::changes_are_worthwhile): Temporarily
            undo all in-progress changes while computing the cost of the
original
            sequence.
            * recog.cc (temporarily_undone_changes): Replace with...
            (undo_recog_changes::s_num_changes): ...this static member
variable.
            (validate_change_1): Update check accordingly.
            (confirm_change_group): Likewise.
            (num_validated_changes): Likewise.
            (temporarily_undo_changes): Replace with...
            (undo_recog_changes::undo_recog_changes): ...this constructor.
            (redo_changes): Replace with...
            (undo_recog_changes::~undo_recog_changes): ...this destructor.
  • [Bug rtl-optimization/117297] [... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to