* [PATCH] tree-optimization/104595 - vectorization of COND_EXPR with bool load
@ 2022-02-21 15:54 Richard Biener
2022-05-05 6:55 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2022-02-21 15:54 UTC (permalink / raw)
To: gcc-patches
The following fixes an omission in bool pattern detection that
makes it fail when check_bool_pattern fails for COND_EXPR. That's
not what it should do, instead it should still pattern recog
to var != 0 even if no further adjustments to the def chain are
necessary when var is not a mask already.
Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for stage1.
There's another piece of the PR not yet fixed.
2022-02-21 Richard Biener <rguenther@suse.de>
PR tree-optimization/104595
* tree-vect-patterns.c (vect_recog_bool_pattern): For
COND_EXPR do not fail if check_bool_pattern returns false.
* gcc.dg/vect/pr104595.c: New testcase.
---
gcc/testsuite/gcc.dg/vect/pr104595.c | 24 ++++++++++++++++++++++++
gcc/tree-vect-patterns.cc | 16 ++++++++--------
2 files changed, 32 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/pr104595.c
diff --git a/gcc/testsuite/gcc.dg/vect/pr104595.c b/gcc/testsuite/gcc.dg/vect/pr104595.c
new file mode 100644
index 00000000000..bb7d79aa69f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr104595.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_condition } */
+
+#define N 256
+typedef char T;
+extern T a[N];
+extern T b[N];
+extern T c[N];
+extern _Bool pb[N];
+extern char pc[N];
+
+void predicate_by_bool()
+{
+ for (int i = 0; i < N; i++)
+ c[i] = pb[i] ? a[i] : b[i];
+}
+
+void predicate_by_char()
+{
+ for (int i = 0; i < N; i++)
+ c[i] = pc[i] ? a[i] : b[i];
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" } } */
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 217bdfd7045..8c61eb965a6 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -4450,18 +4450,18 @@ vect_recog_bool_pattern (vec_info *vinfo,
if (get_vectype_for_scalar_type (vinfo, type) == NULL_TREE)
return NULL;
- if (!check_bool_pattern (var, vinfo, bool_stmts))
+ if (check_bool_pattern (var, vinfo, bool_stmts))
+ var = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo);
+ else if (integer_type_for_mask (var, vinfo))
return NULL;
- rhs = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo);
-
lhs = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
pattern_stmt
- = gimple_build_assign (lhs, COND_EXPR,
- build2 (NE_EXPR, boolean_type_node,
- rhs, build_int_cst (type, 0)),
- gimple_assign_rhs2 (last_stmt),
- gimple_assign_rhs3 (last_stmt));
+ = gimple_build_assign (lhs, COND_EXPR,
+ build2 (NE_EXPR, boolean_type_node,
+ var, build_int_cst (TREE_TYPE (var), 0)),
+ gimple_assign_rhs2 (last_stmt),
+ gimple_assign_rhs3 (last_stmt));
*type_out = vectype;
vect_pattern_detected ("vect_recog_bool_pattern", last_stmt);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tree-optimization/104595 - vectorization of COND_EXPR with bool load
2022-02-21 15:54 [PATCH] tree-optimization/104595 - vectorization of COND_EXPR with bool load Richard Biener
@ 2022-05-05 6:55 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-05-05 6:55 UTC (permalink / raw)
To: GCC Patches
On Mon, Feb 21, 2022 at 4:54 PM Richard Biener via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> The following fixes an omission in bool pattern detection that
> makes it fail when check_bool_pattern fails for COND_EXPR. That's
> not what it should do, instead it should still pattern recog
> to var != 0 even if no further adjustments to the def chain are
> necessary when var is not a mask already.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for stage1.
>
> There's another piece of the PR not yet fixed.
Re-tested on x86_64-unknown-linux-gnu, about to push if gcc.gnu.org lets me.
Richard.
> 2022-02-21 Richard Biener <rguenther@suse.de>
>
> PR tree-optimization/104595
> * tree-vect-patterns.c (vect_recog_bool_pattern): For
> COND_EXPR do not fail if check_bool_pattern returns false.
>
> * gcc.dg/vect/pr104595.c: New testcase.
> ---
> gcc/testsuite/gcc.dg/vect/pr104595.c | 24 ++++++++++++++++++++++++
> gcc/tree-vect-patterns.cc | 16 ++++++++--------
> 2 files changed, 32 insertions(+), 8 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/vect/pr104595.c
>
> diff --git a/gcc/testsuite/gcc.dg/vect/pr104595.c b/gcc/testsuite/gcc.dg/vect/pr104595.c
> new file mode 100644
> index 00000000000..bb7d79aa69f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/vect/pr104595.c
> @@ -0,0 +1,24 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target vect_condition } */
> +
> +#define N 256
> +typedef char T;
> +extern T a[N];
> +extern T b[N];
> +extern T c[N];
> +extern _Bool pb[N];
> +extern char pc[N];
> +
> +void predicate_by_bool()
> +{
> + for (int i = 0; i < N; i++)
> + c[i] = pb[i] ? a[i] : b[i];
> +}
> +
> +void predicate_by_char()
> +{
> + for (int i = 0; i < N; i++)
> + c[i] = pc[i] ? a[i] : b[i];
> +}
> +
> +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" } } */
> diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
> index 217bdfd7045..8c61eb965a6 100644
> --- a/gcc/tree-vect-patterns.cc
> +++ b/gcc/tree-vect-patterns.cc
> @@ -4450,18 +4450,18 @@ vect_recog_bool_pattern (vec_info *vinfo,
> if (get_vectype_for_scalar_type (vinfo, type) == NULL_TREE)
> return NULL;
>
> - if (!check_bool_pattern (var, vinfo, bool_stmts))
> + if (check_bool_pattern (var, vinfo, bool_stmts))
> + var = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo);
> + else if (integer_type_for_mask (var, vinfo))
> return NULL;
>
> - rhs = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo);
> -
> lhs = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL);
> pattern_stmt
> - = gimple_build_assign (lhs, COND_EXPR,
> - build2 (NE_EXPR, boolean_type_node,
> - rhs, build_int_cst (type, 0)),
> - gimple_assign_rhs2 (last_stmt),
> - gimple_assign_rhs3 (last_stmt));
> + = gimple_build_assign (lhs, COND_EXPR,
> + build2 (NE_EXPR, boolean_type_node,
> + var, build_int_cst (TREE_TYPE (var), 0)),
> + gimple_assign_rhs2 (last_stmt),
> + gimple_assign_rhs3 (last_stmt));
> *type_out = vectype;
> vect_pattern_detected ("vect_recog_bool_pattern", last_stmt);
>
> --
> 2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-05 6:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 15:54 [PATCH] tree-optimization/104595 - vectorization of COND_EXPR with bool load Richard Biener
2022-05-05 6:55 ` 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).