]> 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>
Tue, 17 Jun 2025 09:28:16 +0000 (10:28 +0100)
commit80b11a66973e6e5a33d0bd43ab2a97df5b7accd9
tree048afbc888414d0d5f5af2d142d4495040617d51
parente1cd88e1bc5fcad7ea273459c0ccb8d4b2a2439e
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]