[gcc r15-7802] tree-optimization/119096 - bogus conditional reduction vectorization
Richard Biener
rguenth@gcc.gnu.org
Tue Mar 4 08:24:54 GMT 2025
https://gcc.gnu.org/g:10e4107dfcf9fe324d0902f16411a75c596dab91
commit r15-7802-g10e4107dfcf9fe324d0902f16411a75c596dab91
Author: Richard Biener <rguenther@suse.de>
Date: Mon Mar 3 14:12:37 2025 +0100
tree-optimization/119096 - bogus conditional reduction vectorization
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.
Diff:
---
gcc/testsuite/gcc.dg/vect/pr119096.c | 21 +++++++++++++++++++++
gcc/tree-vect-loop.cc | 2 +-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/gcc/testsuite/gcc.dg/vect/pr119096.c b/gcc/testsuite/gcc.dg/vect/pr119096.c
new file mode 100644
index 000000000000..2c03a5936831
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr119096.c
@@ -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;
+}
+
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index dc15b955aadf..52533623cab9 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -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]);
More information about the Gcc-cvs
mailing list