From patchwork Mon Nov 9 12:11:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 541742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B3EFB1402C8 for ; Mon, 9 Nov 2015 23:11:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=ov2T392O; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=bB4oXyWQsBpf/s/0k XlS/DBRFK0m4HHC7FyDTd+RZjFmHieFpWjorSrDqi7NLvnoxwuTR8xl6q0IfSI36 R251LTBEvXl9CZI3kRiqYV/uMe2jFAtgERyonHWEZLBH9kOgYZg8gLGEEligtZ4T wdhbzxTmNcCiec2JorLX2wrLKU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=IvsoO0TUeQZ+P8L2xViMWpR k388=; b=ov2T392OTVPJmGyythVjB0GuskLYjyzI2TGO/4YTWM1eEshK7S5mWns LyeatHqZ1Wm8SBwpeNb2ed2Wqdm7/wP+62eNAR4Ovde/scP/W9ovW/0UAi0+2J/F i21SzAbJpA629qOq1HnA8YDN/B7+4AXxBuaMkI/EtOyn9iEnEx04= Received: (qmail 10497 invoked by alias); 9 Nov 2015 12:11:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9667 invoked by uid 89); 9 Nov 2015 12:11:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wm0-f52.google.com Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 09 Nov 2015 12:11:48 +0000 Received: by wmec201 with SMTP id c201so75475493wme.0 for ; Mon, 09 Nov 2015 04:11:45 -0800 (PST) X-Received: by 10.28.10.13 with SMTP id 13mr26043628wmk.30.1447071105367; Mon, 09 Nov 2015 04:11:45 -0800 (PST) Received: from msticlxl57.ims.intel.com (jfdmzpr06-ext.jf.intel.com. [134.134.137.75]) by smtp.gmail.com with ESMTPSA id w66sm13991065wme.11.2015.11.09.04.11.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2015 04:11:44 -0800 (PST) Date: Mon, 9 Nov 2015 15:11:18 +0300 From: Ilya Enkovich To: Richard Biener Cc: GCC Patches Subject: Re: [vec-cmp, patch 4/6] Support vector mask invariants Message-ID: <20151109121118.GB51763@msticlxl57.ims.intel.com> References: <20151008151140.GE63757@msticlxl57.ims.intel.com> <20151014161352.GO63757@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On 26 Oct 16:21, Richard Biener wrote: > On Wed, Oct 14, 2015 at 6:13 PM, Ilya Enkovich wrote: > > - val = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (type), val); > > + { > > + /* Can't use VIEW_CONVERT_EXPR for booleans because > > + of possibly different sizes of scalar value and > > + vector element. */ > > + if (VECTOR_BOOLEAN_TYPE_P (type)) > > + { > > + if (integer_zerop (val)) > > + val = build_int_cst (TREE_TYPE (type), 0); > > + else if (integer_onep (val)) > > + val = build_int_cst (TREE_TYPE (type), 1); > > + else > > + gcc_unreachable (); > > + } > > + else > > + val = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (type), val); > > I think the existing code is fine with using fold_convert () here > which should also work > for the boolean types. So does just > > val = fold_convert (TREE_TYPE (type), val); > > work? It seems to work OK. > > > @@ -7428,13 +7459,13 @@ vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi, > > gimple *gtemp; > > vec_cond_lhs = > > vect_get_vec_def_for_operand (TREE_OPERAND (cond_expr, 0), > > - stmt, NULL); > > + stmt, NULL, comp_vectype); > > vect_is_simple_use (TREE_OPERAND (cond_expr, 0), stmt, > > loop_vinfo, >emp, &def, &dts[0]); > > > > vec_cond_rhs = > > vect_get_vec_def_for_operand (TREE_OPERAND (cond_expr, 1), > > - stmt, NULL); > > + stmt, NULL, comp_vectype); > > vect_is_simple_use (TREE_OPERAND (cond_expr, 1), stmt, > > loop_vinfo, >emp, &def, &dts[1]); > > I still don't like this very much but I guess without some major > refactoring of all > the functions there isn't a better way to do it for now. > > Thus, ok with trying the change suggested above. > > Thanks, > Richard. > Here is an updated version. Thanks, Ilya --- gcc/ 2015-11-09 Ilya Enkovich * expr.c (const_vector_mask_from_tree): New. (const_vector_from_tree): Use const_vector_mask_from_tree for boolean vectors. * tree-vect-stmts.c (vect_init_vector): Support boolean vector invariants. (vect_get_vec_def_for_operand): Add VECTYPE arg. (vectorizable_condition): Directly provide vectype for invariants used in comparison. * tree-vectorizer.h (vect_get_vec_def_for_operand): Add VECTYPE arg. diff --git a/gcc/expr.c b/gcc/expr.c index 2b2174f..03936ee 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -11423,6 +11423,40 @@ try_tablejump (tree index_type, tree index_expr, tree minval, tree range, return 1; } +/* Return a CONST_VECTOR rtx representing vector mask for + a VECTOR_CST of booleans. */ +static rtx +const_vector_mask_from_tree (tree exp) +{ + rtvec v; + unsigned i; + int units; + tree elt; + machine_mode inner, mode; + + mode = TYPE_MODE (TREE_TYPE (exp)); + units = GET_MODE_NUNITS (mode); + inner = GET_MODE_INNER (mode); + + v = rtvec_alloc (units); + + for (i = 0; i < VECTOR_CST_NELTS (exp); ++i) + { + elt = VECTOR_CST_ELT (exp, i); + + gcc_assert (TREE_CODE (elt) == INTEGER_CST); + if (integer_zerop (elt)) + RTVEC_ELT (v, i) = CONST0_RTX (inner); + else if (integer_onep (elt) + || integer_minus_onep (elt)) + RTVEC_ELT (v, i) = CONSTM1_RTX (inner); + else + gcc_unreachable (); + } + + return gen_rtx_CONST_VECTOR (mode, v); +} + /* Return a CONST_VECTOR rtx for a VECTOR_CST tree. */ static rtx const_vector_from_tree (tree exp) @@ -11438,6 +11472,9 @@ const_vector_from_tree (tree exp) if (initializer_zerop (exp)) return CONST0_RTX (mode); + if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp))) + return const_vector_mask_from_tree (exp); + units = GET_MODE_NUNITS (mode); inner = GET_MODE_INNER (mode); diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index ee549f4..af203ab 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -1300,7 +1300,7 @@ vect_init_vector (gimple *stmt, tree val, tree type, gimple_stmt_iterator *gsi) if (!types_compatible_p (TREE_TYPE (type), TREE_TYPE (val))) { if (CONSTANT_CLASS_P (val)) - val = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (type), val); + val = fold_convert (TREE_TYPE (type), val); else { new_temp = make_ssa_name (TREE_TYPE (type)); @@ -1328,16 +1328,18 @@ vect_init_vector (gimple *stmt, tree val, tree type, gimple_stmt_iterator *gsi) STMT_VINFO_VEC_STMT of the defining stmt holds the relevant def. In case OP is an invariant or constant, a new stmt that creates a vector def - needs to be introduced. */ + needs to be introduced. VECTYPE may be used to specify a required type for + vector invariant. */ tree -vect_get_vec_def_for_operand (tree op, gimple *stmt) +vect_get_vec_def_for_operand (tree op, gimple *stmt, tree vectype) { tree vec_oprnd; gimple *vec_stmt; gimple *def_stmt; stmt_vec_info def_stmt_info = NULL; stmt_vec_info stmt_vinfo = vinfo_for_stmt (stmt); + tree stmt_vectype = STMT_VINFO_VECTYPE (stmt_vinfo); loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo); enum vect_def_type dt; bool is_simple_use; @@ -1372,7 +1374,14 @@ vect_get_vec_def_for_operand (tree op, gimple *stmt) case vect_constant_def: case vect_external_def: { - vector_type = get_vectype_for_scalar_type (TREE_TYPE (op)); + if (vectype) + vector_type = vectype; + else if (TREE_CODE (TREE_TYPE (op)) == BOOLEAN_TYPE + && VECTOR_BOOLEAN_TYPE_P (stmt_vectype)) + vector_type = build_same_sized_truth_vector_type (stmt_vectype); + else + vector_type = get_vectype_for_scalar_type (TREE_TYPE (op)); + gcc_assert (vector_type); return vect_init_vector (stmt, op, vector_type, NULL); } @@ -7329,13 +7338,14 @@ vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi, { gimple *gtemp; vec_cond_lhs = - vect_get_vec_def_for_operand (TREE_OPERAND (cond_expr, 0), stmt); + vect_get_vec_def_for_operand (TREE_OPERAND (cond_expr, 0), + stmt, comp_vectype); vect_is_simple_use (TREE_OPERAND (cond_expr, 0), loop_vinfo, >emp, &dts[0]); vec_cond_rhs = vect_get_vec_def_for_operand (TREE_OPERAND (cond_expr, 1), - stmt); + stmt, comp_vectype); vect_is_simple_use (TREE_OPERAND (cond_expr, 1), loop_vinfo, >emp, &dts[1]); if (reduc_index == 1) diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index 58d5f0b..d38d767 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -978,7 +978,7 @@ extern unsigned record_stmt_cost (stmt_vector_for_cost *, int, extern void vect_finish_stmt_generation (gimple *, gimple *, gimple_stmt_iterator *); extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info); -extern tree vect_get_vec_def_for_operand (tree, gimple *); +extern tree vect_get_vec_def_for_operand (tree, gimple *, tree = NULL); extern tree vect_init_vector (gimple *, tree, tree, gimple_stmt_iterator *); extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree);