On 7/9/24 9:28 AM, Richard Sandiford wrote:
Bit of a brown paper bag issue, but: due to the representation
of the insn chain, insn_info::prev_any_insn would sometimes skip
over instructions.  This led to an invalid update in the PR when
adding and removing instructions.

I think one of the reasons I failed to spot this when checking
the code is that m_prev_insn_or_last_debug_insn is misnamed:
it's the previous instruction *of the same type* or the last
debug instruction in a group.  The patch therefore renames it to
m_prev_sametype_or_last_debug_insn (with the term prev_sametype
already being used in some accessors).

The reason this didn't show up earlier is that (a) prev_any_insn
is rarely used directly, (b) no instructions were lost from the
def-use chains, and (c) only consecutive debug instructions were
skipped when walking the insn chain.

The chaining scheme makes prev_any_insn more complicated than
next_any_insn, prev_nondebug_insn and next_nondebug_insn, but the
object code produced is still relatively simple.

Bootstrapped & regression-tested on aarch64-linux-gnu and
x86_64-linux-gnu.  OK to install?

Richard


gcc/
        PR rtl-optimization/115785
        * rtl-ssa/insns.h (insn_info::prev_insn_or_last_debug_insn)
        (insn_info::next_nondebug_or_debug_insn): Remove typedefs.
        (insn_info::m_prev_insn_or_last_debug_insn): Rename to...
        (insn_info::m_prev_sametype_or_last_debug_insn): ...this.
        * rtl-ssa/internals.inl (insn_info::insn_info): Update after
        above renaming.
        (insn_info::copy_prev_from): Likewise.
        (insn_info::set_prev_sametype_insn): Likewise.
        (insn_info::set_last_debug_insn): Likewise.
        (insn_info::clear_insn_links): Likewise.
        (insn_info::has_insn_links): Likewise.
        * rtl-ssa/member-fns.inl (insn_info::prev_nondebug_insn): Likewise.
        (insn_info::prev_any_insn): Fix moves from non-debug to debug insns.

gcc/testsuite/
        PR rtl-optimization/115785
        * g++.dg/torture/pr115785.C: New test.
OK.

Jeff

Reply via email to