aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-02-24 12:10:25 +0100
committerJakub Jelinek <jakub@redhat.com>2021-02-24 12:10:25 +0100
commit6e646abbe02f2c79cc3ba1f3de705ee62ff9dcd1 (patch)
tree51ff5a521c3955aa0a26f0666d119010f1e93563
parent5296bd57d0605d1fec900d85e3ab3875197e609a (diff)
downloadgcc-6e646abbe02f2c79cc3ba1f3de705ee62ff9dcd1.zip
gcc-6e646abbe02f2c79cc3ba1f3de705ee62ff9dcd1.tar.gz
gcc-6e646abbe02f2c79cc3ba1f3de705ee62ff9dcd1.tar.bz2
fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225]
This optimization was written purely with scalar integers in mind, can work fine even with vectors, but we can't use build_int_cst but need to use build_one_cst instead. 2021-02-24 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/99225 * fold-const.c (fold_binary_loc) <case NE_EXPR>: In (x & (1 << y)) != 0 to ((x >> y) & 1) != 0 simplifications use build_one_cst instead of build_int_cst (..., 1). Formatting fixes. * gcc.c-torture/compile/pr99225.c: New test.
-rw-r--r--gcc/fold-const.c16
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr99225.c31
2 files changed, 39 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index afc3b7f..e0bdb4b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12044,23 +12044,23 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
&& integer_onep (TREE_OPERAND (arg00, 0)))
{
tree tem = fold_build2_loc (loc, RSHIFT_EXPR, TREE_TYPE (arg00),
- arg01, TREE_OPERAND (arg00, 1));
+ arg01, TREE_OPERAND (arg00, 1));
tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), tem,
- build_int_cst (TREE_TYPE (arg0), 1));
+ build_one_cst (TREE_TYPE (arg0)));
return fold_build2_loc (loc, code, type,
- fold_convert_loc (loc, TREE_TYPE (arg1), tem),
- arg1);
+ fold_convert_loc (loc, TREE_TYPE (arg1),
+ tem), arg1);
}
else if (TREE_CODE (arg01) == LSHIFT_EXPR
&& integer_onep (TREE_OPERAND (arg01, 0)))
{
tree tem = fold_build2_loc (loc, RSHIFT_EXPR, TREE_TYPE (arg01),
- arg00, TREE_OPERAND (arg01, 1));
+ arg00, TREE_OPERAND (arg01, 1));
tem = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (arg0), tem,
- build_int_cst (TREE_TYPE (arg0), 1));
+ build_one_cst (TREE_TYPE (arg0)));
return fold_build2_loc (loc, code, type,
- fold_convert_loc (loc, TREE_TYPE (arg1), tem),
- arg1);
+ fold_convert_loc (loc, TREE_TYPE (arg1),
+ tem), arg1);
}
}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr99225.c b/gcc/testsuite/gcc.c-torture/compile/pr99225.c
new file mode 100644
index 0000000..0ef7602
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr99225.c
@@ -0,0 +1,31 @@
+/* PR tree-optimization/99225 */
+
+typedef int V __attribute__((vector_size (4 * sizeof (int))));
+
+void
+foo (V *x)
+{
+ x[2] = (x[0] & (1 << x[1])) != 0;
+}
+
+void
+bar (V *x)
+{
+ x[2] = ((1 << x[1]) & x[0]) != 0;
+}
+
+void
+baz (V *x)
+{
+ V a = 1 << x[1];
+ V b = a & x[0];
+ x[2] = b != 0;
+}
+
+void
+qux (V *x)
+{
+ V a = 1 << x[1];
+ V b = x[0] & a;
+ x[2] = b != 0;
+}