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

--- Comment #21 from CVS 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:24c06560a7fa39049911eeb8777325d112e0deb9

commit r13-6739-g24c06560a7fa39049911eeb8777325d112e0deb9
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Fri Mar 17 18:59:56 2023 +0100

    tree-inline: Fix up multiversioning with vector arguments [PR105554]

    The following testcase ICEs, because we call tree_function_versioning from
    old_decl which has target attributes not supporting V4DImode and so
    DECL_MODE of DECL_ARGUMENTS is BLKmode, while new_decl supports those.
    tree_function_versioning initially copies DECL_RESULT and DECL_ARGUMENTS
    from old_decl to new_decl, then calls initialize_cfun to create cfun
    and only when the cfun is created it can later actually remap_decl
    DECL_RESULT and DECL_ARGUMENTS etc.
    The problem is that initialize_cfun -> push_struct_function ->
    allocate_struct_function calls relayout_decl on DECL_RESULT and
    DECL_ARGUMENTS, which clobbers DECL_MODE of old_decl and we then ICE
because
    of it.
    In particular, allocate_struct_function does:
          if (!abstract_p)
            {
              /* Now that we have activated any function-specific attributes
                 that might affect layout, particularly vector modes, relayout
                 each of the parameters and the result.  */
              relayout_decl (result);
              for (tree parm = DECL_ARGUMENTS (fndecl); parm;
                   parm = DECL_CHAIN (parm))
                relayout_decl (parm);

              /* Similarly relayout the function decl.  */
              targetm.target_option.relayout_function (fndecl);
            }

          if (!abstract_p && aggregate_value_p (result, fndecl))
            {
     #ifdef PCC_STATIC_STRUCT_RETURN
              cfun->returns_pcc_struct = 1;
     #endif
              cfun->returns_struct = 1;
            }
    Now, in the case of tree_function_versioning, I believe all that we need
    from these is possibly the
    targetm.target_option.relayout_function (fndecl);
    call (arm only), we will remap DECL_RESULT and DECL_ARGUMENTS later on
    and copy_decl_for_dup_finish in that case will handle all we need:
      /* For vector typed decls make sure to update DECL_MODE according
         to the new function context.  */
      if (VECTOR_TYPE_P (TREE_TYPE (copy)))
        SET_DECL_MODE (copy, TYPE_MODE (TREE_TYPE (copy)));
    We don't need the cfun->returns_*struct either, because we override it
    in initialize_cfun a few lines later:
      /* Copy items we preserve during cloning.  */
    ...
      cfun->returns_struct = src_cfun->returns_struct;
      cfun->returns_pcc_struct = src_cfun->returns_pcc_struct;

    So, to avoid the clobbering of DECL_RESULT/DECL_ARGUMENTS of old_decl,
    the following patch arranges allocate_struct_function to be called with
    abstract_p true and calls targetm.target_option.relayout_function (fndecl);
    by hand.

    The removal of DECL_RESULT/DECL_ARGUMENTS copying at the start of
    initialize_cfun is removed because the only caller -
    tree_function_versioning, does that unconditionally before.

    2023-03-17  Jakub Jelinek  <ja...@redhat.com>

            PR target/105554
            * function.h (push_struct_function): Add ABSTRACT_P argument
defaulted
            to false.
            * function.cc (push_struct_function): Add ABSTRACT_P argument, pass
it
            to allocate_struct_function instead of false.
            * tree-inline.cc (initialize_cfun): Don't copy DECL_ARGUMENTS
            nor DECL_RESULT here.  Pass true as ABSTRACT_P to
            push_struct_function.  Call targetm.target_option.relayout_function
            after it.
            (tree_function_versioning): Formatting fix.

            * gcc.target/i386/pr105554.c: New test.

Reply via email to