From: Richard Biener Date: Mon, 6 Oct 2025 07:06:45 +0000 (+0200) Subject: tree-optimization/122158 - vector reduction epilog for bit-precision result X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f1cd723c52deca6ea9aaa8c2b54e6c5b6478008;p=thirdparty%2Fgcc.git tree-optimization/122158 - vector reduction epilog for bit-precision result The following makes sure to perform the vector element extraction using the element type and convert to the original, possibly bit-precision, result afterwards. I've also used gimple_build for the BIT_FIELD_REF since that simplifies the code. PR tree-optimization/122158 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Handle bit-precision result. * gcc.dg/vect/pr122158.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/vect/pr122158.c b/gcc/testsuite/gcc.dg/vect/pr122158.c new file mode 100644 index 00000000000..5d0f7dac7dc --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr122158.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +int g_3, g_181, g_7; +void func_54(unsigned int, int *); +int func_24() +{ + int p_25; + int *l_49 = &g_3; + func_54(g_7, l_49); +} +void func_54(unsigned int p_55, int *p_56) +{ + for (g_181 = 27; g_181 != 9; --g_181) + p_55 || (*p_56 = 0); +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index df45adbe035..73398e58fdc 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -6049,8 +6049,6 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, Create: va = vop } */ - tree rhs; - if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "Reduce using vector shifts\n"); @@ -6069,7 +6067,6 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, new_temp = gimple_build (&stmts, code, vectype1, new_name, new_temp); } - gsi_insert_seq_before (&exit_gsi, stmts, GSI_SAME_STMT); /* 2.4 Extract the final scalar result. Create: s_out3 = extract_field */ @@ -6078,12 +6075,11 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, dump_printf_loc (MSG_NOTE, vect_location, "extract scalar result\n"); - rhs = build3 (BIT_FIELD_REF, scalar_type, new_temp, - bitsize, bitsize_zero_node); - epilog_stmt = gimple_build_assign (new_scalar_dest, rhs); - new_temp = make_ssa_name (new_scalar_dest, epilog_stmt); - gimple_assign_set_lhs (epilog_stmt, new_temp); - gsi_insert_before (&exit_gsi, epilog_stmt, GSI_SAME_STMT); + new_temp = gimple_build (&stmts, BIT_FIELD_REF, TREE_TYPE (vectype1), + new_temp, bitsize, bitsize_zero_node); + new_temp = gimple_build (&stmts, VIEW_CONVERT_EXPR, + scalar_type, new_temp); + gsi_insert_seq_before (&exit_gsi, stmts, GSI_SAME_STMT); scalar_results.safe_push (new_temp); } else