This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Avoid versioning the vectorized loop if possible



Richard Guenther <rguenther@suse.de> wrote on 31/03/2009 18:48:06:

>
> This is part #1 of the merge of versioning for strides.  It eliminates
> the need to produce a versioned copy in some cases when we can just use
> the loop for the remaining iterations.
>

This patch also allows us to easily support peeling for alignment together
with loop versioning in case we also do peeling for loop bound.

> Bootstrapped and tested on x86_64-unknown-linux-gnu.  Ira, does this
> look ok?

Yes, just please see two minor comments below.

Thanks,
Ira

>
> Thanks,
> Richard.
>
> 2009-03-31  Richard Guenther  <rguenther@suse.de>
>
>    * Makefile.in (tree-ssa-copy.o): Add $(CFGLOOP_H) dependency.
>    * tree-ssa-copy.c (init_copy_prop): Do not propagate through
>    single-argument PHIs if we are in loop-closed SSA form.
>    * tree-vect-loop-manip.c (slpeel_add_loop_guard): Pass extra guards
>    for the pre-condition.
>    (slpeel_tree_peel_loop_to_edge): Likewise.
>    (vect_build_loop_niters): Take an optional sequence to append stmts.
>    (vect_generate_tmps_on_preheader): Likewise.
>    (vect_do_peeling_for_loop_bound): Take extra guards for the
>    pre-condition.
>    (vect_do_peeling_for_alignment): Adjust.
>    (vect_loop_versioning): Take stmt and stmt list to put pre-condition
>    guards if we are going to peel.  Do not apply versioning in that
>    case.
>    * tree-vectorizer.h (vect_loop_versioning): Adjust declaration.
>    (vect_do_peeling_for_loop_bound): Likewise.
>    * tree-vect-loop.c (vect_transform_loop): If we are peeling for
>    loop bound only record extra pre-conditions, do not apply loop
>    versioning.
>
> Index: trunk/gcc/tree-vect-loop-manip.c
> ===================================================================
> *** trunk.orig/gcc/tree-vect-loop-manip.c   2009-03-31 16:26:46.
> 000000000 +0200
> --- trunk/gcc/tree-vect-loop-manip.c   2009-03-31 17:32:58.000000000
+0200

...

> *************** slpeel_tree_peel_loop_to_edge (struct lo
> *** 1193,1198 ****
> --- 1201,1214 ----
>        pre_condition = fold_build2 (TRUTH_OR_EXPR, boolean_type_node,
>                      cost_pre_condition, pre_condition);
>      }
> +       if (cond_expr)
> +    {
> +      pre_condition =
> +        fold_build2 (TRUTH_OR_EXPR, boolean_type_node,
> +           pre_condition,
> +           fold_build1 (TRUTH_NOT_EXPR, boolean_type_node,
> +                   cond_expr));
> +    }
>       }
>
>     /* Prologue peeling.  */

There is a detailed comment before this code describing that we can skip
the vector loop because of the cost model reasons (paragraph 2.c). Could
you please update it with the versioning reason?

...

> *************** vect_loop_versioning (loop_vec_info loop
> *** 2301,2329 ****
>     th = conservative_cost_threshold (loop_vinfo,
>                   min_profitable_iters);
>
> !   cond_expr =
>       fold_build2 (GT_EXPR, boolean_type_node, scalar_loop_iters,
>                build_int_cst (TREE_TYPE (scalar_loop_iters), th));
>
> !   cond_expr = force_gimple_operand (cond_expr, &cond_expr_stmt_list,
> !                 false, NULL_TREE);
>
>     if (VEC_length (gimple, LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo)))
> !       vect_create_cond_for_align_checks (loop_vinfo, &cond_expr,
> !                 &cond_expr_stmt_list);
>
>     if (VEC_length (ddr_p, LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo)))
> !     vect_create_cond_for_alias_checks (loop_vinfo, &cond_expr,
> !                    &cond_expr_stmt_list);
>
> !   cond_expr =
> !     fold_build2 (NE_EXPR, boolean_type_node, cond_expr,
integer_zero_node);
> !   cond_expr =
> !     force_gimple_operand (cond_expr, &gimplify_stmt_list, true,
NULL_TREE);
> !   gimple_seq_add_seq (&cond_expr_stmt_list, gimplify_stmt_list);
>
>     initialize_original_copy_tables ();
> !   nloop = loop_version (loop, cond_expr, &condition_bb,
>            prob, prob, REG_BR_PROB_BASE - prob, true);
>     free_original_copy_tables();
>
> --- 2346,2379 ----
>     th = conservative_cost_threshold (loop_vinfo,
>                   min_profitable_iters);
>
> !   *cond_expr =
>       fold_build2 (GT_EXPR, boolean_type_node, scalar_loop_iters,
>                build_int_cst (TREE_TYPE (scalar_loop_iters), th));

Since you changed the order of peeling for alignment and versioning, we
ideally should check here that the cost model checks were not created
during peeling for alignment (and remove the corresponding check from
vect_do_peeling_for_alignment()). But since we currently don't do peeling
for alignment if we do versioning, could you please just remove the check
in vect_do_peeling_for_alignment(), since it is now redundant for sure.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]