https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119493

--- Comment #18 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:02409a145946ca0d4f502f43fc3cc20de8b3dea1

commit r15-9125-g02409a145946ca0d4f502f43fc3cc20de8b3dea1
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Apr 1 11:43:16 2025 +0200

    tailr: Punt on tail recursions that would break musttail [PR119493]

    While working on the previous tailc patch, I've noticed the following
    problem.
    The testcase below fails, because we decide to tail recursion optimize
    the call, but tail recursion (as documented in tree-tailcall.cc) needs to
    add some result multiplication and/or addition if any tail recursion uses
    accumulator, which is added right before the return.
    So, if there are musttail non-recurive calls in the function, successful
    tail recursion optimization will mean we'll later error on the musttail
    calls.  musttail recursive calls are ok, those would be tail recursion
    optimized.

    So, the following patch punts on all tail recursion optimizations if it
    needs accumulators (add and/or mult) if there is at least one non-recursive
    musttail call.

    2025-04-01  Jakub Jelinek  <ja...@redhat.com>

            PR tree-optimization/119493
            * tree-tailcall.cc (tree_optimize_tail_calls_1): Ignore tail
recursion
            candidates which need accumulators if there is at least one
musttail
            non-recursive call.

            * gcc.dg/pr119493-2.c: New test.

Reply via email to