]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
match.pd: Check trunc_mod vector obtap before folding.
authorJennifer Schmitz <jschmitz@nvidia.com>
Thu, 3 Oct 2024 11:46:51 +0000 (04:46 -0700)
committerJennifer Schmitz <jschmitz@nvidia.com>
Thu, 10 Oct 2024 08:31:01 +0000 (10:31 +0200)
This patch guards the simplification x / y * y == x -> x % y == 0 in
match.pd by a check for:
1) Non-vector mode of x OR
2) Lack of support for vector division OR
3) Support of vector modulo

The patch was bootstrapped and tested with no regression on
aarch64-linux-gnu and x86_64-linux-gnu.
OK for mainline?

Signed-off-by: Jennifer Schmitz <jschmitz@nvidia.com>
gcc/
PR tree-optimization/116831
* match.pd: Guard simplification to trunc_mod with check for
mod optab support.

gcc/testsuite/
PR tree-optimization/116831
* gcc.dg/torture/pr116831.c: New test.

gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr116831.c [new file with mode: 0644]

index 755ed13e77d11d3a045e6a0a92da14ca03509e55..8a7569ce38712343920ecca557ef9cb6a4a10611 100644 (file)
@@ -5415,8 +5415,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* x / y * y == x -> x % y == 0.  */
 (simplify
   (eq:c (mult:c (trunc_div:s @0 @1) @1) @0)
-  (if (TREE_CODE (TREE_TYPE (@0)) != COMPLEX_TYPE)
-    (eq (trunc_mod @0 @1) { build_zero_cst (TREE_TYPE (@0)); })))
+  (if (TREE_CODE (TREE_TYPE (@0)) != COMPLEX_TYPE
+       && (!VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (@0)))
+          || !target_supports_op_p (TREE_TYPE (@0), TRUNC_DIV_EXPR,
+                                    optab_vector)
+          || target_supports_op_p (TREE_TYPE (@0), TRUNC_MOD_EXPR,
+                                   optab_vector)))
+   (eq (trunc_mod @0 @1) { build_zero_cst (TREE_TYPE (@0)); })))
 
 /* ((X /[ex] A) +- B) * A  -->  X +- A * B.  */
 (for op (plus minus)
diff --git a/gcc/testsuite/gcc.dg/torture/pr116831.c b/gcc/testsuite/gcc.dg/torture/pr116831.c
new file mode 100644 (file)
index 0000000..92b2a13
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-additional-options "-mcpu=neoverse-v2" { target aarch64*-*-* } } */
+
+long a;
+int b, c;
+void d (int e[][5], short f[][5][5][5]) 
+{
+  for (short g; g; g += 4)
+    a = c ?: e[6][0] % b ? 0 : f[0][0][0][g];
+}
+