]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: Fix vect_reduction_def check for odd/even widen mult [PR116142]
authorXi Ruoyao <xry111@xry111.site>
Tue, 6 Aug 2024 09:48:42 +0000 (17:48 +0800)
committerXi Ruoyao <xry111@xry111.site>
Wed, 7 Aug 2024 07:59:03 +0000 (15:59 +0800)
The check was implemented incorrectly, so vec_widen_smult_{even,odd}_M
was never used.  This is not good for targets with native even/odd
widening multiplication but not lo/hi multiplication.

The fix is actually developed by Richard Biener.

gcc/ChangeLog:

PR tree-optimization/116142
* tree-vect-stmts.cc (supportable_widening_operation): Remove an
redundant and incorrect vect_reduction_def check, and fix the
operand of another vect_reduction_def check.

gcc/testsuite/ChangeLog:

PR tree-optimization/116142
* gcc.target/i386/pr116142.c: New test.

Co-authored-by: Richard Biener <rguenther@suse.de>
gcc/testsuite/gcc.target/i386/pr116142.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.target/i386/pr116142.c b/gcc/testsuite/gcc.target/i386/pr116142.c
new file mode 100644 (file)
index 0000000..d288a50
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump "WIDEN_MULT_EVEN_EXPR" "optimized" } } */
+/* { dg-final { scan-tree-dump "WIDEN_MULT_ODD_EXPR" "optimized" } } */
+
+typedef __INT32_TYPE__ i32;
+typedef __INT64_TYPE__ i64;
+
+i32 x[16], y[16];
+
+i64
+test (void)
+{
+  i64 ret = 0;
+  for (int i = 0; i < 16; i++)
+    ret ^= (i64) x[i] * y[i];
+  return ret;
+}
index 20cae83e8206eaff61a835a549fce088a093f096..385e63163c2450b1cee9f3c2e5df11636116ec2d 100644 (file)
@@ -14179,7 +14179,6 @@ supportable_widening_operation (vec_info *vinfo,
         are properly set up for the caller.  If we fail, we'll continue with
         a VEC_WIDEN_MULT_LO/HI_EXPR check.  */
       if (vect_loop
-         && STMT_VINFO_RELEVANT (stmt_info) == vect_used_by_reduction
          && !nested_in_vect_loop_p (vect_loop, stmt_info)
          && supportable_widening_operation (vinfo, VEC_WIDEN_MULT_EVEN_EXPR,
                                             stmt_info, vectype_out,
@@ -14192,7 +14191,7 @@ supportable_widening_operation (vec_info *vinfo,
              same operation.  One such an example is s += a * b, where elements
              in a and b cannot be reordered.  Here we check if the vector defined
              by STMT is only directly used in the reduction statement.  */
-         tree lhs = gimple_assign_lhs (stmt_info->stmt);
+         tree lhs = gimple_assign_lhs (vect_orig_stmt (stmt_info)->stmt);
          stmt_vec_info use_stmt_info = loop_info->lookup_single_use (lhs);
          if (use_stmt_info
              && STMT_VINFO_DEF_TYPE (use_stmt_info) == vect_reduction_def)