From patchwork Mon May 13 10:34:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1934664 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=cV9E08oN; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=z27804M5; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vMvJKjkg; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=SguwTghx; 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 4VdG863Dsdz1ymw for ; Mon, 13 May 2024 20:34:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2ECCE38708A8 for ; Mon, 13 May 2024 10:34:41 +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 20DF43861893 for ; Mon, 13 May 2024 10:34:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20DF43861893 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 20DF43861893 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=1715596461; cv=none; b=a7rnHQowq0+VsgCDGaYqiNh3Qzm3HjrNwRWc5KiMsvxodpKW7AxV8X17HUQHqX33Oc4HaNEe4jBa9yInG392qsezHHbqQsDyG+cp8uKeJ446M9IgYkTlsGy9p8HUKJHjEQ5CtXRKNUiuEP388SV2st1kuQciOxPMIkNWEKcUh68= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715596461; c=relaxed/simple; bh=uB0fYNDMZC+I7uFZnQfzpMF0axbjCTwC61bDtmfARZg=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=f/Ehf4+MLM15iRUOQXWAso8uQf9GrxGB1wmGMVkRwewGfh1cTgJiEKUwB9+Q5nGmD2Men6+3fSME5mz4TQxRM8d62tMCGsTn4/2okSFnHs6aZsZChMJ3lJjoACJ6mjEVgec4dGpbsqDiDU3X5/3HvYKF9L93WHdViWP5ZLqQzXU= ARC-Authentication-Results: i=1; server2.sourceware.org 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 E871434306 for ; Mon, 13 May 2024 10:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715596458; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8bhXoiKRuX1kG7foDCc/gud9BtgQqnTCAl5X29k0yz8=; b=cV9E08oNKSntr/4YR/pCp2xl9rpOELL+YA0+bcVhms++vgA0e1k3vOqC0YLNREYPID7sMd R2V9e2qtiDm0KP27M/S2O6PLHUfcTQ5RgtpOITKZjt9Dd8Aj3H2UxaZIvG0axmy9MktfrX 8BuqK6tF3KkZbKgaxrRUlUOyYY7oxPM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715596458; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8bhXoiKRuX1kG7foDCc/gud9BtgQqnTCAl5X29k0yz8=; b=z27804M5k6pjUJWZZPqozgihiuytO12GQnjXWsWx/Ws0fnr4ma5gpHHj3UiYa6R0aJE5nq ecg+AAvR1sUmZfCA== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715596457; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8bhXoiKRuX1kG7foDCc/gud9BtgQqnTCAl5X29k0yz8=; b=vMvJKjkg0YPR5xcpdOM9rhUGvHD8ED0ZR5x+piBJ10OmRWtXP1oMu/R31uAvQbgq94lf1D vdfWyWPCCesdHUF0s38oXIRwaCXO9m+BwZHWyqsjG1P2LRA/idKoKwP2hLVrwMTM8dzNXn HEwlhLndLgmMxuB+d2UjhLijQiz5vik= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715596457; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=8bhXoiKRuX1kG7foDCc/gud9BtgQqnTCAl5X29k0yz8=; b=SguwTghxY+uXIMxbs10aanN9XB6RBHFLJd0QuklxARhLPqzHdoB/qxByZXgxRtDwnW8afE J35bG5YQzO8DjhBg== Date: Mon, 13 May 2024 12:34:17 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Refactor SLP reduction group discovery MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [0.07 / 50.00]; MISSING_MID(2.50)[]; BAYES_HAM(-1.18)[88.98%]; NEURAL_HAM_LONG(-0.95)[-0.949]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_NONE(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[] X-Spam-Score: 0.07 X-Spam-Status: No, score=-10.4 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240513103441.2ECCE38708A8@sourceware.org> The following refactors a bit how we perform SLP reduction group discovery possibly making it easier to have multiple reduction groups later, esp. with single-lane SLP. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * tree-vect-slp.cc (vect_analyze_slp_instance): Remove slp_inst_kind_reduc_group handling. (vect_analyze_slp): Add the meat here. --- gcc/tree-vect-slp.cc | 67 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 8c18f5308e2..f34ed54a70b 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -3586,7 +3586,6 @@ vect_analyze_slp_instance (vec_info *vinfo, slp_instance_kind kind, unsigned max_tree_size, unsigned *limit) { - unsigned int i; vec scalar_stmts; if (is_a (vinfo)) @@ -3620,35 +3619,6 @@ vect_analyze_slp_instance (vec_info *vinfo, STMT_VINFO_REDUC_DEF (vect_orig_stmt (stmt_info)) = STMT_VINFO_REDUC_DEF (vect_orig_stmt (scalar_stmts.last ())); } - else if (kind == slp_inst_kind_reduc_group) - { - /* Collect reduction statements. */ - const vec &reductions - = as_a (vinfo)->reductions; - scalar_stmts.create (reductions.length ()); - for (i = 0; reductions.iterate (i, &next_info); i++) - { - gassign *g; - next_info = vect_stmt_to_vectorize (next_info); - if ((STMT_VINFO_RELEVANT_P (next_info) - || STMT_VINFO_LIVE_P (next_info)) - /* ??? Make sure we didn't skip a conversion around a reduction - path. In that case we'd have to reverse engineer that - conversion stmt following the chain using reduc_idx and from - the PHI using reduc_def. */ - && STMT_VINFO_DEF_TYPE (next_info) == vect_reduction_def - /* Do not discover SLP reductions for lane-reducing ops, that - will fail later. */ - && (!(g = dyn_cast (STMT_VINFO_STMT (next_info))) - || (gimple_assign_rhs_code (g) != DOT_PROD_EXPR - && gimple_assign_rhs_code (g) != WIDEN_SUM_EXPR - && gimple_assign_rhs_code (g) != SAD_EXPR))) - scalar_stmts.quick_push (next_info); - } - /* If less than two were relevant/live there's nothing to SLP. */ - if (scalar_stmts.length () < 2) - return false; - } else gcc_unreachable (); @@ -3740,9 +3710,40 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size) /* Find SLP sequences starting from groups of reductions. */ if (loop_vinfo->reductions.length () > 1) - vect_analyze_slp_instance (vinfo, bst_map, loop_vinfo->reductions[0], - slp_inst_kind_reduc_group, max_tree_size, - &limit); + { + /* Collect reduction statements. */ + vec scalar_stmts; + scalar_stmts.create (loop_vinfo->reductions.length ()); + for (auto next_info : loop_vinfo->reductions) + { + gassign *g; + next_info = vect_stmt_to_vectorize (next_info); + if ((STMT_VINFO_RELEVANT_P (next_info) + || STMT_VINFO_LIVE_P (next_info)) + /* ??? Make sure we didn't skip a conversion around a + reduction path. In that case we'd have to reverse + engineer that conversion stmt following the chain using + reduc_idx and from the PHI using reduc_def. */ + && STMT_VINFO_DEF_TYPE (next_info) == vect_reduction_def + /* Do not discover SLP reductions for lane-reducing ops, that + will fail later. */ + && (!(g = dyn_cast (STMT_VINFO_STMT (next_info))) + || (gimple_assign_rhs_code (g) != DOT_PROD_EXPR + && gimple_assign_rhs_code (g) != WIDEN_SUM_EXPR + && gimple_assign_rhs_code (g) != SAD_EXPR))) + scalar_stmts.quick_push (next_info); + } + if (scalar_stmts.length () > 1) + { + vec roots = vNULL; + vec remain = vNULL; + vect_build_slp_instance (loop_vinfo, slp_inst_kind_reduc_group, + scalar_stmts, roots, remain, + max_tree_size, &limit, bst_map, NULL); + } + else + scalar_stmts.release (); + } } hash_set visited_patterns;