https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105554
--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> --- So, I have tried --- gcc/cgraphclones.cc.jj 2023-02-24 11:05:19.704595633 +0100 +++ gcc/cgraphclones.cc 2023-03-16 19:12:30.452503051 +0100 @@ -1094,6 +1094,15 @@ cgraph_node::create_version_clone_with_b || in_lto_p) new_version_node->unique_name = true; + if (target_attributes) + { + push_cfun (DECL_STRUCT_FUNCTION (new_decl)); + for (tree arg = DECL_ARGUMENTS (new_decl); arg; arg = DECL_CHAIN (arg)) + if (VECTOR_TYPE_P (TREE_TYPE (arg))) + SET_DECL_MODE (arg, TYPE_MODE (TREE_TYPE (arg))); + pop_cfun (); + } + /* Update the call_expr on the edges to call the new version node. */ update_call_expr (new_version_node); but that really didn't help, the problem seems to be actually different. >From what I can see, tree_function_versioning does: 6240 DECL_RESULT (new_decl) = DECL_RESULT (old_decl); 6241 DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl); 6242 initialize_cfun (new_decl, old_decl, 6243 new_entry ? new_entry->count : old_entry_block->count); and initialize_cfun will call allocate_function, which does: 4845 /* Now that we have activated any function-specific attributes 4846 that might affect layout, particularly vector modes, relayout 4847 each of the parameters and the result. */ 4848 relayout_decl (result); 4849 for (tree parm = DECL_ARGUMENTS (fndecl); parm; 4850 parm = DECL_CHAIN (parm)) 4851 relayout_decl (parm); So, we temporarily set DECL_ARGUMENTS and DECL_RESULT of new_decl to arguments/result of old_decl and allocate_function called relayout_decl on those, later on we create new arguments (which supposedly have correct DECL_MODE). But we've changed the old DECL_RESULT/DECL_ARGUMENTS.