After we introduced additional induction kinds we failed to make sure
integer cond reductions are unaffected.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/127600
* tree-vect-loop.cc (vect_is_simple_iv_evolution): Explicitly
initialize STMT_VINFO_LOOP_PHI_EVOLUTION_TYPE.
(is_nonwrapping_integer_induction): Bail out for alternate
induction types.
* gcc.dg/vect/vect-cond-reduc-7.c: New testcase.
---
gcc/testsuite/gcc.dg/vect/vect-cond-reduc-7.c | 45 +++++++++++++++++++
gcc/tree-vect-loop.cc | 7 ++-
2 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-cond-reduc-7.c
diff --git a/gcc/testsuite/gcc.dg/vect/vect-cond-reduc-7.c
b/gcc/testsuite/gcc.dg/vect/vect-cond-reduc-7.c
new file mode 100644
index 00000000000..abaa3693aff
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-cond-reduc-7.c
@@ -0,0 +1,45 @@
+/* PR1276000 */
+
+#include "tree-vect.h"
+
+extern void abort (void) __attribute__ ((noreturn));
+
+int __attribute__((noipa))
+f (int *a, int n)
+{
+ int last = -99;
+ int j = 1;
+ for (int i = 0; i < n; i++)
+ {
+ if (a[i])
+ last = j;
+ j = -j;
+ }
+ return last;
+}
+
+int
+main (void)
+{
+ check_vect ();
+
+ int a[16] = { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ if (f (a, 16) != 1)
+ abort ();
+
+ int b[16] = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ if (f (b, 16) != -1)
+ abort ();
+
+ int c[16] = { 0 };
+ if (f (c, 16) != -99)
+ abort ();
+
+ int d[16] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ if (f (d, 16) != 1)
+ abort ();
+
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "condition expression based on integer
induction." "vect" } } */
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c010d664870..8cd1e75c263 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -199,6 +199,7 @@ vect_is_simple_iv_evolution (unsigned loop_nb, tree
access_fn,
STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED (stmt_info) = init_expr;
STMT_VINFO_LOOP_PHI_EVOLUTION_PART (stmt_info) = step_expr;
+ STMT_VINFO_LOOP_PHI_EVOLUTION_TYPE (stmt_info) = vect_step_op_add;
if (TREE_CODE (step_expr) != INTEGER_CST
&& (TREE_CODE (step_expr) != SSA_NAME
@@ -6597,7 +6598,7 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo,
/* Function is_nonwrapping_integer_induction.
- Check if STMT_VINO (which is part of loop LOOP) both increments and
+ Check if STMT_VINFO (which is part of loop LOOP) both increments and
does not cause overflow. */
static bool
@@ -6610,6 +6611,10 @@ is_nonwrapping_integer_induction (stmt_vec_info
stmt_vinfo, class loop *loop)
widest_int ni, max_loop_value, lhs_max;
wi::overflow_type overflow = wi::OVF_NONE;
+ /* Make sure this is a regular induction. */
+ if (STMT_VINFO_LOOP_PHI_EVOLUTION_TYPE (stmt_vinfo) != vect_step_op_add)
+ return false;
+
/* Make sure the loop is integer based. */
if (TREE_CODE (base) != INTEGER_CST
|| TREE_CODE (step) != INTEGER_CST)
--
2.51.0