]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/122158 - vector reduction epilog for bit-precision result
authorRichard Biener <rguenther@suse.de>
Mon, 6 Oct 2025 07:06:45 +0000 (09:06 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 6 Oct 2025 08:32:27 +0000 (10:32 +0200)
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.

gcc/testsuite/gcc.dg/vect/pr122158.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/vect/pr122158.c b/gcc/testsuite/gcc.dg/vect/pr122158.c
new file mode 100644 (file)
index 0000000..5d0f7da
--- /dev/null
@@ -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);
+}
index df45adbe035d9fa1e2db6f75996b02bfe07fafd3..73398e58fdc9d34aba761016ed9d2544735da4f8 100644 (file)
@@ -6049,8 +6049,6 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
                   Create:  va = vop <va, va'>
                 }  */
 
-          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 <v_out2, bitpos>  */
@@ -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