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 <[email protected]>
---
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