aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJennifer Schmitz <jschmitz@nvidia.com>2024-10-03 04:46:51 -0700
committerJennifer Schmitz <jschmitz@nvidia.com>2024-10-10 10:31:01 +0200
commita2e06b7f081a3d2e50e3afa8d3f1676a05099707 (patch)
tree59ffe18724ec525cb37dd113f2d4ef463c3ec6d3 /gcc
parentbcccc3221b838ee7ae7848e7194603acb18294b3 (diff)
downloadgcc-a2e06b7f081a3d2e50e3afa8d3f1676a05099707.zip
gcc-a2e06b7f081a3d2e50e3afa8d3f1676a05099707.tar.gz
gcc-a2e06b7f081a3d2e50e3afa8d3f1676a05099707.tar.bz2
match.pd: Check trunc_mod vector obtap before folding.
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd9
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr116831.c10
2 files changed, 17 insertions, 2 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 755ed13..8a7569c 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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
index 0000000..92b2a13
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116831.c
@@ -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];
+}
+