aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-01-07 12:17:10 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-01-07 12:17:10 +0000
commitf4bf2aabe36633d75852313caafe7efab71d5ba7 (patch)
tree4b1605d010ed5331fcd70d90790c5ce41dd2f7c2 /gcc/tree.c
parent46c66a46aa33077bda821e0428cc7859945c04c8 (diff)
downloadgcc-f4bf2aabe36633d75852313caafe7efab71d5ba7.zip
gcc-f4bf2aabe36633d75852313caafe7efab71d5ba7.tar.gz
gcc-f4bf2aabe36633d75852313caafe7efab71d5ba7.tar.bz2
[2/2] PR88598: Optimise reduc (bit_and)
This patch folds certain reductions of X & CST to X[I] & CST[I] if I is the only nonzero element of CST. This includes the motivating case in which CST[I] is -1. We could do the same for REDUC_MAX on unsigned types, but I wasn't sure that that special case was worth it. 2019-01-07 Richard Sandiford <richard.sandiford@arm.com> gcc/ PR tree-optimization/88598 * tree.h (single_nonzero_element): Declare. * tree.c (single_nonzero_element): New function. * match.pd: Fold certain reductions of X & CST to X[I] & CST[I] if I is the only nonzero element of CST. gcc/testsuite/ PR tree-optimization/88598 * gcc.dg/vect/pr88598-1.c: New test. * gcc.dg/vect/pr88598-2.c: Likewise. * gcc.dg/vect/pr88598-3.c: Likewise. * gcc.dg/vect/pr88598-4.c: Likewise. * gcc.dg/vect/pr88598-5.c: Likewise. * gcc.dg/vect/pr88598-6.c: Likewise. From-SVN: r267646
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 533694c..f957e4c 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -11340,6 +11340,38 @@ uniform_integer_cst_p (tree t)
return NULL_TREE;
}
+/* If VECTOR_CST T has a single nonzero element, return the index of that
+ element, otherwise return -1. */
+
+int
+single_nonzero_element (const_tree t)
+{
+ unsigned HOST_WIDE_INT nelts;
+ unsigned int repeat_nelts;
+ if (VECTOR_CST_NELTS (t).is_constant (&nelts))
+ repeat_nelts = nelts;
+ else if (VECTOR_CST_NELTS_PER_PATTERN (t) == 2)
+ {
+ nelts = vector_cst_encoded_nelts (t);
+ repeat_nelts = VECTOR_CST_NPATTERNS (t);
+ }
+ else
+ return -1;
+
+ int res = -1;
+ for (unsigned int i = 0; i < nelts; ++i)
+ {
+ tree elt = vector_cst_elt (t, i);
+ if (!integer_zerop (elt) && !real_zerop (elt))
+ {
+ if (res >= 0 || i >= repeat_nelts)
+ return -1;
+ res = i;
+ }
+ }
+ return res;
+}
+
/* Build an empty statement at location LOC. */
tree