On Fri, Mar 27, 2020 at 11:07 AM Kito Cheng <[email protected]> wrote:
>
> - The alignment for local variable was adjust during
> estimate_stack_frame_size,
> however it seems wrong spot to adjust that, expand phase will adjust that
> but it little too late to some gimple optimization, which rely on certain
> target hooks need to check alignment, forwprop is an example for
> that, result of simplify_builtin_call rely on the alignment on some
> target like ARM or RISC-V.
>
> - So we must adjust at some point, and here is already a pass to adjust
> alignment, which is ipa-increase-alignment, used for tree vectorization.
>
> - This patch fix gfortran.dg/pr45636.f90 for arm and riscv.
>
> - Regression test on riscv32/riscv64 and x86_64-linux-gnu, no new fail
> introduced.
>
> gcc/ChangeLog
>
> PR target/90811
> * ipa-increase-alignment.cc (increase_alignment_local_var): New.
> (increase_alignment_global_var): New.
> (pass_ipa_increase_alignment::gate): Remove.
> ---
> gcc/ipa-increase-alignment.cc | 45 ++++++++++++++++++++++++++++-------
> 1 file changed, 36 insertions(+), 9 deletions(-)
>
> diff --git a/gcc/ipa-increase-alignment.cc b/gcc/ipa-increase-alignment.cc
> index 6e34124bc03..8f28ad83349 100644
> --- a/gcc/ipa-increase-alignment.cc
> +++ b/gcc/ipa-increase-alignment.cc
> @@ -148,10 +148,35 @@ get_vec_alignment_for_type (tree type)
> return (alignment > TYPE_ALIGN (type)) ? alignment : 0;
> }
>
> -/* Entry point to increase_alignment pass. */
> -static unsigned int
> -increase_alignment (void)
> +/* Adjust alignment for local variable. */
> +static void
> +increase_alignment_local_var (void)
> +{
> + size_t i;
> + tree var;
> + struct cgraph_node *node;
> + unsigned int align;
> +
> + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
> + {
> + function *fun = node->get_fun ();
> + FOR_EACH_LOCAL_DECL (fun, i, var)
> + {
> + align = LOCAL_DECL_ALIGNMENT (var);
> +
> + SET_DECL_ALIGN (var, align);
I think this is wrong if the user has set the alignment already.
You need to check DECL_USER_ALIGN.
Thanks,
Andrew Pinski
> + }
> + }
> +}
> +
> +/* Adjust alignment for global variable, only used for tree vectorization
> + currently. */
> +static void
> +increase_alignment_global_var (void)
> {
> + if (!(flag_section_anchors && flag_tree_loop_vectorize))
> + return;
> +
> varpool_node *vnode;
>
> vect_location = dump_user_location_t ();
> @@ -178,6 +203,14 @@ increase_alignment (void)
> }
>
> delete type_align_map;
> +}
> +
> +/* Entry point to increase_alignment pass. */
> +static unsigned int
> +increase_alignment (void)
> +{
> + increase_alignment_local_var ();
> + increase_alignment_global_var ();
> return 0;
> }
>
> @@ -204,12 +237,6 @@ public:
> : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt)
> {}
>
> - /* opt_pass methods: */
> - virtual bool gate (function *)
> - {
> - return flag_section_anchors && flag_tree_loop_vectorize;
> - }
> -
> virtual unsigned int execute (function *) { return increase_alignment (); }
>
> }; // class pass_ipa_increase_alignment
> --
> 2.25.2
>