From patchwork Fri Sep 20 13:27:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1987905 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=2M0pugpQ; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=B+3M/emc; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=2M0pugpQ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=B+3M/emc; 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 4X9CrK1kgjz1y27 for ; Fri, 20 Sep 2024 23:28:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B3AC3858D35 for ; Fri, 20 Sep 2024 13:28:13 +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 [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id 3CC403858D29 for ; Fri, 20 Sep 2024 13:27:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CC403858D29 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 3CC403858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726838868; cv=none; b=ARuAGR7OV3fGwJND9bopK50rd53nyn0AkqzjK7cU37VcOKilLmUb9THlv44nFKUSbmnw4T8Bk9atpvSeWmDtbui6TrIsbTWL1NDJpC9Ppqj5Y3rcRomjr7RKXiTSF2Q/zS0z7WA2HtBHWWWuxmwNnGEMNC9/wcJzI01JYq9pQ9c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726838868; c=relaxed/simple; bh=qHb0OsIMtQObulj4KoO4fJ1CZyd0wO37g/wo8Sept7s=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=SOsJWd7qXgbdzrae80xPBW5FrcrkXam3q5zOtDD1shVQZC2TN5PKJVU17QV3XkXXONrthBKTu7riMo99fj0TfFIrRa1A/J5QDP8KxNcuYowSnRS7vEogGfjsHvblofMSEqDWFuLNBMC182+esU0+5eYaHkcD1lQxRvgH4rkd0Zs= 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 2791033A5B; Fri, 20 Sep 2024 13:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1726838865; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=J4BBVjTgH6e94r/UH1Lv1tDMb1MPOcKuh3LkcwvyycA=; b=2M0pugpQaPYiOJk9UlrBcd3PZiYF1TaPbLjzZZq3yLjEU5SXD7KMqD/d2JunOVUjZof+kh r//svVEWOFXwk6MU0/2h9k2WAekoMNUgaWdL36Owq+OCW7oU6C0GU/Mu0LcF8mcbBjsB8/ UrxZhXRh8aPdZxCsWZlq2H7RDHgmWy0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1726838865; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=J4BBVjTgH6e94r/UH1Lv1tDMb1MPOcKuh3LkcwvyycA=; b=B+3M/emcAPgcbuNuEciFQDDqvCTgJ5tTM1xCLrKzMTwUz6DJRF+8Il96oZvwjMUWppqpvK Ofo90Q2S515tVHBQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1726838865; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=J4BBVjTgH6e94r/UH1Lv1tDMb1MPOcKuh3LkcwvyycA=; b=2M0pugpQaPYiOJk9UlrBcd3PZiYF1TaPbLjzZZq3yLjEU5SXD7KMqD/d2JunOVUjZof+kh r//svVEWOFXwk6MU0/2h9k2WAekoMNUgaWdL36Owq+OCW7oU6C0GU/Mu0LcF8mcbBjsB8/ UrxZhXRh8aPdZxCsWZlq2H7RDHgmWy0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1726838865; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=J4BBVjTgH6e94r/UH1Lv1tDMb1MPOcKuh3LkcwvyycA=; b=B+3M/emcAPgcbuNuEciFQDDqvCTgJ5tTM1xCLrKzMTwUz6DJRF+8Il96oZvwjMUWppqpvK Ofo90Q2S515tVHBQ== 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 F049713AE1; Fri, 20 Sep 2024 13:27:44 +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 n/79OFB47WYVOwAAD6G6ig (envelope-from ); Fri, 20 Sep 2024 13:27:44 +0000 Date: Fri, 20 Sep 2024 15:27:36 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: richard.sandiford@arm.com Subject: [PATCH] tree-optimization/115372 - failed store-lanes in some cases MIME-Version: 1.0 Message-Id: <20240920132744.F049713AE1@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_TLS_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; 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, KAM_SHORT, 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 gcc.target/riscv/rvv/autovec/struct/struct_vect-4.c testcase shows that we sometimes fail to use store-lanes even though it should be profitable. We're currently relying on vect_slp_prefer_store_lanes_p at the point we run into the first SLP discovery mismatch with obviously limited information. For the case at hand we have 3, 5 or 7 lanes of VnDImode [2, 2] vectors with the first mismatch at lane 2 so the new group size is 1. The heuristic says that might be an OK split given the rest is a multiple of the vector lanes. Now we continue discovery but in the end mismatches result in uniformly single-lane SLP instances which we can handle via interleaving but of course are prime candidates for store-lanes. The following patch re-assesses with the extra knowledge now just relying on the fact whether the target supports store-lanes for the given group size. Bootstrap and regtest running on x86_64-unknown-linux-gnu; I'll be watching the CI for fallout. Richard. PR tree-optimization/115372 * tree-vect-slp.cc (vect_build_slp_instance): Compute the uniform, if, number of lanes of the RHS sub-graphs feeding the store and if uniformly one, use store-lanes if the target supports that. --- gcc/tree-vect-slp.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 9c817de18bd..fc918d47c00 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -3957,6 +3957,7 @@ vect_build_slp_instance (vec_info *vinfo, /* Calculate the unrolling factor based on the smallest type. */ poly_uint64 unrolling_factor = 1; + unsigned int rhs_common_nlanes = 0; unsigned int start = 0, end = i; while (start < group_size) { @@ -3978,6 +3979,10 @@ vect_build_slp_instance (vec_info *vinfo, calculate_unrolling_factor (max_nunits, end - start)); rhs_nodes.safe_push (node); + if (start == 0) + rhs_common_nlanes = SLP_TREE_LANES (node); + else if (rhs_common_nlanes != SLP_TREE_LANES (node)) + rhs_common_nlanes = 0; start = end; if (want_store_lanes || force_single_lane) end = start + 1; @@ -4015,6 +4020,15 @@ vect_build_slp_instance (vec_info *vinfo, } } + /* Now re-assess whether we want store lanes in case the + discovery ended up producing all single-lane RHSs. */ + if (rhs_common_nlanes == 1 + && vect_store_lanes_supported (SLP_TREE_VECTYPE (rhs_nodes[0]), + group_size, + SLP_TREE_CHILDREN + (rhs_nodes[0]).length () != 1)) + want_store_lanes = true; + /* Now we assume we can build the root SLP node from all stores. */ if (want_store_lanes) {