From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 3F2703856246; Thu, 5 May 2022 08:36:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F2703856246 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-128] tree-optimization/104595 - vectorization of COND_EXPR with bool load X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: b9b764bce89f104e48f797b33836d66073e73ebb X-Git-Newrev: 938a02a589dc22cef65bba2b131fc9e4874baddb Message-Id: <20220505083658.3F2703856246@sourceware.org> Date: Thu, 5 May 2022 08:36:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 08:36:58 -0000 https://gcc.gnu.org/g:938a02a589dc22cef65bba2b131fc9e4874baddb commit r13-128-g938a02a589dc22cef65bba2b131fc9e4874baddb Author: Richard Biener 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 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);