From patchwork Fri Jun 28 14:11:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1953961 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=T6vp2QAa; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=wubRVtj3; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=T6vp2QAa; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=wubRVtj3; 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 4W9cnC5qp1z1yhT for ; Sat, 29 Jun 2024 00:11:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5CB63826DC4 for ; Fri, 28 Jun 2024 14:11:40 +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 AD158388461C for ; Fri, 28 Jun 2024 14:11:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD158388461C 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 AD158388461C 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=1719583877; cv=none; b=qwtCRpPyO775RubjXqYXVBtT2mcWFDul0MN0ZtMKdsleK4SkoTI1//66rjP/aAlQUNLZ2NkYCYtSpHGyGSIO8xvtdcfc/kHoOSl/nL8coUYzoZhsqdqksnZ2Y1r9zZa+8tk6bC0F/cMmnhJ6VUq+9/PTWaJIR/BPAePZVyvKkh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719583877; c=relaxed/simple; bh=Bj2s3eFhf7zcHTaxT0MF5nRqKKJ0Y05bjCZpxNV5JkM=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=CTrTcaXOVvYj4cQnzwBTV7gS/mR7vPw2RCBfQka06Dr9CUHj9OFO9Z7bqxW9AqGQZGqJ8bo5DcjoZ0/U9jLYLnERwrCMIfAocp7ydsZFiN5y2EuEyhlRHkgzqIPbTz39sTodYt0o6T3sgLJR+73ywXyaK+49zaCQGWzJpfUPwkw= 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 701D621BD3 for ; Fri, 28 Jun 2024 14:11:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719583873; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=FaK1er+tqfM/3UwQRoWn0tqdvFWoD1qxo1OqtbcZB58=; b=T6vp2QAa7EblkBCNMpgkqcqdt/W+mLMW/I9KmfI4Ufe8LpLzKyuLjbMM/EJPILd8ZtP541 miCG2tXSz7FpQpgqY0g6LFer7zmqVoHNsU1Mdp2BVFctasfB78FR9m3CoWtgtl74Mqd6QJ b1Pz/wcwXrfrhxDvCrqi9ThXB7U/4s0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719583873; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=FaK1er+tqfM/3UwQRoWn0tqdvFWoD1qxo1OqtbcZB58=; b=wubRVtj3KiMjrGtQTEl6DYLh9HWzuATwvs7KSAwvsv5fpwf+ZQ6o1F6U1InK9Lm5Y8BVAv xRBSBuiG/Xy+v5CA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719583873; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=FaK1er+tqfM/3UwQRoWn0tqdvFWoD1qxo1OqtbcZB58=; b=T6vp2QAa7EblkBCNMpgkqcqdt/W+mLMW/I9KmfI4Ufe8LpLzKyuLjbMM/EJPILd8ZtP541 miCG2tXSz7FpQpgqY0g6LFer7zmqVoHNsU1Mdp2BVFctasfB78FR9m3CoWtgtl74Mqd6QJ b1Pz/wcwXrfrhxDvCrqi9ThXB7U/4s0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719583873; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=FaK1er+tqfM/3UwQRoWn0tqdvFWoD1qxo1OqtbcZB58=; b=wubRVtj3KiMjrGtQTEl6DYLh9HWzuATwvs7KSAwvsv5fpwf+ZQ6o1F6U1InK9Lm5Y8BVAv xRBSBuiG/Xy+v5CA== 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 5635C13375 for ; Fri, 28 Jun 2024 14:11:13 +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 np5cE4HEfmbnDQAAD6G6ig (envelope-from ) for ; Fri, 28 Jun 2024 14:11:13 +0000 Date: Fri, 28 Jun 2024 16:11:12 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] RISC-V: Handle NULL stmt in SLP_TREE_SCALAR_STMTS MIME-Version: 1.0 Message-Id: <20240628141113.5635C13375@imap1.dmz-prg2.suse.org> 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)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[tree-vect-slp.cc:url] X-Spam-Score: -4.30 X-Spam-Level: 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 starts to handle NULL elements in SLP_TREE_SCALAR_STMTS with the first candidate being the two-operator nodes where some lanes are do-not-care and also do not have a scalar stmt computing the result. I've sofar whack-a-moled the vect.exp testsuite. I do plan to use NULL elements for loads from groups with gaps where we get around not doing that by having a load permutation. I want to separate changing places where I have coverage from those I do not. So this is for the CI and I'll followup with patching up all remaining iterations over SLP_TREE_SCALAR_STMTS. * tree-vect-slp.cc (vect_build_slp_tree_2): Make two-operator nodes have SLP_TREE_SCALAR_STMTS with do-not-care lanes NULL. (bst_traits::hash): Handle NULL elements in SLP_TREE_SCALAR_STMTS. (vect_print_slp_tree): Likewise. (vect_mark_slp_stmts): Likewise. (vect_mark_slp_stmts_relevant): Likewise. (vect_find_last_scalar_stmt_in_slp): Likewise. (vect_bb_slp_mark_live_stmts): Likewise. (vect_slp_prune_covered_roots): Likewise. (vect_bb_partition_graph_r): Likewise. (vect_remove_slp_scalar_calls): Likewise. * tree-vect-stmts.cc (can_vectorize_live_stmts): Likewise. --- gcc/tree-vect-slp.cc | 56 ++++++++++++++++++++++++++++-------------- gcc/tree-vect-stmts.cc | 11 +++++---- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index dd9017e5b3a..47664158e57 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -1571,7 +1571,7 @@ bst_traits::hash (value_type x) { inchash::hash h; for (unsigned i = 0; i < x.length (); ++i) - h.add_int (gimple_uid (x[i]->stmt)); + h.add_int (x[i] ? gimple_uid (x[i]->stmt) : -1); return h.end (); } inline bool @@ -2702,6 +2702,8 @@ fail: SLP_TREE_VECTYPE (two) = vectype; SLP_TREE_CHILDREN (one).safe_splice (children); SLP_TREE_CHILDREN (two).safe_splice (children); + SLP_TREE_SCALAR_STMTS (one).create (stmts.length ()); + SLP_TREE_SCALAR_STMTS (two).create (stmts.length ()); slp_tree child; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (two), i, child) SLP_TREE_REF_COUNT (child)++; @@ -2726,9 +2728,15 @@ fail: SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (1, i)); ocode = gimple_assign_rhs_code (ostmt); j = i; + SLP_TREE_SCALAR_STMTS (one).quick_push (NULL); + SLP_TREE_SCALAR_STMTS (two).quick_push (stmts[i]); } else - SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (0, i)); + { + SLP_TREE_LANE_PERMUTATION (node).safe_push (std::make_pair (0, i)); + SLP_TREE_SCALAR_STMTS (one).quick_push (stmts[i]); + SLP_TREE_SCALAR_STMTS (two).quick_push (NULL); + } } SLP_TREE_CODE (one) = code0; SLP_TREE_CODE (two) = ocode; @@ -2781,9 +2789,12 @@ vect_print_slp_tree (dump_flags_t dump_kind, dump_location_t loc, } if (SLP_TREE_SCALAR_STMTS (node).exists ()) FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - dump_printf_loc (metadata, user_loc, "\t%sstmt %u %G", - STMT_VINFO_LIVE_P (stmt_info) ? "[l] " : "", - i, stmt_info->stmt); + if (stmt_info) + dump_printf_loc (metadata, user_loc, "\t%sstmt %u %G", + STMT_VINFO_LIVE_P (stmt_info) ? "[l] " : "", + i, stmt_info->stmt); + else + dump_printf_loc (metadata, user_loc, "\tstmt %u ---\n"); else { dump_printf_loc (metadata, user_loc, "\t{ "); @@ -2924,7 +2935,8 @@ vect_mark_slp_stmts (slp_tree node, hash_set &visited) return; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - STMT_SLP_TYPE (stmt_info) = pure_slp; + if (stmt_info) + STMT_SLP_TYPE (stmt_info) = pure_slp; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) if (child) @@ -2954,11 +2966,12 @@ vect_mark_slp_stmts_relevant (slp_tree node, hash_set &visited) return; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - { - gcc_assert (!STMT_VINFO_RELEVANT (stmt_info) - || STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_scope); - STMT_VINFO_RELEVANT (stmt_info) = vect_used_in_scope; - } + if (stmt_info) + { + gcc_assert (!STMT_VINFO_RELEVANT (stmt_info) + || STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_scope); + STMT_VINFO_RELEVANT (stmt_info) = vect_used_in_scope; + } FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) if (child) @@ -3009,10 +3022,11 @@ vect_find_last_scalar_stmt_in_slp (slp_tree node) stmt_vec_info stmt_vinfo; for (int i = 0; SLP_TREE_SCALAR_STMTS (node).iterate (i, &stmt_vinfo); i++) - { - stmt_vinfo = vect_orig_stmt (stmt_vinfo); - last = last ? get_later_stmt (stmt_vinfo, last) : stmt_vinfo; - } + if (stmt_vinfo) + { + stmt_vinfo = vect_orig_stmt (stmt_vinfo); + last = last ? get_later_stmt (stmt_vinfo, last) : stmt_vinfo; + } return last; } @@ -6895,7 +6909,7 @@ vect_bb_slp_mark_live_stmts (bb_vec_info bb_vinfo, slp_tree node, stmt_vec_info last_stmt = vect_find_last_scalar_stmt_in_slp (node); FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) { - if (svisited.contains (stmt_info)) + if (!stmt_info || svisited.contains (stmt_info)) continue; stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info); if (STMT_VINFO_IN_PATTERN_P (orig_stmt_info) @@ -7084,7 +7098,8 @@ vect_slp_prune_covered_roots (slp_tree node, hash_set &roots, stmt_vec_info stmt; unsigned i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt) - roots.remove (vect_orig_stmt (stmt)); + if (stmt) + roots.remove (vect_orig_stmt (stmt)); slp_tree child; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) @@ -7260,8 +7275,9 @@ vect_bb_partition_graph_r (bb_vec_info bb_vinfo, unsigned i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) - vect_map_to_instance (instance, stmt_info, stmt_to_instance, - instance_leader); + if (stmt_info) + vect_map_to_instance (instance, stmt_info, stmt_to_instance, + instance_leader); if (vect_map_to_instance (instance, node, node_to_instance, instance_leader)) @@ -9824,6 +9840,8 @@ vect_remove_slp_scalar_calls (vec_info *vinfo, FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info) { + if (!stmt_info) + continue; gcall *stmt = dyn_cast (stmt_info->stmt); if (!stmt || gimple_bb (stmt) == NULL) continue; diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 7b889f31645..ec73b47b845 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -13081,11 +13081,12 @@ can_vectorize_live_stmts (vec_info *vinfo, stmt_vec_info stmt_info, unsigned int i; FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (slp_node), i, slp_stmt_info) { - if ((STMT_VINFO_LIVE_P (slp_stmt_info) - || (loop_vinfo - && LOOP_VINFO_EARLY_BREAKS (loop_vinfo) - && STMT_VINFO_DEF_TYPE (slp_stmt_info) - == vect_induction_def)) + if (slp_stmt_info + && (STMT_VINFO_LIVE_P (slp_stmt_info) + || (loop_vinfo + && LOOP_VINFO_EARLY_BREAKS (loop_vinfo) + && STMT_VINFO_DEF_TYPE (slp_stmt_info) + == vect_induction_def)) && !vectorizable_live_operation (vinfo, slp_stmt_info, slp_node, slp_node_instance, i, vec_stmt_p, cost_vec))