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.
--- /dev/null
+#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;
+}
+
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]);