On Sun, Jun 16, 2024 at 9:27 AM Feng Xue OS <[email protected]> wrote:
>
> It's better to place 3 relevant independent variables into array, since we
> have requirement to access them via an index in the following patch. At the
> same time, this change may get some duplicated code be more compact.
OK. I might have caused a conflict for this patch, so even OK after conflict
resolution.
Thanks,
Richard.
> Thanks,
> Feng
>
> ---
> gcc/
> * tree-vect-loop.cc (vect_transform_reduction): Replace
> vec_oprnds0/1/2
> with one new array variable vec_oprnds[3].
> ---
> gcc/tree-vect-loop.cc | 42 +++++++++++++++++-------------------------
> 1 file changed, 17 insertions(+), 25 deletions(-)
>
> diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
> index 39aa5cb1197..7909d63d4df 100644
> --- a/gcc/tree-vect-loop.cc
> +++ b/gcc/tree-vect-loop.cc
> @@ -8605,9 +8605,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
>
> /* Transform. */
> tree new_temp = NULL_TREE;
> - auto_vec<tree> vec_oprnds0;
> - auto_vec<tree> vec_oprnds1;
> - auto_vec<tree> vec_oprnds2;
> + auto_vec<tree> vec_oprnds[3];
>
> if (dump_enabled_p ())
> dump_printf_loc (MSG_NOTE, vect_location, "transform reduction.\n");
> @@ -8657,12 +8655,12 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
> {
> vect_get_vec_defs (loop_vinfo, stmt_info, slp_node, ncopies,
> single_defuse_cycle && reduc_index == 0
> - ? NULL_TREE : op.ops[0], &vec_oprnds0,
> + ? NULL_TREE : op.ops[0], &vec_oprnds[0],
> single_defuse_cycle && reduc_index == 1
> - ? NULL_TREE : op.ops[1], &vec_oprnds1,
> + ? NULL_TREE : op.ops[1], &vec_oprnds[1],
> op.num_ops == 3
> && !(single_defuse_cycle && reduc_index == 2)
> - ? op.ops[2] : NULL_TREE, &vec_oprnds2);
> + ? op.ops[2] : NULL_TREE, &vec_oprnds[2]);
> }
> else
> {
> @@ -8670,12 +8668,12 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
> vectype. */
> gcc_assert (single_defuse_cycle
> && (reduc_index == 1 || reduc_index == 2));
> - vect_get_vec_defs (loop_vinfo, stmt_info, slp_node, ncopies,
> - op.ops[0], truth_type_for (vectype_in), &vec_oprnds0,
> + vect_get_vec_defs (loop_vinfo, stmt_info, slp_node, ncopies, op.ops[0],
> + truth_type_for (vectype_in), &vec_oprnds[0],
> reduc_index == 1 ? NULL_TREE : op.ops[1],
> - NULL_TREE, &vec_oprnds1,
> + NULL_TREE, &vec_oprnds[1],
> reduc_index == 2 ? NULL_TREE : op.ops[2],
> - NULL_TREE, &vec_oprnds2);
> + NULL_TREE, &vec_oprnds[2]);
> }
>
> /* For single def-use cycles get one copy of the vectorized reduction
> @@ -8683,20 +8681,21 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
> if (single_defuse_cycle)
> {
> vect_get_vec_defs (loop_vinfo, stmt_info, slp_node, 1,
> - reduc_index == 0 ? op.ops[0] : NULL_TREE,
> &vec_oprnds0,
> - reduc_index == 1 ? op.ops[1] : NULL_TREE,
> &vec_oprnds1,
> + reduc_index == 0 ? op.ops[0] : NULL_TREE,
> + &vec_oprnds[0],
> + reduc_index == 1 ? op.ops[1] : NULL_TREE,
> + &vec_oprnds[1],
> reduc_index == 2 ? op.ops[2] : NULL_TREE,
> - &vec_oprnds2);
> + &vec_oprnds[2]);
> }
>
> bool emulated_mixed_dot_prod = vect_is_emulated_mixed_dot_prod (stmt_info);
> + unsigned num = vec_oprnds[reduc_index == 0 ? 1 : 0].length ();
>
> - unsigned num = (reduc_index == 0
> - ? vec_oprnds1.length () : vec_oprnds0.length ());
> for (unsigned i = 0; i < num; ++i)
> {
> gimple *new_stmt;
> - tree vop[3] = { vec_oprnds0[i], vec_oprnds1[i], NULL_TREE };
> + tree vop[3] = { vec_oprnds[0][i], vec_oprnds[1][i], NULL_TREE };
> if (masked_loop_p && !mask_by_cond_expr)
> {
> /* No conditional ifns have been defined for dot-product yet. */
> @@ -8721,7 +8720,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
> else
> {
> if (op.num_ops >= 3)
> - vop[2] = vec_oprnds2[i];
> + vop[2] = vec_oprnds[2][i];
>
> if (masked_loop_p && mask_by_cond_expr)
> {
> @@ -8752,14 +8751,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
> }
>
> if (single_defuse_cycle && i < num - 1)
> - {
> - if (reduc_index == 0)
> - vec_oprnds0.safe_push (gimple_get_lhs (new_stmt));
> - else if (reduc_index == 1)
> - vec_oprnds1.safe_push (gimple_get_lhs (new_stmt));
> - else if (reduc_index == 2)
> - vec_oprnds2.safe_push (gimple_get_lhs (new_stmt));
> - }
> + vec_oprnds[reduc_index].safe_push (gimple_get_lhs (new_stmt));
> else if (slp_node)
> slp_node->push_vec_def (new_stmt);
> else
> --
> 2.17.1