From patchwork Tue Sep 3 09:32:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1979943 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=w2Ub0XLx; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=5W60CzY7; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=w2Ub0XLx; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=5W60CzY7; 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 4WygRS0Nxgz1yg9 for ; Tue, 3 Sep 2024 19:33:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1C0C3860768 for ; Tue, 3 Sep 2024 09:33:37 +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 7579A3858401 for ; Tue, 3 Sep 2024 09:33:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7579A3858401 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 7579A3858401 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=1725355995; cv=none; b=R843cmNhcOCfhYFTamSrgrtWveEZnMTsdc8vn+afDFAmD0NNHg9ocYoG+usVdwu+AtV6uXk0sB3vUcYCb/5Kly4D7Jcalj0mglhfaYUV/g+JIRaG0g6LyymiMBZxbOBHNiEvDRMMrb6sBdQqqcpPoQk49zSto28AUMmRL3g5GDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725355995; c=relaxed/simple; bh=t4F1Pqb8i2g/SFN8IGuo4CaEyfhjNy/7x2LlYYxR4fU=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=YCyu0Liv6mvNnKu4NyyxH4kcAJyPBrUmfmrQc/Xph9jq83gSJn9AnD0m3KjSsp3ws2Kh26n6p6FrJ++tSUDVKzoAMtEE8FEWeZ+0Shda41F+nw6kY/X9rKaBzfSW/K0OduXozYtcRlA+OLRik+RiVgRW+p/SHrvfmnVmKQKpCaY= 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 7652E1FCF6 for ; Tue, 3 Sep 2024 09:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725355992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=3daDSUEUH6krdIfG8uOU3PPSq8X2XVgdO38lIt0C7uE=; b=w2Ub0XLxpkKbsYJ+SKd5IRxuxcx1FwZYcskLMXH9Na1phjkhxca+ct8FPivu++xIXc1su8 csE81pQc8egvH/TXxFS2v3qer8swgw8S6aVesUfmeGxE95DUYxyy8M4ouZ3LowH0ZYpNU1 /UhlcUzv7zLEgZ4e9nMcgZqZzTkx4XY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725355992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=3daDSUEUH6krdIfG8uOU3PPSq8X2XVgdO38lIt0C7uE=; b=5W60CzY7X+8tucwIjFzezU449RMbUcjuyw8aXQXfXBzBrI3CJO0+HVqFcADoiJjchfVHq/ 1mvxsknRveCk74Ag== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725355992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=3daDSUEUH6krdIfG8uOU3PPSq8X2XVgdO38lIt0C7uE=; b=w2Ub0XLxpkKbsYJ+SKd5IRxuxcx1FwZYcskLMXH9Na1phjkhxca+ct8FPivu++xIXc1su8 csE81pQc8egvH/TXxFS2v3qer8swgw8S6aVesUfmeGxE95DUYxyy8M4ouZ3LowH0ZYpNU1 /UhlcUzv7zLEgZ4e9nMcgZqZzTkx4XY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725355992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=3daDSUEUH6krdIfG8uOU3PPSq8X2XVgdO38lIt0C7uE=; b=5W60CzY7X+8tucwIjFzezU449RMbUcjuyw8aXQXfXBzBrI3CJO0+HVqFcADoiJjchfVHq/ 1mvxsknRveCk74Ag== 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 5D41A13A52 for ; Tue, 3 Sep 2024 09:33:12 +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 BNwpFdjX1maaegAAD6G6ig (envelope-from ) for ; Tue, 03 Sep 2024 09:33:12 +0000 Date: Tue, 3 Sep 2024 11:32:56 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: Also lower SLP grouped loads with just one consumer MIME-Version: 1.0 Message-Id: <20240903093312.5D41A13A52@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]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] 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, 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.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 This makes sure to produce interleaving schemes or load-lanes for single-element interleaving and other permutes that otherwise would use more than three vectors. It exposes the latent issue that single-element interleaving with large gaps can be inefficient - the mitigation in get_group_load_store_type doesn't trigger when we clear the load permutation. It also exposes the fact that not all permutes can be lowered in the best way in a vector length agnostic way so I've added an exception to keep power-of-two size contiguous aligned chunks unlowered (unless we want load-lanes). The optimal handling of load/store vectorization is going to continue to be a learning process. Bootstrap and regtest running on x86_64-unknown-linux-gnu. * tree-vect-slp.cc (vect_lower_load_permutations): Also process single-use grouped loads. Avoid lowering contiguous aligned power-of-two sized chunks, those are better handled by the vector size specific SLP code generation. * tree-vect-stmts.c (get_group_load_store_type): Drop the unrelated requirement of a load permutation for the single-element interleaving limit. --- gcc/tree-vect-slp.cc | 54 ++++++++++++++++++++++++++++-------------- gcc/tree-vect-stmts.cc | 1 - 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 1342913affa..1dc5888e92a 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -4312,6 +4312,35 @@ vect_lower_load_permutations (loop_vec_info loop_vinfo, && ld_lanes_lanes == 0) continue; + /* Build the permute to get the original load permutation order. */ + bool contiguous = true; + lane_permutation_t final_perm; + final_perm.create (SLP_TREE_LANES (load)); + for (unsigned i = 0; i < SLP_TREE_LANES (load); ++i) + { + final_perm.quick_push + (std::make_pair (0, SLP_TREE_LOAD_PERMUTATION (load)[i])); + if (i != 0 + && (SLP_TREE_LOAD_PERMUTATION (load)[i] + != SLP_TREE_LOAD_PERMUTATION (load)[i-1] + 1)) + contiguous = false; + } + + /* When the load permutation accesses a contiguous unpermuted, + power-of-two aligned and sized chunk leave the load alone. + We can likely (re-)load it more efficiently rather than + extracting it from the larger load. + ??? Long-term some of the lowering should move to where + the vector types involved are fixed. */ + if (ld_lanes_lanes == 0 + && pow2p_hwi (SLP_TREE_LANES (load)) + && SLP_TREE_LOAD_PERMUTATION (load)[0] % SLP_TREE_LANES (load) == 0 + && group_lanes % SLP_TREE_LANES (load) == 0) + { + final_perm.release (); + continue; + } + /* First build (and possibly re-use) a load node for the unpermuted group. Gaps in the middle and on the end are represented with NULL stmts. */ @@ -4335,13 +4364,6 @@ vect_lower_load_permutations (loop_vec_info loop_vinfo, &max_nunits, matches, &limit, &tree_size, bst_map); - /* Build the permute to get the original load permutation order. */ - lane_permutation_t final_perm; - final_perm.create (SLP_TREE_LANES (load)); - for (unsigned i = 0; i < SLP_TREE_LANES (load); ++i) - final_perm.quick_push - (std::make_pair (0, SLP_TREE_LOAD_PERMUTATION (load)[i])); - if (ld_lanes_lanes != 0) { /* ??? If this is not in sync with what get_load_store_type @@ -4500,20 +4522,16 @@ vect_lower_load_permutations (loop_vec_info loop_vinfo, && STMT_VINFO_GROUPED_ACCESS (b0) && DR_GROUP_FIRST_ELEMENT (a0) == DR_GROUP_FIRST_ELEMENT (b0)) continue; - /* Just one SLP load of a possible group, leave those alone. */ - if (i == firsti + 1) - { - firsti = i; - continue; - } - /* Now we have multiple SLP loads of the same group from + /* Now we have one or multiple SLP loads of the same group from firsti to i - 1. */ - vect_lower_load_permutations (loop_vinfo, bst_map, - make_array_slice (&loads[firsti], - i - firsti)); + if (STMT_VINFO_GROUPED_ACCESS (a0)) + vect_lower_load_permutations (loop_vinfo, bst_map, + make_array_slice (&loads[firsti], + i - firsti)); firsti = i; } - if (firsti < loads.length () - 1) + if (firsti < loads.length () + && STMT_VINFO_GROUPED_ACCESS (SLP_TREE_SCALAR_STMTS (loads[firsti])[0])) vect_lower_load_permutations (loop_vinfo, bst_map, make_array_slice (&loads[firsti], loads.length () - firsti)); diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index ace1c8eaa0d..e509ab506ef 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -2186,7 +2186,6 @@ get_group_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, blow up memory, see PR65518). */ if (loop_vinfo && *memory_access_type == VMAT_CONTIGUOUS - && SLP_TREE_LOAD_PERMUTATION (slp_node).exists () && single_element_p && maybe_gt (group_size, TYPE_VECTOR_SUBPARTS (vectype))) {