]> git.ipfire.org Git - thirdparty/gcc.git/commit
opcodes: fix wrong code in expand_binop_directly [PR117811]
authorRichard Earnshaw <rearnsha@arm.com>
Thu, 20 Mar 2025 14:42:59 +0000 (14:42 +0000)
committerRichard Earnshaw <rearnsha@arm.com>
Fri, 13 Jun 2025 11:12:39 +0000 (12:12 +0100)
commitef18d9570a48bab3d3c54e5d3f72b0611c891035
treec1ad1e2922d466749d3340b180f71166eba4462c
parent7dbf4964b80eaa5f047be24949e294b8b25a2419
opcodes: fix wrong code in expand_binop_directly [PR117811]

If expand_binop_directly fails to add a REG_EQUAL note it tries to
unwind and restart.  But it can unwind too far if expand_binop changed
some of the operands before calling it.  We don't need to unwind that
far anyway since we should end up taking exactly the same route next
time, just without a target rtx.

To fix this we remove LAST from the argument list and let the callers
(all in expand_binop) do their own unwinding if the call fails.
Instead we unwind just as far as the entry to expand_binop_directly
and recurse within this function instead of all the way back up.

gcc/ChangeLog:

PR middle-end/117811
* optabs.cc (expand_binop_directly): Remove LAST as an argument,
instead record the last insn on entry.  Only delete insns if
we need to restart and restart by calling ourself, not expand_binop.
(expand_binop): Update callers to expand_binop_directly.  If it
fails to expand the operation, delete back to LAST.

gcc/testsuite:

PR middle-end/117811
* gcc.dg/torture/pr117811.c: New test.

(cherry picked from commit 7679b826840c58343d72d05922355b646db4bdcc)
gcc/optabs.cc
gcc/testsuite/gcc.dg/torture/pr117811.c [new file with mode: 0644]