From patchwork Thu Jun 27 09:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1953104 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=LStotBQc; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=fV+Ltc4a; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=LStotBQc; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=fV+Ltc4a; 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 4W8tr36wRSz20XB for ; Thu, 27 Jun 2024 19:41:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2E46B3834686 for ; Thu, 27 Jun 2024 09:41:38 +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 72ACF3834695 for ; Thu, 27 Jun 2024 09:41:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72ACF3834695 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 72ACF3834695 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=1719481270; cv=none; b=VrXq0p6rftXOegxOQA5R3e+W46d2vhE1mDST7YaDCelqHTQgsATyIUv8Rh0PGa/qHaBXsAs5SwNlvg0BNbeRbBdfUBUiMj0CCcPMOh+pqASyJrpY+iHipy9b63spMC7uiGmt/8p4K3N+XGIjkai/FaaGZ/euANiy99QhdjRqK+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719481270; c=relaxed/simple; bh=G+6vABjonVx/6FUYAiNY/z/hZj6VGrdfnZzZK1NNx24=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=dmaMzQXvgFPiWjFh+2UbynbTQj2fFggmtgjTx6UF7N2nugsEYpjpvgkGQYM5EGL3obLqPRCgcLmyxXrY189sVh1jAPunijrc5uYRe0ZJpPAWFAZMadDk/Fnlh7Q8AQAgxwfR/FWlLA+fYIe52aUV+oCZhFhO7A9y6VOXNBanF8M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104: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 8430E1FBB6 for ; Thu, 27 Jun 2024 09:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719481267; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=jbLtvl4mVNFlMcM0tySEbLRhNT46yNNRCwbdFy+NEWU=; b=LStotBQc4LqNXb4hkD8GFk5QwJQNx/OYpfNb6ubMO4D3Pnoivy7U6O3nBAeHOHc3p+wEz6 k1w3cx8UhHQlJQpvFrBLFK1F7qg0+6CzAS4z44P49/u6qBIlC/aqnXz7LvNPt97a58Sheb 6b3apRFLVk7l4zDbzi2YUxgcmacUWNc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719481267; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=jbLtvl4mVNFlMcM0tySEbLRhNT46yNNRCwbdFy+NEWU=; b=fV+Ltc4ag3bPPfU4XgGa3+Di/UmiIAOZXrPq3faaBi/LxcQ6lXJ4cetCkzEL/vCRm1DvPH 0IblZTyLaas7P2Bw== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=LStotBQc; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=fV+Ltc4a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719481267; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=jbLtvl4mVNFlMcM0tySEbLRhNT46yNNRCwbdFy+NEWU=; b=LStotBQc4LqNXb4hkD8GFk5QwJQNx/OYpfNb6ubMO4D3Pnoivy7U6O3nBAeHOHc3p+wEz6 k1w3cx8UhHQlJQpvFrBLFK1F7qg0+6CzAS4z44P49/u6qBIlC/aqnXz7LvNPt97a58Sheb 6b3apRFLVk7l4zDbzi2YUxgcmacUWNc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719481267; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=jbLtvl4mVNFlMcM0tySEbLRhNT46yNNRCwbdFy+NEWU=; b=fV+Ltc4ag3bPPfU4XgGa3+Di/UmiIAOZXrPq3faaBi/LxcQ6lXJ4cetCkzEL/vCRm1DvPH 0IblZTyLaas7P2Bw== 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 610341384C for ; Thu, 27 Jun 2024 09:41:07 +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 /KckFrMzfWZBHwAAD6G6ig (envelope-from ) for ; Thu, 27 Jun 2024 09:41:07 +0000 Date: Thu, 27 Jun 2024 11:41:06 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] Harden SLP reduction support wrt STMT_VINFO_REDUC_IDX MIME-Version: 1.0 Message-Id: <20240627094107.610341384C@imap1.dmz-prg2.suse.org> X-Spamd-Result: default: False [-6.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; DWL_DNSWL_MED(-2.00)[suse.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; 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)[]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 8430E1FBB6 X-Spam-Score: -6.51 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 makes sure that for a SLP reductions all lanes have the same STMT_VINFO_REDUC_IDX. Once we move that info and can adjust it we can implement swapping. It also makes the existing protection against operand swapping trigger for all stmts participating in a reduction, not just the final one marked as reduction-def. * tree-vect-slp.cc (vect_build_slp_tree_1): Compare STMT_VINFO_REDUC_IDX. (vect_build_slp_tree_2): Prevent operand swapping for all stmts participating in a reduction. --- gcc/tree-vect-slp.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index cb8604eb611..db006661296 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -1072,6 +1072,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, stmt_vec_info first_load = NULL, prev_first_load = NULL; bool first_stmt_ldst_p = false, ldst_p = false; bool first_stmt_phi_p = false, phi_p = false; + int first_reduc_idx = -1; bool maybe_soft_fail = false; tree soft_fail_nunits_vectype = NULL_TREE; @@ -1204,6 +1205,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, first_stmt_code = rhs_code; first_stmt_ldst_p = ldst_p; first_stmt_phi_p = phi_p; + first_reduc_idx = STMT_VINFO_REDUC_IDX (stmt_info); /* Shift arguments should be equal in all the packed stmts for a vector shift with scalar shift operand. */ @@ -1267,6 +1269,19 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, } else { + if (first_reduc_idx != STMT_VINFO_REDUC_IDX (stmt_info)) + { + if (dump_enabled_p ()) + { + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "Build SLP failed: different reduc_idx " + "%d instead of %d in %G", + STMT_VINFO_REDUC_IDX (stmt_info), + first_reduc_idx, stmt); + } + /* Mismatch. */ + continue; + } if (first_stmt_code != rhs_code && alt_stmt_code == ERROR_MARK) alt_stmt_code = rhs_code; @@ -2535,8 +2550,7 @@ out: && oprnds_info[1]->first_dt == vect_internal_def && is_gimple_assign (stmt_info->stmt) /* Swapping operands for reductions breaks assumptions later on. */ - && STMT_VINFO_DEF_TYPE (stmt_info) != vect_reduction_def - && STMT_VINFO_DEF_TYPE (stmt_info) != vect_double_reduction_def) + && STMT_VINFO_REDUC_IDX (stmt_info) != -1) { /* See whether we can swap the matching or the non-matching stmt operands. */