Richard Biener <rguent...@suse.de> writes: > On Fri, 8 Nov 2019, Richard Sandiford wrote: > >> Richard Biener <rguent...@suse.de> writes: >> > I've been sitting on this for a few days since I'm not 100% happy >> > with how the code looks like. There's possibly still holes in it >> > (chains with mixed signed/unsigned adds for example might pick >> > up signed adds in the epilogue), but the wrong-code cases should >> > work fine now. I'm probably going to followup with some >> > mass renaming of variable/parameter names to make it more clear >> > which stmt / type we are actually looking at ... >> > >> > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. >> >> Does this look like the right way of updating neutral_op_for_slp_reduction? >> It now needs to know whether the caller is using STMT_VINFO_REDUC_VECTYPE >> (for an epilogue value) or STMT_VINFO_REDUC_VECTYPE_IN (for a PHI argument). >> >> Fixes various gcc.target/aarch64/sve/slp_* tests, will give it a >> full test on aarch64-linux-gnu. > > Yeah, it looks sensible. In vect_create_epilog_for_reduction > please move the call down to the only use in the > > else if (direct_slp_reduc) > { > > block.
Thanks, here's what I installed after testing on aarch64-linux-gnu and x86_64-linux-gnu. Richard 2019-11-08 Richard Sandiford <richard.sandif...@arm.com> gcc/ * tree-vect-loop.c (neutral_op_for_slp_reduction): Take the vector type as an argument rather than reading it from the stmt_vec_info. (vect_create_epilog_for_reduction): Update accordingly. (vectorizable_reduction): Likewise. (vect_transform_cycle_phi): Likewise. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2019-11-08 11:58:22.331095690 +0000 +++ gcc/tree-vect-loop.c 2019-11-08 16:06:11.389032120 +0000 @@ -2590,17 +2590,17 @@ reduction_fn_for_scalar_code (enum tree_ /* If there is a neutral value X such that SLP reduction NODE would not be affected by the introduction of additional X elements, return that X, - otherwise return null. CODE is the code of the reduction. REDUC_CHAIN - is true if the SLP statements perform a single reduction, false if each - statement performs an independent reduction. */ + otherwise return null. CODE is the code of the reduction and VECTOR_TYPE + is the vector type that would hold element X. REDUC_CHAIN is true if + the SLP statements perform a single reduction, false if each statement + performs an independent reduction. */ static tree -neutral_op_for_slp_reduction (slp_tree slp_node, tree_code code, - bool reduc_chain) +neutral_op_for_slp_reduction (slp_tree slp_node, tree vector_type, + tree_code code, bool reduc_chain) { vec<stmt_vec_info> stmts = SLP_TREE_SCALAR_STMTS (slp_node); stmt_vec_info stmt_vinfo = stmts[0]; - tree vector_type = STMT_VINFO_VECTYPE (stmt_vinfo); tree scalar_type = TREE_TYPE (vector_type); class loop *loop = gimple_bb (stmt_vinfo->stmt)->loop_father; gcc_assert (loop); @@ -4220,11 +4220,6 @@ vect_create_epilog_for_reduction (stmt_v = as_a <gphi *> (STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info))->stmt); enum tree_code code = STMT_VINFO_REDUC_CODE (reduc_info); internal_fn reduc_fn = STMT_VINFO_REDUC_FN (reduc_info); - tree neutral_op = NULL_TREE; - if (slp_node) - neutral_op - = neutral_op_for_slp_reduction (slp_node_instance->reduc_phis, code, - REDUC_GROUP_FIRST_ELEMENT (stmt_info)); stmt_vec_info prev_phi_info; tree vectype; machine_mode mode; @@ -4822,6 +4817,14 @@ vect_create_epilog_for_reduction (stmt_v scalar value if we have one, otherwise the initial scalar value is itself a neutral value. */ tree vector_identity = NULL_TREE; + tree neutral_op = NULL_TREE; + if (slp_node) + { + stmt_vec_info first = REDUC_GROUP_FIRST_ELEMENT (stmt_info); + neutral_op + = neutral_op_for_slp_reduction (slp_node_instance->reduc_phis, + vectype, code, first != NULL); + } if (neutral_op) vector_identity = gimple_build_vector_from_val (&seq, vectype, neutral_op); @@ -6214,7 +6217,7 @@ vectorizable_reduction (stmt_vec_info st tree neutral_op = NULL_TREE; if (slp_node) neutral_op = neutral_op_for_slp_reduction - (slp_node_instance->reduc_phis, orig_code, + (slp_node_instance->reduc_phis, vectype_out, orig_code, REDUC_GROUP_FIRST_ELEMENT (stmt_info) != NULL); if (double_reduc && reduction_type == FOLD_LEFT_REDUCTION) @@ -6797,7 +6800,7 @@ vect_transform_cycle_phi (stmt_vec_info gcc_assert (slp_node == slp_node_instance->reduc_phis); stmt_vec_info first = REDUC_GROUP_FIRST_ELEMENT (reduc_stmt_info); tree neutral_op - = neutral_op_for_slp_reduction (slp_node, + = neutral_op_for_slp_reduction (slp_node, vectype_out, STMT_VINFO_REDUC_CODE (reduc_info), first != NULL); get_initial_defs_for_reduction (slp_node_instance->reduc_phis,