public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-128] tree-optimization/104595 - vectorization of COND_EXPR with bool load
@ 2022-05-05  8:36 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-05-05  8:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:938a02a589dc22cef65bba2b131fc9e4874baddb

commit r13-128-g938a02a589dc22cef65bba2b131fc9e4874baddb
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 21 11:05:58 2022 +0100

    tree-optimization/104595 - vectorization of COND_EXPR with bool load
    
    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.
    
    2022-02-21  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/104595
            * tree-vect-patterns.cc (vect_recog_bool_pattern): For
            COND_EXPR do not fail if check_bool_pattern returns false.
    
            * gcc.dg/vect/pr104595.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr104595.c | 24 ++++++++++++++++++++++++
 gcc/tree-vect-patterns.cc            | 16 ++++++++--------
 2 files changed, 32 insertions(+), 8 deletions(-)

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);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-05  8:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05  8:36 [gcc r13-128] tree-optimization/104595 - vectorization of COND_EXPR with bool load 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).