]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/119096 - bogus conditional reduction vectorization
authorRichard Biener <rguenther@suse.de>
Mon, 3 Mar 2025 13:12:37 +0000 (14:12 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 4 Mar 2025 08:24:31 +0000 (09:24 +0100)
When we vectorize a .COND_ADD reduction and apply the single-use-def
cycle optimization we can end up chosing the wrong else value for
subsequent .COND_ADD.  The following rectifies this.

PR tree-optimization/119096
* tree-vect-loop.cc (vect_transform_reduction): Use the
correct else value for .COND_fn.

* gcc.dg/vect/pr119096.c: New testcase.

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

diff --git a/gcc/testsuite/gcc.dg/vect/pr119096.c b/gcc/testsuite/gcc.dg/vect/pr119096.c
new file mode 100644 (file)
index 0000000..2c03a59
--- /dev/null
@@ -0,0 +1,21 @@
+#include "tree-vect.h"
+
+long __attribute__((noipa))
+sum(int* A, int* B)
+{
+        long total = 0;
+        for(int j = 0; j < 16; j++)
+                if((A[j] > 0) & (B[j] > 0))
+                        total += (long)A[j];
+        return total;
+}
+int main()
+{
+  int A[16] = { 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1 };
+  int B[16] = { };
+  check_vect ();
+  if (sum (A, B) != 0)
+    abort ();
+  return 0;
+}
+
index dc15b955aadf58c0a1e36f8d8d294647d91f1b54..52533623cab93ad47a8ca436961e1b655c1ca7c7 100644 (file)
@@ -9064,7 +9064,7 @@ vect_transform_reduction (loop_vec_info loop_vinfo,
            new_stmt = gimple_build_call_internal (internal_fn (code),
                                                   op.num_ops,
                                                   vop[0], vop[1], vop[2],
-                                                  vop[1]);
+                                                  vop[reduc_index]);
          else
            new_stmt = gimple_build_assign (vec_dest, tree_code (op.code),
                                            vop[0], vop[1], vop[2]);