Instead of going via the PHI node def, use the scalar reduction
input from the reduction stmt.

Bootstrapped and tested on x86_64-unknown-linux-gnu.  I'll wait
for risc-v CI and hope for aarch64 CI as well ...

Thanks,
Richard.

        * tree-vect-loop.cc (vectorize_fold_left_reduction): Get
        reduc_var as argument.
        (vect_transform_reduction): Adjust.
---
 gcc/tree-vect-loop.cc | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index e367bd6e683..65710035d51 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6486,7 +6486,7 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo,
                               stmt_vec_info stmt_info,
                               gimple_stmt_iterator *gsi,
                               slp_tree slp_node,
-                              gimple *reduc_def_stmt,
+                              tree reduc_var,
                               code_helper code, internal_fn reduc_fn,
                               int num_ops, tree vectype_in,
                               int reduc_index, vec_loop_masks *masks,
@@ -6531,7 +6531,6 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo,
   gimple *sdef = vect_orig_stmt (scalar_dest_def_info)->stmt;
   tree scalar_dest = gimple_get_lhs (sdef);
   tree scalar_type = TREE_TYPE (scalar_dest);
-  tree reduc_var = gimple_phi_result (reduc_def_stmt);
 
   int vec_num = vec_oprnds0.length ();
   tree vec_elem_type = TREE_TYPE (vectype_out);
@@ -8000,8 +7999,6 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
      The last use is the reduction variable.  In case of nested cycle this
      assumption is not true: we use reduc_index to record the index of the
      reduction variable.  */
-  stmt_vec_info phi_info = STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info));
-  gphi *reduc_def_phi = as_a <gphi *> (phi_info->stmt);
   int reduc_index = STMT_VINFO_REDUC_IDX (stmt_info);
   tree vectype_in = SLP_TREE_VECTYPE (SLP_TREE_CHILDREN (slp_node)[0]);
 
@@ -8043,8 +8040,9 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
     {
       internal_fn reduc_fn = VECT_REDUC_INFO_FN (reduc_info);
       gcc_assert (code.is_tree_code () || cond_fn_p);
+      tree reduc_var = op.ops[reduc_index];
       return vectorize_fold_left_reduction
-         (loop_vinfo, stmt_info, gsi, slp_node, reduc_def_phi,
+         (loop_vinfo, stmt_info, gsi, slp_node, reduc_var,
           code, reduc_fn, op.num_ops, vectype_in,
           reduc_index, masks, lens);
     }
-- 
2.43.0

Reply via email to