On Tue, Jul 24, 2018 at 11:55 AM Richard Sandiford
wrote:
>
> This patch adds a vec_info helper for checking whether an operand is an
> SSA_NAME that is defined in the vectorisable region.
OK.
>
> 2018-07-24 Richard Sandiford
>
> gcc/
> * tree-vectorizer.h (vec_info::lookup_def): Declare.
> * tree-vectorizer.c (vec_info::lookup_def): New function.
> * tree-vect-patterns.c (vect_get_internal_def): Use it.
> (vect_widened_op_tree): Likewise.
> * tree-vect-stmts.c (vect_is_simple_use): Likewise.
> * tree-vect-loop.c (vect_analyze_loop_operations): Likewise.
> (vectorizable_reduction): Likewise.
> (vect_valid_reduction_input_p): Take a stmt_vec_info instead
> of a gimple *.
> (vect_is_slp_reduction): Update calls accordingly. Use
> vec_info::lookup_def.
> (vect_is_simple_reduction): Likewise
> * tree-vect-slp.c (vect_detect_hybrid_slp_1): Use
> vec_info::lookup_def.
>
> Index: gcc/tree-vectorizer.h
> ===
> --- gcc/tree-vectorizer.h 2018-07-24 10:22:23.797367688 +0100
> +++ gcc/tree-vectorizer.h 2018-07-24 10:22:27.285336715 +0100
> @@ -219,6 +219,7 @@ struct vec_info {
>
>stmt_vec_info add_stmt (gimple *);
>stmt_vec_info lookup_stmt (gimple *);
> + stmt_vec_info lookup_def (tree);
>
>/* The type of vectorization. */
>vec_kind kind;
> Index: gcc/tree-vectorizer.c
> ===
> --- gcc/tree-vectorizer.c 2018-07-24 10:22:23.797367688 +0100
> +++ gcc/tree-vectorizer.c 2018-07-24 10:22:27.285336715 +0100
> @@ -535,6 +535,19 @@ vec_info::lookup_stmt (gimple *stmt)
>return NULL;
> }
>
> +/* If NAME is an SSA_NAME and its definition has an associated stmt_vec_info,
> + return that stmt_vec_info, otherwise return null. It is safe to call
> + this on arbitrary operands. */
> +
> +stmt_vec_info
> +vec_info::lookup_def (tree name)
> +{
> + if (TREE_CODE (name) == SSA_NAME
> + && !SSA_NAME_IS_DEFAULT_DEF (name))
> +return lookup_stmt (SSA_NAME_DEF_STMT (name));
> + return NULL;
> +}
> +
> /* A helper function to free scev and LOOP niter information, as well as
> clear loop constraint LOOP_C_FINITE. */
>
> Index: gcc/tree-vect-patterns.c
> ===
> --- gcc/tree-vect-patterns.c2018-07-24 10:22:23.793367723 +0100
> +++ gcc/tree-vect-patterns.c2018-07-24 10:22:27.281336751 +0100
> @@ -227,14 +227,11 @@ vect_element_precision (unsigned int pre
> static stmt_vec_info
> vect_get_internal_def (vec_info *vinfo, tree op)
> {
> - vect_def_type dt;
> - gimple *def_stmt;
> - if (TREE_CODE (op) != SSA_NAME
> - || !vect_is_simple_use (op, vinfo, , _stmt)
> - || dt != vect_internal_def)
> -return NULL;
> -
> - return vinfo_for_stmt (def_stmt);
> + stmt_vec_info def_stmt_info = vinfo->lookup_def (op);
> + if (def_stmt_info
> + && STMT_VINFO_DEF_TYPE (def_stmt_info) == vect_internal_def)
> +return def_stmt_info;
> + return NULL;
> }
>
> /* Check whether NAME, an ssa-name used in USE_STMT,
> @@ -528,6 +525,7 @@ vect_widened_op_tree (stmt_vec_info stmt
> vect_unpromoted_value *unprom, tree *common_type)
> {
>/* Check for an integer operation with the right code. */
> + vec_info *vinfo = stmt_info->vinfo;
>gassign *assign = dyn_cast (stmt_info->stmt);
>if (!assign)
> return 0;
> @@ -584,7 +582,7 @@ vect_widened_op_tree (stmt_vec_info stmt
>
> /* Recursively process the definition of the operand. */
> stmt_vec_info def_stmt_info
> - = vinfo_for_stmt (SSA_NAME_DEF_STMT (this_unprom->op));
> + = vinfo->lookup_def (this_unprom->op);
> nops = vect_widened_op_tree (def_stmt_info, code, widened_code,
>shift_p, max_nops, this_unprom,
>common_type);
> Index: gcc/tree-vect-stmts.c
> ===
> --- gcc/tree-vect-stmts.c 2018-07-24 10:22:23.797367688 +0100
> +++ gcc/tree-vect-stmts.c 2018-07-24 10:22:27.281336751 +0100
> @@ -10092,11 +10092,11 @@ vect_is_simple_use (tree operand, vec_in
>else
> {
>gimple *def_stmt = SSA_NAME_DEF_STMT (operand);
> - if (! vect_stmt_in_region_p (vinfo, def_stmt))
> + stmt_vec_info stmt_vinfo = vinfo->lookup_def (operand);
> + if (!stmt_vinfo)
> *dt = vect_external_def;
>else
> {
> - stmt_vec_info stmt_vinfo = vinfo_for_stmt (def_stmt);
> if (STMT_VINFO_IN_PATTERN_P (stmt_vinfo))
> {
> def_stmt = STMT_VINFO_RELATED_STMT (stmt_vinfo);
> Index: gcc/tree-vect-loop.c
> ===
> --- gcc/tree-vect-loop.c