From patchwork Mon Jul 1 07:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1954539 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Vv1xP7wx; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=4cSoaQEf; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=1rQHjrz8; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=nIdVIQuf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCJM56hJ9z1xpN for ; Mon, 1 Jul 2024 17:58:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 410F9381D465 for ; Mon, 1 Jul 2024 07:58:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 26F38381D465 for ; Mon, 1 Jul 2024 07:57:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26F38381D465 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 26F38381D465 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719820678; cv=none; b=kmTqqp9wWlbIfwuLahoCr+U4/EqueeyQkaBGHUohHqhecnHTgOlr4/WeFZdgHUVcU33QTHWKuxYkBskIskKKmBfRRr+bCvWDf6Uu23nZ2E+6ZF3q0H5jZ3aFTUvEythRNn0+MaeUFFq77fYD88YQ4lCiJVDd2CJkrCNLs6xSmIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719820678; c=relaxed/simple; bh=z9urhlbjOxRPskEQhjxShJGhpeMKNX+GbCNHFsAhsY4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=vGc5fwCpxx6h2b8UeTCUpU7PZugxAuJn9XpXvHcY8kjZbDC8E2LlAsxlXN03sdtAIOs0LW562yD5wu9XEHl53JRaurmySHmNKhW9ki6BDIuW7Qoi/XbNDaba9gAIdzlOlXJ41crhFyo/GS8++cXvIWUIm3Qd1SxzYumnDfVE78M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id F2CFA21BEC; Mon, 1 Jul 2024 07:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719820675; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=KTIQxuVvkgZKNj30XZ361oRWGc6zY1j/tEnAYhX9IrU=; b=Vv1xP7wxohvMVKRRGzSnu+Fhv0yR3yaaNN1a4cLAYBuY+syPJjdTUUXlRAkBEv7JegztS+ pWGOibKKl2w2LgjEdtYgg5un25R8ra38Wb0YsWbFIM6UoEfRcksLCRIoTa3/Lde9xSK6jS Ir0yqpgGQMDupbVAP3mXq3FGowBxb3I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719820675; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=KTIQxuVvkgZKNj30XZ361oRWGc6zY1j/tEnAYhX9IrU=; b=4cSoaQEfODAjCG2rhGhwKMhrcrQAMoiXkBMxfMzoZS2dmdB1phhtZSdfPlAZeDb1oJbEtw SwDDv8qQ0ZFKC+DQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719820674; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=KTIQxuVvkgZKNj30XZ361oRWGc6zY1j/tEnAYhX9IrU=; b=1rQHjrz8gPPXKBfFwYkX3sMI28e0XEGj3Q0OVsl6kDA6v19W9ZQ3DTvPIzCaZdBVnXc0V9 KXxEBq/TzStmDkJpKjECsvaIkzY6wicOXOMKmpkOPKZevXQ6Xs71Ih1dgfH7egmp5U4f9i jebCw+2egeVJwX2v769ls3bfUeu+wV8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719820674; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=KTIQxuVvkgZKNj30XZ361oRWGc6zY1j/tEnAYhX9IrU=; b=nIdVIQufq7554KV4ch5P+81JSgtev4ubVk40TPHiIqBr3DUUoGJGoz1v5OrTlqRncL4YoB hL4cdD3kNPclSYAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id CAC6D139C2; Mon, 1 Jul 2024 07:57:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id s9PQL4JhgmZweAAAD6G6ig (envelope-from ); Mon, 01 Jul 2024 07:57:54 +0000 Date: Mon, 1 Jul 2024 09:57:53 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: richard.sandiford@arm.com, Jakub Jelinek Subject: [PATCH] Add single-lane SLP support to .GOMP_SIMD_LANE vectorization MIME-Version: 1.0 Message-Id: <20240701075754.CAC6D139C2@imap1.dmz-prg2.suse.org> X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_THREE(0.00)[3] X-Spam-Score: -4.30 X-Spam-Level: X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 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 The following adds support for single-lane SLP .GOMP_SIMD_LANE vectorization. This doesn't handle much, esp. g++.dg/vect/simd-*.cc with their 'inscan' uses are unhandled. * tree-vect-slp.cc (no_arg_map): New. (vect_get_operand_map): Handle IFN_GOMP_SIMD_LANE. (vect_build_slp_tree_1): Likewise. * tree-vect-stmts.cc (vectorizable_call): Handle single-lane SLP for .GOMP_SIMD_LANE calls. --- gcc/tree-vect-slp.cc | 11 +++++++++++ gcc/tree-vect-stmts.cc | 27 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 3138a815da7..f3743997e9c 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -505,6 +505,7 @@ static const int cond_expr_maps[3][5] = { { 4, -2, -1, 1, 2 }, { 4, -1, -2, 2, 1 } }; +static const int no_arg_map[] = { 0 }; static const int arg0_map[] = { 1, 0 }; static const int arg1_map[] = { 1, 1 }; static const int arg2_map[] = { 1, 2 }; @@ -585,6 +586,9 @@ vect_get_operand_map (const gimple *stmt, bool gather_scatter_p = false, case IFN_CTZ: return arg0_map; + case IFN_GOMP_SIMD_LANE: + return no_arg_map; + default: break; } @@ -1168,6 +1172,8 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, ldst_p = true; rhs_code = CFN_MASK_STORE; } + else if (cfn == CFN_GOMP_SIMD_LANE) + ; else if ((cfn != CFN_LAST && cfn != CFN_MASK_CALL && internal_fn_p (cfn) @@ -1271,6 +1277,11 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, need_same_oprnds = true; first_op1 = gimple_call_arg (call_stmt, 1); } + else if (rhs_code == CFN_GOMP_SIMD_LANE) + { + need_same_oprnds = true; + first_op1 = gimple_call_arg (call_stmt, 1); + } } else { diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 840ff8a3406..270c5a5dd34 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -3341,7 +3341,7 @@ vectorizable_call (vec_info *vinfo, if (ifn == IFN_LAST && !fndecl) { if (cfn == CFN_GOMP_SIMD_LANE - && !slp_node + && (!slp_node || SLP_TREE_LANES (slp_node) == 1) && loop_vinfo && LOOP_VINFO_LOOP (loop_vinfo)->simduid && TREE_CODE (gimple_call_arg (stmt, 0)) == SSA_NAME @@ -3487,18 +3487,15 @@ vectorizable_call (vec_info *vinfo, /* Build argument list for the vectorized call. */ if (slp_node) { - vec vec_oprnds0; - + unsigned int vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node); vect_get_slp_defs (vinfo, slp_node, &vec_defs); - vec_oprnds0 = vec_defs[0]; /* Arguments are ready. Create the new vector stmt. */ - FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_oprnd0) + for (i = 0; i < vec_num; ++i) { int varg = 0; if (masked_loop_p && reduc_idx >= 0) { - unsigned int vec_num = vec_oprnds0.length (); /* Always true for SLP. */ gcc_assert (ncopies == 1); vargs[varg++] = vect_get_loop_mask (loop_vinfo, @@ -3539,11 +3536,26 @@ vectorizable_call (vec_info *vinfo, vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi); } + else if (cfn == CFN_GOMP_SIMD_LANE) + { + /* ??? For multi-lane SLP we'd need to build + { 0, 0, .., 1, 1, ... }. */ + tree cst = build_index_vector (vectype_out, + i * nunits_out, 1); + tree new_var + = vect_get_new_ssa_name (vectype_out, vect_simple_var, + "cst_"); + gimple *init_stmt = gimple_build_assign (new_var, cst); + vect_init_vector_1 (vinfo, stmt_info, init_stmt, NULL); + new_temp = make_ssa_name (vec_dest); + new_stmt = gimple_build_assign (new_temp, new_var); + vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, + gsi); + } else { if (len_opno >= 0 && len_loop_p) { - unsigned int vec_num = vec_oprnds0.length (); /* Always true for SLP. */ gcc_assert (ncopies == 1); tree len @@ -3557,7 +3569,6 @@ vectorizable_call (vec_info *vinfo, } else if (mask_opno >= 0 && masked_loop_p) { - unsigned int vec_num = vec_oprnds0.length (); /* Always true for SLP. */ gcc_assert (ncopies == 1); tree mask = vect_get_loop_mask (loop_vinfo,