From patchwork Fri Nov 12 17:57:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 47556 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24322385840F for ; Fri, 12 Nov 2021 17:58:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24322385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636739880; bh=ECTR6M0znjAhi3okjwA4rmGBhlIQVlsuveotjRsxH3g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=atlR94Vhk6skcVpdFskEGmULrXOU6kaUGLg1POl6AKK4wvpRZZ4+q51rGrehytjk0 Rf11oRQNbn48ICqkiKR1/NJljr02lJYd0L95l5Uih1tsJ4z5wAE9mhzv0kpK9Db2HP 8wlMHfNThol2UjX4VeMsb60WNm5a6I+OgePZYcMc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 3AA7A385840F for ; Fri, 12 Nov 2021 17:57:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3AA7A385840F Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D9932D6E for ; Fri, 12 Nov 2021 09:57:30 -0800 (PST) Received: from localhost (unknown [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 80DA63F718 for ; Fri, 12 Nov 2021 09:57:30 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 1/5] vect: Use code_helper when building SLP nodes Date: Fri, 12 Nov 2021 17:57:29 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch uses code_helper to represent the common (and alternative) operations when building an SLP node. It's not much of a saving on its own, but it helps with later patches. Regstrapped on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ * tree-vect-slp.c (vect_build_slp_tree_1): Use code_helper to record the operations performed by statements, only using CALL_EXPR for things that don't map to built-in or internal functions. For shifts, require all shift amounts to be equal if optab_vector is not supported but optab_scalar is. --- gcc/tree-vect-slp.c | 77 +++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 51 deletions(-) diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 94c75497495..f4123cf830a 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -876,17 +876,13 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, { unsigned int i; stmt_vec_info first_stmt_info = stmts[0]; - enum tree_code first_stmt_code = ERROR_MARK; - enum tree_code alt_stmt_code = ERROR_MARK; - enum tree_code rhs_code = ERROR_MARK; - enum tree_code first_cond_code = ERROR_MARK; + code_helper first_stmt_code = ERROR_MARK; + code_helper alt_stmt_code = ERROR_MARK; + code_helper rhs_code = ERROR_MARK; + code_helper first_cond_code = ERROR_MARK; tree lhs; bool need_same_oprnds = false; tree vectype = NULL_TREE, first_op1 = NULL_TREE; - optab optab; - int icode; - machine_mode optab_op2_mode; - machine_mode vec_mode; stmt_vec_info first_load = NULL, prev_first_load = NULL; bool first_stmt_load_p = false, load_p = false; bool first_stmt_phi_p = false, phi_p = false; @@ -966,13 +962,16 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, gcall *call_stmt = dyn_cast (stmt); if (call_stmt) { - rhs_code = CALL_EXPR; + combined_fn cfn = gimple_call_combined_fn (call_stmt); + if (cfn != CFN_LAST) + rhs_code = cfn; + else + rhs_code = CALL_EXPR; - if (gimple_call_internal_p (stmt, IFN_MASK_LOAD)) + if (cfn == CFN_MASK_LOAD) load_p = true; - else if ((gimple_call_internal_p (call_stmt) - && (!vectorizable_internal_fn_p - (gimple_call_internal_fn (call_stmt)))) + else if ((internal_fn_p (cfn) + && !vectorizable_internal_fn_p (as_internal_fn (cfn))) || gimple_call_tail_p (call_stmt) || gimple_call_noreturn_p (call_stmt) || gimple_call_chain (call_stmt)) @@ -1013,32 +1012,11 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, || rhs_code == LROTATE_EXPR || rhs_code == RROTATE_EXPR) { - vec_mode = TYPE_MODE (vectype); - /* First see if we have a vector/vector shift. */ - optab = optab_for_tree_code (rhs_code, vectype, - optab_vector); - - if (!optab - || optab_handler (optab, vec_mode) == CODE_FOR_nothing) + if (!directly_supported_p (rhs_code, vectype, optab_vector)) { /* No vector/vector shift, try for a vector/scalar shift. */ - optab = optab_for_tree_code (rhs_code, vectype, - optab_scalar); - - if (!optab) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "Build SLP failed: no optab.\n"); - if (is_a (vinfo) && i != 0) - continue; - /* Fatal mismatch. */ - matches[0] = false; - return false; - } - icode = (int) optab_handler (optab, vec_mode); - if (icode == CODE_FOR_nothing) + if (!directly_supported_p (rhs_code, vectype, optab_scalar)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -1050,12 +1028,8 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, matches[0] = false; return false; } - optab_op2_mode = insn_data[icode].operand[2].mode; - if (!VECTOR_MODE_P (optab_op2_mode)) - { - need_same_oprnds = true; - first_op1 = gimple_assign_rhs2 (stmt); - } + need_same_oprnds = true; + first_op1 = gimple_assign_rhs2 (stmt); } } else if (rhs_code == WIDEN_LSHIFT_EXPR) @@ -1081,8 +1055,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, return false; } } - else if (call_stmt - && gimple_call_internal_p (call_stmt, IFN_DIV_POW2)) + else if (rhs_code == CFN_DIV_POW2) { need_same_oprnds = true; first_op1 = gimple_call_arg (call_stmt, 1); @@ -1139,10 +1112,10 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, continue; } - if (!load_p && rhs_code == CALL_EXPR) + if (!load_p && call_stmt) { if (!compatible_calls_p (as_a (stmts[0]->stmt), - as_a (stmt))) + call_stmt)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -1243,10 +1216,11 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, /* Not memory operation. */ if (!phi_p - && TREE_CODE_CLASS (rhs_code) != tcc_binary - && TREE_CODE_CLASS (rhs_code) != tcc_unary - && TREE_CODE_CLASS (rhs_code) != tcc_expression - && TREE_CODE_CLASS (rhs_code) != tcc_comparison + && rhs_code.is_tree_code () + && TREE_CODE_CLASS (tree_code (rhs_code)) != tcc_binary + && TREE_CODE_CLASS (tree_code (rhs_code)) != tcc_unary + && TREE_CODE_CLASS (tree_code (rhs_code)) != tcc_expression + && TREE_CODE_CLASS (tree_code (rhs_code)) != tcc_comparison && rhs_code != VIEW_CONVERT_EXPR && rhs_code != CALL_EXPR && rhs_code != BIT_FIELD_REF) @@ -1308,7 +1282,8 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, /* If we allowed a two-operation SLP node verify the target can cope with the permute we are going to use. */ if (alt_stmt_code != ERROR_MARK - && TREE_CODE_CLASS (alt_stmt_code) != tcc_reference) + && (!alt_stmt_code.is_tree_code () + || TREE_CODE_CLASS (tree_code (alt_stmt_code)) != tcc_reference)) { *two_operators = true; }