The a % b -> a - a / b pattern breaks reduction constraints, disable it
for reduction stmts.
PR tree-optimization/121767
* tree-vect-patterns.cc (vect_recog_mod_var_pattern): Disable
for reductions.
* gcc.dg/vect/pr121767.c: New testcase.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-mcpu=neoverse-v2" { target aarch64-*-* } } */
+
+int foo (int x, int y, int n)
+{
+ for (int i = 0; i < n; ++i)
+ x = x % y;
+ return x;
+}
gimple *pattern_stmt, *def_stmt;
enum tree_code rhs_code;
- if (!is_gimple_assign (last_stmt))
+ if (!is_gimple_assign (last_stmt) || vect_is_reduction (stmt_vinfo))
return NULL;
rhs_code = gimple_assign_rhs_code (last_stmt);