From patchwork Fri Oct 4 13:02:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1992735 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=Xgjv69Fg; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=J3VTPCCP; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=z7Wi6q3Q; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3sBkPyxB; dkim-atps=neutral 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=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 [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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XKpcC45cvz1xtH for ; Fri, 4 Oct 2024 23:02:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B5D93844761 for ; Fri, 4 Oct 2024 13:02:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id DD9C1385E011 for ; Fri, 4 Oct 2024 13:02:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD9C1385E011 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 DD9C1385E011 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728046934; cv=none; b=Qv6Kcrk3oL01g9YbLxatr6IrmYR4uxCZsW8Jf/RzkhJWrDKEu/uCs0ya9v1gKL3euXTSJdMANL9GgLqR+D+dTzEstxkuIDm4cpjotkX0sl6W+JDTjj5Ki4DjQVkHvikyUZmMbInFqma7dort4rytkuCzpM8JF7EeyeMRiU79+L4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728046934; c=relaxed/simple; bh=n7hzgd26aiGrZJlX3qmLKHjXMeWDWETegyaWuwQC23w=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=NsW8FZS6uFqx/YlFpx47KPBpu+dSqvZYUvmAsn5uWOki/HhanA2IrA4UsjeQh3BGOj1gX1I7tFFtt8HqcjF6IuyVNXegha9fChUOHgbjZTxVQJeTRb9e+WXXRjRGFcg81hqUpqfLiFMxADGtTdxPOtIQm4C0gut9Xj381hJJ+Ww= 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-out2.suse.de (Postfix) with ESMTPS id E186C1FB76 for ; Fri, 4 Oct 2024 13:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728046932; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2CDBFLI/RhCSkiDuml74C6PrSvvezDJxkS+124d251A=; b=Xgjv69Fg0StNbnqJeDxusr45fZULH30bpTerWdEECgAiaWhuat01Vh/peEX1C3B8zz1C7N +oN6FgDW7c7Ocq3yghUZPCtw/xuJV60TB6T04+YHViAl9qjbDl9P12Rd8g21RlvEiYFMkG gKALPLVPhwI2kVj4Tj90TlIpdSPksa0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728046932; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2CDBFLI/RhCSkiDuml74C6PrSvvezDJxkS+124d251A=; b=J3VTPCCPFj7a7xIeEMiAek5Q7MDBDgodISvhnK1+UWueoNd+DQpTJRdkcQAAWQ37PEXDcQ 4MK+eM1tI9rjqRCQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1728046931; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2CDBFLI/RhCSkiDuml74C6PrSvvezDJxkS+124d251A=; b=z7Wi6q3Qu50OonpQ3lFKg6Ogp3UujdjVZsL1NUjT3Naelq7tPnHpcVGhhmzZb/YlDPk6xo Tkz8oaUHuuXCEJv6s8g3zznoWQrn34shy+945kW7zrXKmmemp9Dde+O9qw+as2uOvm0MMC Q/U7KaAkGWdHlo1iKrs7P0cuUVJaKmI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1728046931; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=2CDBFLI/RhCSkiDuml74C6PrSvvezDJxkS+124d251A=; b=3sBkPyxBTv0UHuTvBL5OBX1zc8Z+Yay+v4/Oc7KugKLXDB1Gd/ObBIxJC+/andP3/cEkE/ HY4peUU3FVDVhtAA== 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 C749313A55 for ; Fri, 4 Oct 2024 13:02:11 +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 EZQCL1Pn/2Y2TQAAD6G6ig (envelope-from ) for ; Fri, 04 Oct 2024 13:02:11 +0000 Date: Fri, 4 Oct 2024 15:02:11 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Add single-lane SLP support to .GOMP_SIMD_LANE vectorization MIME-Version: 1.0 Message-Id: <20241004130211.C749313A55@imap1.dmz-prg2.suse.org> X-Spam-Level: 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]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; MISSING_XM_UA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:mid] X-Spam-Score: -4.30 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 basic support for single-lane SLP .GOMP_SIMD_LANE vectorization, in particular it enables SLP discovery. * 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 2274d0e428e..125e69cf0eb 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -507,6 +507,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 }; @@ -587,6 +588,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; } @@ -1175,6 +1179,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) @@ -1273,6 +1279,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 584be52f423..b5dd03b25a4 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -3392,7 +3392,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 @@ -3538,18 +3538,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, @@ -3590,11 +3587,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 @@ -3608,7 +3620,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,