[PATCH] combine: Ignore trailing debug insns when checking return values
Yongqiang Tian
yqtian668@gmail.com
Sat Oct 10 01:33:23 GMT 2026
Hi Jeff,
I sent a v2 that instead uses prev_nondebug_insn, preserving the
existing treatment of notes.
I also added a regression test with a NOTE_INSN_DELETED between the
return-value USE
and the trailing debug instruction.
The v2 is here:
https://inbox.sourceware.org/gcc-patches/20261010012919.13081-1-yqtian668@gmail.com/
It was bootstrapped and regression tested on x86_64-pc-linux-gnu. I
also rebuilt the mips-elf
compiler and ran the two targeted RTL tests, which produced 8 expected
passes and no failures.
Thanks a lot for your guidance. Really a great learning experience for me.
Thanks,
Yongqiang
On Sat, 10 Oct 2026 at 04:37, Jeff Law <jeffrey.law@oss.qualcomm.com> wrote:
>
>
>
> On 10/8/26 9:14 PM, Yongqiang Tian wrote:
> > likely_spilled_retval_p uses BB_END to locate the USE of a
> > multi-register return value. With debug information, BB_END can be a
> > DEBUG_INSN, causing the check to fail and allowing combine to merge into
> > a return-register copy that it rejects without debug information.
> >
> > Other CFG code already handles DEBUG_INSNs at BB_END. Step backward
> > over trailing debug instructions and notes before inspecting the USE so
> > that this decision does not depend on debug information.
> >
> > Add a MIPS __RTL test that exercises the affected multi-register return
> > path directly.
> >
> > Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian.
> >
> > gcc/ChangeLog:
> >
> > * combine.cc (likely_spilled_retval_p): Skip trailing debug
> > instructions when locating the return-value USE.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.dg/rtl/mips/combine-likely-spilled-retval.c: New test.
> >
> > Signed-off-by: Yongqiang Tian <yqtian668@gmail.com>
> > ---
> > gcc/combine.cc | 9 +++-
> > .../rtl/mips/combine-likely-spilled-retval.c | 49 +++++++++++++++++++
> > 2 files changed, 57 insertions(+), 1 deletion(-)
> > create mode 100644 gcc/testsuite/gcc.dg/rtl/mips/combine-likely-spilled-retval.c
> >
> > diff --git a/gcc/combine.cc b/gcc/combine.cc
> > index 429530816..fd108f5a8 100644
> > --- a/gcc/combine.cc
> > +++ b/gcc/combine.cc
> > @@ -2315,7 +2315,14 @@ likely_spilled_retval_p (rtx_insn *insn)
> > unsigned mask;
> > struct likely_spilled_retval_info info;
> >
> > - if (!NONJUMP_INSN_P (use) || GET_CODE (PATTERN (use)) != USE || insn == use)
> > + /* With -g, BB_END may be a DEBUG_INSN. Step back so that this decision
> > + does not depend on debug information. */
> > + if (use && DEBUG_INSN_P (use))
> > + use = prev_nonnote_nondebug_insn_bb (use);
> I'm reasonably confident use can never be NULL here. Otherwise the old
> code would have been triggering an ICE since NONJUMP_INSN_P
> unconditionally dereferences its argument to get the IL node's rtx code.
>
> I don't think this is correct though. I think it introduces another
> potential compare-debug failure.
>
> Whether or not we walk backwards through a note becomes dependent on
> whether or not USE is a debug insn.
>
> jeff
>
>
More information about the Gcc-patches
mailing list