From patchwork Tue Aug 18 09:36:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 508238 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 C060714029C for ; Tue, 18 Aug 2015 19:37:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=A5c5wkdS; 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:subject:message-id:mime-version:content-type; q=dns; s= default; b=PEEFK4Jg0mYOvvoIlpSSIXM6rlA1l87QTXeE8ZcS64/2jNr/VKbdd Fp5CdWQrjioNoPHdnU5PsG1ETRR7j7pMlIePBsfCeHxUFgZEqbuDOKOE5RIiDdBn 9DXZcI3BmXxNVdvaPVmO7ZpcrQPgotKkLRCmgmoPLlnvzYHp7n5I+g= 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:subject:message-id:mime-version:content-type; s= default; bh=VUNHnBTH6a8Qw+6crYaKToEIARg=; b=A5c5wkdSMFN6S0MzflCg aeN5OyYJpG52grnLrYM/5rIFmRrc0AAjq40LOhDE36OyXN/YdypM5DCeZRhAIbYM mnh9XS0holhaG8FmNhTjdUNusFzkftDPEYN2GoeXhwoiomsJquTJ3LwyLbzyxIOD FWrcTWXZCf235yuOeuoQg7M= Received: (qmail 48972 invoked by alias); 18 Aug 2015 09:37:03 -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 48962 invoked by uid 89); 18 Aug 2015 09:37:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f173.google.com Received: from mail-qk0-f173.google.com (HELO mail-qk0-f173.google.com) (209.85.220.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 18 Aug 2015 09:37:02 +0000 Received: by qkdv3 with SMTP id v3so55702708qkd.3 for ; Tue, 18 Aug 2015 02:37:00 -0700 (PDT) X-Received: by 10.55.204.80 with SMTP id r77mr11037636qki.28.1439890619974; Tue, 18 Aug 2015 02:36:59 -0700 (PDT) Received: from msticlxl57.ims.intel.com ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id g30sm9846366qge.11.2015.08.18.02.36.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Aug 2015 02:36:59 -0700 (PDT) Date: Tue, 18 Aug 2015 12:36:46 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [Scalar masks 4/x] Vecorization factor and vectype for bool statements Message-ID: <20150818093646.GD12565@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, This patch adopts vectorization factor and vectype computation to statements operating with boolean operands. For comparison compared values are used to estimate VF. Other bool statements don't affect VF. Thanks, Ilya --- 2015-08-18 Ilya Enkovich * tree-vect-loop.c (vect_determine_vectorization_factor): Ignore statements with no non-bool args when computing vectorization factor. Compute vectype for masks producers separately. (vect_transform_loop): Support scalar masks. diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 59c75af..89990e3 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -193,19 +193,21 @@ vect_determine_vectorization_factor (loop_vec_info loop_vinfo) { struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo); basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo); - int nbbs = loop->num_nodes; + unsigned nbbs = loop->num_nodes; unsigned int vectorization_factor = 0; tree scalar_type; gphi *phi; tree vectype; unsigned int nunits; stmt_vec_info stmt_info; - int i; + unsigned i; HOST_WIDE_INT dummy; gimple stmt, pattern_stmt = NULL; gimple_seq pattern_def_seq = NULL; gimple_stmt_iterator pattern_def_si = gsi_none (); bool analyze_pattern_stmt = false; + bool bool_result; + auto_vec mask_producers; if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, @@ -424,6 +426,8 @@ vect_determine_vectorization_factor (loop_vec_info loop_vinfo) return false; } + bool_result = false; + if (STMT_VINFO_VECTYPE (stmt_info)) { /* The only case when a vectype had been already set is for stmts @@ -444,6 +448,30 @@ vect_determine_vectorization_factor (loop_vec_info loop_vinfo) scalar_type = TREE_TYPE (gimple_call_arg (stmt, 3)); else scalar_type = TREE_TYPE (gimple_get_lhs (stmt)); + + /* Bool ops don't participate in vectorization factor + computation. For comparison use compared types to + compute a factor. */ + if (scalar_type == boolean_type_node) + { + mask_producers.safe_push (stmt_info); + bool_result = true; + + if (gimple_code (stmt) == GIMPLE_ASSIGN + && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison + && TREE_TYPE (gimple_assign_rhs1 (stmt)) != boolean_type_node) + scalar_type = TREE_TYPE (gimple_assign_rhs1 (stmt)); + else + { + if (!analyze_pattern_stmt && gsi_end_p (pattern_def_si)) + { + pattern_def_seq = NULL; + gsi_next (&si); + } + continue; + } + } + if (dump_enabled_p ()) { dump_printf_loc (MSG_NOTE, vect_location, @@ -466,7 +494,8 @@ vect_determine_vectorization_factor (loop_vec_info loop_vinfo) return false; } - STMT_VINFO_VECTYPE (stmt_info) = vectype; + if (!bool_result) + STMT_VINFO_VECTYPE (stmt_info) = vectype; if (dump_enabled_p ()) { @@ -479,8 +508,9 @@ vect_determine_vectorization_factor (loop_vec_info loop_vinfo) /* The vectorization factor is according to the smallest scalar type (or the largest vector size, but we only support one vector size per loop). */ - scalar_type = vect_get_smallest_scalar_type (stmt, &dummy, - &dummy); + if (!bool_result) + scalar_type = vect_get_smallest_scalar_type (stmt, &dummy, + &dummy); if (dump_enabled_p ()) { dump_printf_loc (MSG_NOTE, vect_location, @@ -555,6 +585,70 @@ vect_determine_vectorization_factor (loop_vec_info loop_vinfo) } LOOP_VINFO_VECT_FACTOR (loop_vinfo) = vectorization_factor; + for (i = 0; i < mask_producers.length (); i++) + { + tree mask_type = NULL; + + stmt = STMT_VINFO_STMT (mask_producers[i]); + + if (gimple_code (stmt) == GIMPLE_ASSIGN + && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison + && TREE_TYPE (gimple_assign_rhs1 (stmt)) != boolean_type_node) + { + scalar_type = TREE_TYPE (gimple_assign_rhs1 (stmt)); + vectype = get_vectype_for_scalar_type (scalar_type); + nunits = TYPE_VECTOR_SUBPARTS (vectype); + mask_type = build_nonstandard_integer_type (nunits, 1); + } + else + { + tree rhs; + ssa_op_iter iter; + gimple def_stmt; + + FOR_EACH_SSA_TREE_OPERAND (rhs, stmt, iter, SSA_OP_USE) + { + def_stmt = SSA_NAME_DEF_STMT (rhs); + if (!def_stmt + || !(stmt_info = vinfo_for_stmt (def_stmt)) + || !(vectype = STMT_VINFO_VECTYPE (stmt_info)) + || VECTOR_TYPE_P (vectype)) + { + if (dump_enabled_p ()) + { + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: can't compute mask type " + "in statement, "); + dump_gimple_stmt (MSG_MISSED_OPTIMIZATION, TDF_SLIM, stmt, + 0); + dump_printf (MSG_MISSED_OPTIMIZATION, "\n"); + } + return false; + } + if (!mask_type) + mask_type = vectype; + else if (TYPE_PRECISION (mask_type) != TYPE_PRECISION (vectype)) + { + if (dump_enabled_p ()) + { + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: different sized masks " + "types in statement, "); + dump_generic_expr (MSG_MISSED_OPTIMIZATION, TDF_SLIM, + mask_type); + dump_printf (MSG_MISSED_OPTIMIZATION, " and "); + dump_generic_expr (MSG_MISSED_OPTIMIZATION, TDF_SLIM, + vectype); + dump_printf (MSG_MISSED_OPTIMIZATION, "\n"); + } + return false; + } + } + } + + STMT_VINFO_VECTYPE (mask_producers[i]) = mask_type; + } + return true; } @@ -6203,9 +6297,12 @@ vect_transform_loop (loop_vec_info loop_vinfo) if (STMT_VINFO_VECTYPE (stmt_info)) { - unsigned int nunits - = (unsigned int) + unsigned int nunits; + if (VECTOR_TYPE_P (STMT_VINFO_VECTYPE (stmt_info))) + nunits = (unsigned int) TYPE_VECTOR_SUBPARTS (STMT_VINFO_VECTYPE (stmt_info)); + else + nunits = TYPE_PRECISION (STMT_VINFO_VECTYPE (stmt_info)); if (!STMT_SLP_TYPE (stmt_info) && nunits != (unsigned int) vectorization_factor && dump_enabled_p ())