From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 84B2E3861893 for ; Mon, 13 May 2024 10:24:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84B2E3861893 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 84B2E3861893 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=1715595869; cv=none; b=HmR/ZYjpO/kTNIXHeojB94wS4+p6a/85CjYajCv2fg4uxkCGDoKoPcgUvBBNiMX1uX0djeT8YedB2pMVBqjUx21q72ZKeXos3b9vLt5eYxHG3FnKm+t76T9L8cr8GmdDHpVoIqTpWt+k9yJbsS2F8IxDk9EdE9naYbzM2yi4AfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715595869; c=relaxed/simple; bh=pYdMh3F/0PsOmyaq8MUPdEE0dsvCTWhubpNcwZLyXiQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=IVevkSdXm51LBSscdnp7wcLgQTbWjzS90N2lbAc/h+0OCjC0Ah6dXyUX59FgJwFH5jjTv5fpH+ABMCM5Wrsqrq/hoa02RTHq7s92SiRgruhVQjg2tYq+H9LBnvn0mqigf0RLAdcg06dC7Nct99UCdiBvxGkTJiNEVPM45rQ/XvU= 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-out2.suse.de (Postfix) with ESMTPS id 6A10720A9C; Mon, 13 May 2024 10:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715595866; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VyTayui/YQ2wKGlrWtWtJ3WJvNtCVl9WPnedGMoSIYA=; b=fcLoo+TNqkJZGmT6dQDv6A0cLA26qKiSudwr62n12EAgR3jpOrTlS8Pf24R70f4oHe0IiF 1M4IAClNwXRJisW4TpHOoN54KQDjUsWV55C7z1ITdOZPnCmKKBeOBt6PuF62q06aYeDEGd ETDO0PyA9P22agJ+bwTabFlRAdU+T+A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715595866; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VyTayui/YQ2wKGlrWtWtJ3WJvNtCVl9WPnedGMoSIYA=; b=Ei2TcFifQ8ipcUUcUpizSk99NM8MnzZhpPz7tSQ+cJdb46eFXd+KM7j5CmMZrq90SOAHQR qcg1M+g0VofZYqCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1715595866; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VyTayui/YQ2wKGlrWtWtJ3WJvNtCVl9WPnedGMoSIYA=; b=fcLoo+TNqkJZGmT6dQDv6A0cLA26qKiSudwr62n12EAgR3jpOrTlS8Pf24R70f4oHe0IiF 1M4IAClNwXRJisW4TpHOoN54KQDjUsWV55C7z1ITdOZPnCmKKBeOBt6PuF62q06aYeDEGd ETDO0PyA9P22agJ+bwTabFlRAdU+T+A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1715595866; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=VyTayui/YQ2wKGlrWtWtJ3WJvNtCVl9WPnedGMoSIYA=; b=Ei2TcFifQ8ipcUUcUpizSk99NM8MnzZhpPz7tSQ+cJdb46eFXd+KM7j5CmMZrq90SOAHQR qcg1M+g0VofZYqCA== Date: Mon, 13 May 2024 12:24:26 +0200 (CEST) From: Richard Biener To: Tamar Christina cc: "gcc-patches@gcc.gnu.org" Subject: RE: [PATCH] Allow patterns in SLP reductions In-Reply-To: Message-ID: <535qo851-s888-2rs8-40p4-67o53r51qr9o@fhfr.qr> References: <20240301091735.8BBBD13A39@imap2.dmz-prg2.suse.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="-1475677436-233138144-1715595866=:16364" X-Spam-Level: X-Spamd-Result: default: False [-3.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; CTYPE_MIXED_BOGUS(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[multipart/mixed,text/plain]; FROM_HAS_DN(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+]; TO_DN_SOME(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email] X-Spam-Score: -3.30 X-Spam-Status: No, score=-10.9 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 List-Id: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1475677436-233138144-1715595866=:16364 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT On Mon, 13 May 2024, Tamar Christina wrote: > > -----Original Message----- > > From: Richard Biener > > Sent: Friday, May 10, 2024 2:07 PM > > To: Richard Biener > > Cc: gcc-patches@gcc.gnu.org > > Subject: Re: [PATCH] Allow patterns in SLP reductions > > > > On Fri, Mar 1, 2024 at 10:21 AM Richard Biener wrote: > > > > > > The following removes the over-broad rejection of patterns for SLP > > > reductions which is done by removing them from LOOP_VINFO_REDUCTIONS > > > during pattern detection. That's also insufficient in case the > > > pattern only appears on the reduction path. Instead this implements > > > the proper correctness check in vectorizable_reduction and guides > > > SLP discovery to heuristically avoid forming later invalid groups. > > > > > > I also couldn't find any testcase that FAILs when allowing the SLP > > > reductions to form so I've added one. > > > > > > I came across this for single-lane SLP reductions with the all-SLP > > > work where we rely on patterns to properly vectorize COND_EXPR > > > reductions. > > > > > > Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for stage1. > > > > Re-bootstrapped/tested, r15-361-g52d4691294c847 > > Awesome! > > Does this now allow us to write new reductions using patterns? i.e. > widening reductions? Yes (SLP reductions, that is). This is really only for SLP reductions (not SLP reduction chains, not non-SLP reductions). So it's just a corner-case but since with SLP-only non-SLP reductions become SLP reductions with a single lane that was important to fix ;) Richard. > Cheers, > Tamar > > > > Richard. > > > > > Richard. > > > > > > * tree-vect-patterns.cc (vect_pattern_recog_1): Do not > > > remove reductions involving patterns. > > > * tree-vect-loop.cc (vectorizable_reduction): Reject SLP > > > reduction groups with multiple lane-reducing reductions. > > > * tree-vect-slp.cc (vect_analyze_slp_instance): When discovering > > > SLP reduction groups avoid including lane-reducing ones. > > > > > > * gcc.dg/vect/vect-reduc-sad-9.c: New testcase. > > > --- > > > gcc/testsuite/gcc.dg/vect/vect-reduc-sad-9.c | 68 ++++++++++++++++++++ > > > gcc/tree-vect-loop.cc | 15 +++++ > > > gcc/tree-vect-patterns.cc | 13 ---- > > > gcc/tree-vect-slp.cc | 26 +++++--- > > > 4 files changed, 101 insertions(+), 21 deletions(-) > > > create mode 100644 gcc/testsuite/gcc.dg/vect/vect-reduc-sad-9.c > > > > > > diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-sad-9.c > > b/gcc/testsuite/gcc.dg/vect/vect-reduc-sad-9.c > > > new file mode 100644 > > > index 00000000000..3c6af4510f4 > > > --- /dev/null > > > +++ b/gcc/testsuite/gcc.dg/vect/vect-reduc-sad-9.c > > > @@ -0,0 +1,68 @@ > > > +/* Disabling epilogues until we find a better way to deal with scans. */ > > > +/* { dg-additional-options "--param vect-epilogues-nomask=0" } */ > > > +/* { dg-additional-options "-msse4.2" { target { x86_64-*-* i?86-*-* } } } */ > > > +/* { dg-require-effective-target vect_usad_char } */ > > > + > > > +#include > > > +#include "tree-vect.h" > > > + > > > +#define N 64 > > > + > > > +unsigned char X[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))); > > > +unsigned char Y[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))); > > > +int abs (int); > > > + > > > +/* Sum of absolute differences between arrays of unsigned char types. > > > + Detected as a sad pattern. > > > + Vectorized on targets that support sad for unsigned chars. */ > > > + > > > +__attribute__ ((noinline)) int > > > +foo (int len, int *res2) > > > +{ > > > + int i; > > > + int result = 0; > > > + int result2 = 0; > > > + > > > + for (i = 0; i < len; i++) > > > + { > > > + /* Make sure we are not using an SLP reduction for this. */ > > > + result += abs (X[2*i] - Y[2*i]); > > > + result2 += abs (X[2*i + 1] - Y[2*i + 1]); > > > + } > > > + > > > + *res2 = result2; > > > + return result; > > > +} > > > + > > > + > > > +int > > > +main (void) > > > +{ > > > + int i; > > > + int sad; > > > + > > > + check_vect (); > > > + > > > + for (i = 0; i < N/2; i++) > > > + { > > > + X[2*i] = i; > > > + Y[2*i] = N/2 - i; > > > + X[2*i+1] = i; > > > + Y[2*i+1] = 0; > > > + __asm__ volatile (""); > > > + } > > > + > > > + > > > + int sad2; > > > + sad = foo (N/2, &sad2); > > > + if (sad != (N/2)*(N/4)) > > > + abort (); > > > + if (sad2 != (N/2-1)*(N/2)/2) > > > + abort (); > > > + > > > + return 0; > > > +} > > > + > > > +/* { dg-final { scan-tree-dump "vect_recog_sad_pattern: detected" "vect" } } */ > > > +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */ > > > + > > > diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc > > > index 35f1f8c7d42..13dcdba403a 100644 > > > --- a/gcc/tree-vect-loop.cc > > > +++ b/gcc/tree-vect-loop.cc > > > @@ -7703,6 +7703,21 @@ vectorizable_reduction (loop_vec_info loop_vinfo, > > > return false; > > > } > > > > > > + /* Lane-reducing ops also never can be used in a SLP reduction group > > > + since we'll mix lanes belonging to different reductions. But it's > > > + OK to use them in a reduction chain or when the reduction group > > > + has just one element. */ > > > + if (lane_reduc_code_p > > > + && slp_node > > > + && !REDUC_GROUP_FIRST_ELEMENT (stmt_info) > > > + && SLP_TREE_LANES (slp_node) > 1) > > > + { > > > + if (dump_enabled_p ()) > > > + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, > > > + "lane-reducing reduction in reduction group.\n"); > > > + return false; > > > + } > > > + > > > /* All uses but the last are expected to be defined in the loop. > > > The last use is the reduction variable. In case of nested cycle this > > > assumption is not true: we use reduc_index to record the index of the > > > diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc > > > index d562f57920f..fe1ffba8688 100644 > > > --- a/gcc/tree-vect-patterns.cc > > > +++ b/gcc/tree-vect-patterns.cc > > > @@ -7172,7 +7172,6 @@ vect_pattern_recog_1 (vec_info *vinfo, > > > vect_recog_func *recog_func, stmt_vec_info stmt_info) > > > { > > > gimple *pattern_stmt; > > > - loop_vec_info loop_vinfo; > > > tree pattern_vectype; > > > > > > /* If this statement has already been replaced with pattern statements, > > > @@ -7198,8 +7197,6 @@ vect_pattern_recog_1 (vec_info *vinfo, > > > return; > > > } > > > > > > - loop_vinfo = dyn_cast (vinfo); > > > - > > > /* Found a vectorizable pattern. */ > > > if (dump_enabled_p ()) > > > dump_printf_loc (MSG_NOTE, vect_location, > > > @@ -7208,16 +7205,6 @@ vect_pattern_recog_1 (vec_info *vinfo, > > > > > > /* Mark the stmts that are involved in the pattern. */ > > > vect_mark_pattern_stmts (vinfo, stmt_info, pattern_stmt, pattern_vectype); > > > - > > > - /* Patterns cannot be vectorized using SLP, because they change the order of > > > - computation. */ > > > - if (loop_vinfo) > > > - { > > > - unsigned ix, ix2; > > > - stmt_vec_info *elem_ptr; > > > - VEC_ORDERED_REMOVE_IF (LOOP_VINFO_REDUCTIONS (loop_vinfo), ix, > > ix2, > > > - elem_ptr, *elem_ptr == stmt_info); > > > - } > > > } > > > > > > > > > diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc > > > index dabd8407aaf..d9961945c1c 100644 > > > --- a/gcc/tree-vect-slp.cc > > > +++ b/gcc/tree-vect-slp.cc > > > @@ -3597,14 +3597,24 @@ vect_analyze_slp_instance (vec_info *vinfo, > > > = as_a (vinfo)->reductions; > > > scalar_stmts.create (reductions.length ()); > > > for (i = 0; reductions.iterate (i, &next_info); i++) > > > - 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) > > > - scalar_stmts.quick_push (next_info); > > > + { > > > + 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; > > > -- > > > 2.35.3 > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg) ---1475677436-233138144-1715595866=:16364--