From patchwork Mon Sep 15 13:15:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 120282 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D5FAC3858C24 for ; Mon, 15 Sep 2025 13:40:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D5FAC3858C24 Authentication-Results: sourceware.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=vtgYFvCb; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UpPM6Jt6; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vtgYFvCb; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UpPM6Jt6 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 7F3803858C83 for ; Mon, 15 Sep 2025 13:16:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F3803858C83 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 7F3803858C83 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=1757942160; cv=none; b=C92Xrcyi4AS9HoTvCjzPHE/HhugYHg5jS5Ir++6WO9nrEDY6ZZxROZgNusnw/aJwPjqO/DGnX7yNTvCyeuR5KLZpjX0EW0z7FJ2K/fTCE+d+WVQIXbTMitp/elJfR7I4znmmNHV+VGS6bGHRNaibJ+upCO2/VEMWGFJk1uA1Qfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1757942160; c=relaxed/simple; bh=1tL+88H5zDQhBjAorwi/cIA/IR/CDr3zpAHmn7MAOkc=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=ELIx3nX3sNXKeejdu0HYk/rRVvNDxGOVLNPt+RUaMkYThs9ICAqCt09/ioINJZeYqzKY2+TXpFKO9M5A23qtSpxVco+qkkDV/ZqhPDdUwxCqBvQo1yPrf7YSTUlD0uhEQBU1nwicIIfMdSgmkd8S9DH9nQ+k6eZ4vMGXpIPBJbs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F3803858C83 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 6708B21904; Mon, 15 Sep 2025 13:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1757942159; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=e81kgQmGdaB5GQZge89VA0AfGN5cCNUeUuNJ8ZDzND0=; b=vtgYFvCb2GxfwWZHn5sC+wTMZjJDZMcYm81gTFJGAuxOilpic118dzAqFM8I1cSpZg4vVh SJSCsri0+lVve5U6BFxWLvNZabOAHpNDHlweBW/LrIVx/UfqVrlBU3u8P70ih1uVdM/UgL hPcjx/iZzaeChyvYlWPBTMhvSNyCPGQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1757942159; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=e81kgQmGdaB5GQZge89VA0AfGN5cCNUeUuNJ8ZDzND0=; b=UpPM6Jt6BmSMJG5qeX9p37y8ewzJMYBmwLSE6OC8/byCU98hf9Zt8B7JJeDyX3axF4P41r OBS6P7sfgv3ZhtBg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1757942159; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=e81kgQmGdaB5GQZge89VA0AfGN5cCNUeUuNJ8ZDzND0=; b=vtgYFvCb2GxfwWZHn5sC+wTMZjJDZMcYm81gTFJGAuxOilpic118dzAqFM8I1cSpZg4vVh SJSCsri0+lVve5U6BFxWLvNZabOAHpNDHlweBW/LrIVx/UfqVrlBU3u8P70ih1uVdM/UgL hPcjx/iZzaeChyvYlWPBTMhvSNyCPGQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1757942159; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=e81kgQmGdaB5GQZge89VA0AfGN5cCNUeUuNJ8ZDzND0=; b=UpPM6Jt6BmSMJG5qeX9p37y8ewzJMYBmwLSE6OC8/byCU98hf9Zt8B7JJeDyX3axF4P41r OBS6P7sfgv3ZhtBg== Date: Mon, 15 Sep 2025 15:15:59 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: RISC-V CI Subject: [PATCH] Unify last two vect_transform_slp_perm_load calls MIME-Version: 1.0 X-Spamd-Result: default: False [-1.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.987]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; TO_DN_SOME(0.00)[] X-Spam-Level: X-Spam-Score: -1.80 X-Spam-Status: No, score=-10.7 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~patchwork=sourceware.org@gcc.gnu.org Message-Id: <20250915134012.D5FAC3858C24@sourceware.org> The following unifies the vect_transform_slp_perm_load call done in vectorizable_load with that eventually done in get_load_store_type. On the way it fixes the conditions on which we can allow VMAT_ELEMENTWISE or VMAT_GATHER_SCATTER when there's a SLP permutation (and we arrange to not code generate that). In particular that only works for single-lane SLP of non-grouped loads or groups of size one. VMAT_ELEMENTWISE does not (yet?) materialize a permutation upon vector build but still relies on vect_transform_slp_perm_load. Bootstrapped and tested on x86_64-unknown-linux-gnu. * tree-vect-stmts.cc (get_load_store_type): Get in a flag whether a SLP_TREE_LOAD_PERMUTATION on the node can be code generated and use it. Fix the condition on using strided gather/scatter to avoid dropping a meaningful permutation. (vectorizable_store): Adjust. (vectorizable_load): Analyze the permutation early and pass the result down to get_load_store_type. Fix the condition on when we are allowed to elide a load permutation. --- gcc/tree-vect-stmts.cc | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index d46c1e3d56d..6274956e2a5 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -1963,13 +1963,16 @@ vector_vector_composition_type (tree vtype, poly_uint64 nelts, tree *ptype) VECTYPE is the vector type that the vectorized statements will use. If ELSVALS is nonzero the supported else values will be stored in the - vector ELSVALS points to. */ + vector ELSVALS points to. + + For loads PERM_OK indicates whether we can code generate a + SLP_TREE_LOAD_PERMUTATION on the node. */ static bool get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, tree vectype, slp_tree slp_node, bool masked_p, vec_load_store_type vls_type, - vect_load_store_data *ls) + bool perm_ok, vect_load_store_data *ls) { vect_memory_access_type *memory_access_type = &ls->memory_access_type; poly_int64 *poffset = &ls->poffset; @@ -2153,17 +2156,13 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, /* For single-element interleaving also fall back to elementwise access in case we did not lower a permutation and cannot code generate it. */ - auto_vec temv; - unsigned n_perms; if (loop_vinfo && single_element_p && SLP_TREE_LANES (slp_node) == 1 && (*memory_access_type == VMAT_CONTIGUOUS || *memory_access_type == VMAT_CONTIGUOUS_REVERSE) && SLP_TREE_LOAD_PERMUTATION (slp_node).exists () - && !vect_transform_slp_perm_load - (loop_vinfo, slp_node, temv, NULL, - LOOP_VINFO_VECT_FACTOR (loop_vinfo), true, &n_perms)) + && !perm_ok) { *memory_access_type = VMAT_ELEMENTWISE; if (dump_enabled_p ()) @@ -2314,11 +2313,13 @@ get_load_store_type (vec_info *vinfo, stmt_vec_info stmt_info, on nearby locations. Or, even if it's a win over scalar code, it might not be a win over vectorizing at a lower VF, if that allows us to use contiguous accesses. */ - if ((*memory_access_type == VMAT_ELEMENTWISE - || *memory_access_type == VMAT_STRIDED_SLP) + if (loop_vinfo + && (*memory_access_type == VMAT_ELEMENTWISE + || *memory_access_type == VMAT_STRIDED_SLP) && !STMT_VINFO_GATHER_SCATTER_P (stmt_info) && SLP_TREE_LANES (slp_node) == 1 - && loop_vinfo) + && (!SLP_TREE_LOAD_PERMUTATION (slp_node).exists () + || single_element_p)) { gather_scatter_info gs_info; if (vect_use_strided_gather_scatters_p (stmt_info, vectype, loop_vinfo, @@ -7881,7 +7882,7 @@ vectorizable_store (vec_info *vinfo, vect_load_store_data &ls = slp_node->get_data (_ls_data); if (cost_vec && !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node, - vls_type, &_ls_data)) + vls_type, false, &_ls_data)) return false; /* Temporary aliases to analysis data, should not be modified through these. */ @@ -9447,11 +9448,17 @@ vectorizable_load (vec_info *vinfo, else group_size = 1; + bool perm_ok = true; + unsigned n_perms = -1U; + if (cost_vec && SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()) + perm_ok = vect_transform_slp_perm_load (vinfo, slp_node, vNULL, NULL, vf, + true, &n_perms); + vect_load_store_data _ls_data{}; vect_load_store_data &ls = slp_node->get_data (_ls_data); if (cost_vec && !get_load_store_type (vinfo, stmt_info, vectype, slp_node, mask_node, - VLS_LOAD, &ls)) + VLS_LOAD, perm_ok, &ls)) return false; /* Temporary aliases to analysis data, should not be modified through these. */ @@ -9474,11 +9481,12 @@ vectorizable_load (vec_info *vinfo, /* ??? The following checks should really be part of get_load_store_type. */ - unsigned n_perms = -1U; if (SLP_TREE_LOAD_PERMUTATION (slp_node).exists () && !((memory_access_type == VMAT_ELEMENTWISE || mat_gather_scatter_p (memory_access_type)) - && SLP_TREE_LANES (slp_node) == 1)) + && SLP_TREE_LANES (slp_node) == 1 + && (!grouped_load + || !DR_GROUP_NEXT_ELEMENT (first_stmt_info)))) { slp_perm = true; @@ -9507,8 +9515,7 @@ vectorizable_load (vec_info *vinfo, if (cost_vec) { - if (!vect_transform_slp_perm_load (vinfo, slp_node, vNULL, NULL, vf, - true, &n_perms)) + if (!perm_ok) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION,