https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117811
--- Comment #23 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Earnshaw <rearn...@gcc.gnu.org>: https://gcc.gnu.org/g:7679b826840c58343d72d05922355b646db4bdcc commit r15-8881-g7679b826840c58343d72d05922355b646db4bdcc Author: Richard Earnshaw <rearn...@arm.com> Date: Thu Mar 20 14:42:59 2025 +0000 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.