From patchwork Thu Jul 4 10:57:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1956796 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=femAw5MR; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FF/gL0MB; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=pNLPtTLB; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=/hU59PX0; 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 4WFDC458T5z1xqb for ; Thu, 4 Jul 2024 20:58:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 86654384A4B5 for ; Thu, 4 Jul 2024 10:58:06 +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 AB6BE3858C41 for ; Thu, 4 Jul 2024 10:57:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB6BE3858C41 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 AB6BE3858C41 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=1720090668; cv=none; b=AV6Irztz3PITXuQ9Szb7+WgJGempXNqcAYSC/D2w/Ti4m6HboHvk27U8whwLK6+itdNwq1HltxessXdlrBNzpWLnLVn2p0fohDu60KjwAk+LtHI00sMZHxn8J9OVCYzxBvvc5V6EkeN2TP1Q6spuq3oN2S1RCwCED9cd39QjUbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720090668; c=relaxed/simple; bh=cm4vBiGhf8lP4vvPqc30nctTHQeOkfXlTzvgT8zfF5s=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=lGeK+c2vgAX+K22kH68H3Wq8sSWG71ITj9bzD2Gzi66Hs3kcmrqZlmQSddLMMYfga3zxp0/soeU0FiES7kAMd+HicorsUTCoySoNqHgu3dhvKsZpQpA8Pbwd37pRISmOB2VJLpF2NYOFl20pu0z0baQbY79B7Pj6oUYUo6cL43I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (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 7C4B021A03 for ; Thu, 4 Jul 2024 10:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720090665; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=1+BTc7XdrO0jVwFQaR842IH2aWnWy3uZleHhZojkgBg=; b=femAw5MRC83H4efOYHu5RO1QNdP+Px0dn4eBwqA9HajCNMSPM0Z4e47xDtmb1PMlu9cB48 QYSnuOKNktoujHcvW30JOOjWnKXp+myvrH2CPxRHP2WLeLBJDbCu02n2A7xaTJcNBxF6Yc DQA4c92tzo8Q6hdwC1Mt57ZBb6Szlyo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720090665; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=1+BTc7XdrO0jVwFQaR842IH2aWnWy3uZleHhZojkgBg=; b=FF/gL0MBjauQAjFqJipNmObvRIj3QzPIcqUFRXYscxUyIc8p1eHHKfSA66KFW6EfV+DYWq xaAvv6hxXb9VETCw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1720090664; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=1+BTc7XdrO0jVwFQaR842IH2aWnWy3uZleHhZojkgBg=; b=pNLPtTLB2ggG8avGBqhMPRJ51zHNCQQ4DVV5hkVTXAVvQVNBHGAH6+i6Txcq3TM2POx7k8 ZE9ut/SZwtGLGkr6eieYeIs/Z4F5zuWnkdu5FeesIA1e9qbKJotYArj8NGT6dZy3YtOxaG X/i4iqJc9ZL/LHKiazriLym1k2jIyTc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1720090664; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=1+BTc7XdrO0jVwFQaR842IH2aWnWy3uZleHhZojkgBg=; b=/hU59PX0epqfwEMecKEiYh5BN17fsW12apsxU96WrwUoMmH/BfKGWgbBa0iTzg36zvY8ra oNbqqqqLpdATosCw== Date: Thu, 4 Jul 2024 12:57:44 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: Support group size of three in SLP store permute lowering MIME-Version: 1.0 X-Spamd-Result: default: False [-1.76 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-1.00)[-0.998]; NEURAL_HAM_SHORT(-0.16)[-0.816]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[murzim.nue2.suse.org:helo, tree-vect-slp.cc:url] X-Spam-Score: -1.76 X-Spam-Level: X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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 Message-Id: <20240704105806.86654384A4B5@sourceware.org> The following implements the group-size three scheme from vect_permute_store_chain in SLP grouped store permute lowering and extends it to power-of-two multiples of group size three. The scheme goes from vectors A, B and C to { A[0], B[0], C[0], A[1], B[1], C[1], ... } by first producing { A[0], B[0], X, A[1], B[1], X, ... } (with X random but chosen to A[n]) and then permuting in C[n] in the appropriate places. The extension goes as to replace vector elements with a power-of-two number of lanes and you'd get pairwise interleaving until the final three input permutes happen. The last permute step could be seen as extending C to { C[0], C[0], C[0], ... } and then performing a blend. VLA archs will want to use store-lanes here I guess, I'm not sure if the three vector interleave operation is also available with a register source and destination and thus available for a shuffle. * tree-vect-slp.cc (vect_build_slp_instance): Special case three input permute with the same number of lanes in store permute lowering. * gcc.dg/vect/slp-53.c: New testcase. * gcc.dg/vect/slp-54.c: New testcase. --- gcc/testsuite/gcc.dg/vect/slp-53.c | 15 +++++++ gcc/testsuite/gcc.dg/vect/slp-54.c | 18 +++++++++ gcc/tree-vect-slp.cc | 65 +++++++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/slp-53.c create mode 100644 gcc/testsuite/gcc.dg/vect/slp-54.c diff --git a/gcc/testsuite/gcc.dg/vect/slp-53.c b/gcc/testsuite/gcc.dg/vect/slp-53.c new file mode 100644 index 00000000000..d8cd5f85b3c --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/slp-53.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +void foo (int * __restrict x, int *y) +{ + x = __builtin_assume_aligned (x, __BIGGEST_ALIGNMENT__); + y = __builtin_assume_aligned (y, __BIGGEST_ALIGNMENT__); + for (int i = 0; i < 1024; ++i) + { + x[3*i+0] = y[2*i+0] * 7 + 5; + x[3*i+1] = y[2*i+1] * 2; + x[3*i+2] = y[2*i+0] + 3; + } +} + +/* { dg-final { scan-tree-dump "vectorizing stmts using SLP" "vect" { target { vect_int && vect_int_mult } xfail vect_load_lanes } } } */ diff --git a/gcc/testsuite/gcc.dg/vect/slp-54.c b/gcc/testsuite/gcc.dg/vect/slp-54.c new file mode 100644 index 00000000000..ab66b349d1f --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/slp-54.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ + +void foo (int * __restrict x, int *y) +{ + x = __builtin_assume_aligned (x, __BIGGEST_ALIGNMENT__); + y = __builtin_assume_aligned (y, __BIGGEST_ALIGNMENT__); + for (int i = 0; i < 1024; ++i) + { + x[6*i+0] = y[4*i+0] * 7 + 5; + x[6*i+1] = y[4*i+1] * 2; + x[6*i+2] = y[4*i+2] + 3; + x[6*i+3] = y[4*i+3] * 7 + 5; + x[6*i+4] = y[4*i+0] * 2; + x[6*i+5] = y[4*i+3] + 3; + } +} + +/* { dg-final { scan-tree-dump "vectorizing stmts using SLP" "vect" { target { vect_int && vect_int_mult } xfail riscv*-*-* } } } */ diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 170d0cf7fa1..2dc6d365303 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -3714,6 +3714,69 @@ vect_build_slp_instance (vec_info *vinfo, when the number of lanes is even. */ while (SLP_TREE_CHILDREN (perm).length () > 2) { + /* When we have three equal sized groups left the pairwise + reduction does not result in a scheme that avoids using + three vectors. Instead merge the first two groups + to the final size with do-not-care elements (chosen + from the first group) and then merge with the third. + { A0, B0, x, A1, B1, x, ... } + -> { A0, B0, C0, A1, B1, C1, ... } + This handles group size of three (and at least + power-of-two multiples of that). */ + if (SLP_TREE_CHILDREN (perm).length () == 3 + && (SLP_TREE_LANES (SLP_TREE_CHILDREN (perm)[0]) + == SLP_TREE_LANES (SLP_TREE_CHILDREN (perm)[1])) + && (SLP_TREE_LANES (SLP_TREE_CHILDREN (perm)[0]) + == SLP_TREE_LANES (SLP_TREE_CHILDREN (perm)[2]))) + { + int ai = 0; + int bi = 1; + slp_tree a = SLP_TREE_CHILDREN (perm)[ai]; + slp_tree b = SLP_TREE_CHILDREN (perm)[bi]; + unsigned n = SLP_TREE_LANES (perm); + + slp_tree permab + = vect_create_new_slp_node (2, VEC_PERM_EXPR); + SLP_TREE_LANES (permab) = n; + SLP_TREE_LANE_PERMUTATION (permab).create (n); + SLP_TREE_VECTYPE (permab) = SLP_TREE_VECTYPE (perm); + /* ??? Should be NULL but that's not expected. */ + SLP_TREE_REPRESENTATIVE (permab) + = SLP_TREE_REPRESENTATIVE (perm); + SLP_TREE_CHILDREN (permab).quick_push (a); + for (unsigned k = 0; k < SLP_TREE_LANES (a); ++k) + SLP_TREE_LANE_PERMUTATION (permab) + .quick_push (std::make_pair (0, k)); + SLP_TREE_CHILDREN (permab).quick_push (b); + for (unsigned k = 0; k < SLP_TREE_LANES (b); ++k) + SLP_TREE_LANE_PERMUTATION (permab) + .quick_push (std::make_pair (1, k)); + /* Push the do-not-care lanes. */ + for (unsigned k = 0; k < SLP_TREE_LANES (a); ++k) + SLP_TREE_LANE_PERMUTATION (permab) + .quick_push (std::make_pair (0, k)); + + /* Put the merged node into 'perm', in place of a. */ + SLP_TREE_CHILDREN (perm)[ai] = permab; + /* Adjust the references to b in the permutation + of perm and to the later children which we'll + remove. */ + for (unsigned k = 0; k < SLP_TREE_LANES (perm); ++k) + { + std::pair &p + = SLP_TREE_LANE_PERMUTATION (perm)[k]; + if (p.first == (unsigned) bi) + { + p.first = ai; + p.second += SLP_TREE_LANES (a); + } + else if (p.first > (unsigned) bi) + p.first--; + } + SLP_TREE_CHILDREN (perm).ordered_remove (bi); + break; + } + /* Pick the two nodes with the least number of lanes, prefer the earliest candidate and maintain ai < bi. */ int ai = -1; @@ -3750,7 +3813,7 @@ vect_build_slp_instance (vec_info *vinfo, SLP_TREE_LANES (permab) = n; SLP_TREE_LANE_PERMUTATION (permab).create (n); SLP_TREE_VECTYPE (permab) = SLP_TREE_VECTYPE (perm); - /* ??? We should set this NULL but that's not expected. */ + /* ??? Should be NULL but that's not expected. */ SLP_TREE_REPRESENTATIVE (permab) = SLP_TREE_REPRESENTATIVE (perm); SLP_TREE_CHILDREN (permab).quick_push (a);