From patchwork Tue Jun 13 15:55:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 1794589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QgY7h5KThz20QH for ; Wed, 14 Jun 2023 01:56:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4244385828E for ; Tue, 13 Jun 2023 15:56:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 2330E3858CDA for ; Tue, 13 Jun 2023 15:56:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2330E3858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="6.00,240,1681200000"; d="scan'208";a="9709536" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 13 Jun 2023 07:56:02 -0800 IronPort-SDR: ioGqnPMQCrrj0IG8ZIa+Vum/icVOMYYyk2r1WATb0s/+0dm0RT8eNsE7qqrDElwnb1+KGiobg7 TRwvLBWVMkvZDX+ih8yzt6ML8V5eRiT3U+R/P5O7UK8yNE6XAbaGLGzxC2+aoSvSlZFDZyuvTH 57y7BxUUlQmOAeNEPE9zvGLos51DKw+GaoxeL/8NAUa4v9aAUj5VGBW7SUjNFeiJeB9EF7XT9x DiOPj18Nsb4bSPU6D0tMe67fdaTDA65QmcyxYv9EUi2dolxbhLADLTkevpM33wUEtTmBntqrzk ceU= Message-ID: <0e5fddf8-8605-a0d6-eede-1a8fcf12535c@codesourcery.com> Date: Tue, 13 Jun 2023 16:55:57 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.12.0 Content-Language: en-GB From: Andrew Stubbs Subject: [PATCH] vect: Vectorize via libfuncs To: "gcc-patches@gcc.gnu.org" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-11.mgc.mentorg.com (139.181.222.11) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch allows vectorization when operators are available as libfuncs, rather that only as insns. This will be useful for amdgcn where we plan to vectorize loops that contain integer division or modulus, but don't want to generate inline instructions for the division algorithm every time. The change should have not affect architectures that do not define vector-mode libfuncs. OK for mainline? Andrew vect: vectorize via libfuncs This patch allows vectorization when the libfuncs are defined. gcc/ChangeLog: * tree-vect-generic.cc: Include optabs-libfuncs.h. (get_compute_type): Check optab_libfunc. * tree-vect-stmts.cc: Include optabs-libfuncs.h. (vectorizable_operation): Check optab_libfunc. diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc index b7d4a919c55..4d784a70c0d 100644 --- a/gcc/tree-vect-generic.cc +++ b/gcc/tree-vect-generic.cc @@ -44,6 +44,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-fold.h" #include "gimple-match.h" #include "recog.h" /* FIXME: for insn_data */ +#include "optabs-libfuncs.h" /* Build a ternary operation and gimplify it. Emit code before GSI. @@ -1714,7 +1715,8 @@ get_compute_type (enum tree_code code, optab op, tree type) machine_mode compute_mode = TYPE_MODE (compute_type); if (VECTOR_MODE_P (compute_mode)) { - if (op && optab_handler (op, compute_mode) != CODE_FOR_nothing) + if (op && (optab_handler (op, compute_mode) != CODE_FOR_nothing + || optab_libfunc (op, compute_mode))) return compute_type; if (code == MULT_HIGHPART_EXPR && can_mult_highpart_p (compute_mode, diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index a7acc032d47..71a8cf2c6d4 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-fold.h" #include "regs.h" #include "attribs.h" +#include "optabs-libfuncs.h" /* For lang_hooks.types.type_for_mode. */ #include "langhooks.h" @@ -6528,8 +6529,8 @@ vectorizable_operation (vec_info *vinfo, "no optab.\n"); return false; } - target_support_p = (optab_handler (optab, vec_mode) - != CODE_FOR_nothing); + target_support_p = (optab_handler (optab, vec_mode) != CODE_FOR_nothing + || optab_libfunc (optab, vec_mode)); } bool using_emulated_vectors_p = vect_emulated_vector_p (vectype);