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

--- Comment #19 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:01acd453d89ff5e414fade2dfeeae1f652143376

commit r15-9132-g01acd453d89ff5e414fade2dfeeae1f652143376
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Apr 1 16:47:37 2025 +0200

    tailc: Improve tail recursion handling [PR119493]

    This is a partial step towards fixing that PR.
    For musttail recursive calls which have non-is_gimple_reg_type typed
    parameters, the only case we've handled was if the exact parameter
    was passed through (perhaps modified, but still the same PARM_DECL).
    That isn't necessary, we can copy the argument to the parameter as well
    (just need to watch for the use of the parameter in later arguments,
    say musttail recursive call which swaps 2 structure arguments).

    The patch attempts to play safe and punts if any of the parameters are
    addressable (like we do for all normal tail calls and tail recursions,
    except for musttail in the posted unreviewed patch).

    With this patch (at least when early inlining isn't done on not yet
    optimized body) inlining should see already tail recursion optimized
    body and will not have problems with SRA breaking musttail.

    This version of the patch limits this for musttail tail recursions,
    with intent to enable for all tail recursions in GCC 16.

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

            PR tree-optimization/119493
            * tree-tailcall.cc (find_tail_calls): Don't punt on tail recusion
            if some arguments don't have is_gimple_reg_type, only punt if they
            have non-POD types, or volatile, or addressable or (for now) it is
            not a musttail call.  Set tailr_arg_needs_copy in those cases too.
            (eliminate_tail_call): Copy call arguments to params if they don't
            have is_gimple_reg_type, use temporaries if the argument is used
            later.
            (tree_optimize_tail_calls_1): Skip !is_gimple_reg_type
            tailr_arg_needs_copy parameters.  Formatting fix.

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

Reply via email to