]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121767 - modvar pattern breaking reductions
authorRichard Biener <rguenther@suse.de>
Wed, 3 Sep 2025 09:04:49 +0000 (11:04 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 3 Sep 2025 11:02:35 +0000 (13:02 +0200)
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.

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

diff --git a/gcc/testsuite/gcc.dg/vect/pr121767.c b/gcc/testsuite/gcc.dg/vect/pr121767.c
new file mode 100644 (file)
index 0000000..3b52692
--- /dev/null
@@ -0,0 +1,9 @@
+/* { 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;
+}
index 41ca0f085f0ec89399b997320332e46f0731cc56..f5c97242acb629020e9e83f417d6d170de6b303b 100644 (file)
@@ -5363,7 +5363,7 @@ vect_recog_mod_var_pattern (vec_info *vinfo,
   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);