* [PATCH] fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225]
@ 2021-02-24 10:12 Jakub Jelinek
2021-02-24 10:50 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2021-02-24 10:12 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
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.
--- gcc/fold-const.c.jj 2021-02-23 09:49:40.000000000 +0100
+++ gcc/fold-const.c 2021-02-23 19:53:33.143763292 +0100
@@ -12044,23 +12044,23 @@ fold_binary_loc (location_t loc, enum tr
&& 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);
}
}
--- gcc/testsuite/gcc.c-torture/compile/pr99225.c.jj 2021-02-23 20:12:01.825464969 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr99225.c 2021-02-23 20:11:45.962640464 +0100
@@ -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;
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225]
2021-02-24 10:12 [PATCH] fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225] Jakub Jelinek
@ 2021-02-24 10:50 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-02-24 10:50 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Wed, 24 Feb 2021, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
Richard.
> 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.
>
> --- gcc/fold-const.c.jj 2021-02-23 09:49:40.000000000 +0100
> +++ gcc/fold-const.c 2021-02-23 19:53:33.143763292 +0100
> @@ -12044,23 +12044,23 @@ fold_binary_loc (location_t loc, enum tr
> && 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);
> }
> }
>
> --- gcc/testsuite/gcc.c-torture/compile/pr99225.c.jj 2021-02-23 20:12:01.825464969 +0100
> +++ gcc/testsuite/gcc.c-torture/compile/pr99225.c 2021-02-23 20:11:45.962640464 +0100
> @@ -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;
> +}
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-24 10:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 10:12 [PATCH] fold-const: Fix up ((1 << x) & y) != 0 folding for vectors [PR99225] Jakub Jelinek
2021-02-24 10:50 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).