From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 568BC3858CDB for ; Thu, 20 Jul 2023 17:11:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 568BC3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5B49821DDB; Thu, 20 Jul 2023 17:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689873060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/GGjziTtgHd746AC1Gi1+OblsdTBLyCHz80ZKh5JOCc=; b=rqO8O0vngPscQvvt6n4yzB9aUNW/iygtL2fyx1oSuew6+/SxoADUnuChVoSxI/+00LG5rd bsVI+Pf/g/eEcm9HA6gZF6GcWeDkbL7gvVIwL4WkfsSfAhO1LpNmYv2YSFzCW/GLbBd3Kc uutRf60BAn8jR5TMQybzQ3wWxcC6Cfg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689873060; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/GGjziTtgHd746AC1Gi1+OblsdTBLyCHz80ZKh5JOCc=; b=muzOmELZLN+S9IZCMRV3m179bAeeGeJER58GfthjsHB0iK5qGcQuhv7hgHc1MH8PhAB0Zn +cuVpHbpula/1YBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4F60C138EC; Thu, 20 Jul 2023 17:11:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id L25TE6RquWRsSgAAMHmgww (envelope-from ); Thu, 20 Jul 2023 17:11:00 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Richard Biener Mime-Version: 1.0 (1.0) Subject: Re: [PATCH] tree-optimization/110742 - fix latent issue with permuting existing vectors Date: Thu, 20 Jul 2023 19:10:49 +0200 Message-Id: <39395404-A479-4451-A2E8-2BF46AE766C0@suse.de> References: Cc: Richard Biener via Gcc-patches In-Reply-To: To: Richard Sandiford X-Mailer: iPhone Mail (20F75) X-Spam-Status: No, score=-11.1 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,T_SCC_BODY_TEXT_LINE 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: > Am 20.07.2023 um 18:59 schrieb Richard Sandiford : >=20 > =EF=BB=BFRichard Biener writes: >>>> Am 20.07.2023 um 16:09 schrieb Richard Sandiford : >>>=20 >>> =EF=BB=BFRichard Biener via Gcc-patches writes= : >>>> When we materialize a layout we push edge permutes to constant/external= >>>> defs without checking we can actually do so. For externals defined >>>> by vector stmts rather than scalar components we can't. >>>>=20 >>>> Bootstrapped and tested on x86_64-unknown-linux-gnu. >>>>=20 >>>> OK? >>>>=20 >>>> Thanks, >>>> Richard. >>>>=20 >>>> PR tree-optimization/110742 >>>> * tree-vect-slp.cc (vect_optimize_slp_pass::get_result_with_layout): >>>> Do not materialize an edge permutation in an external node with >>>> vector defs. >>>> (vect_slp_analyze_node_operations_1): Guard purely internal >>>> nodes better. >>>>=20 >>>> * g++.dg/torture/pr110742.C: New testcase. >>>> --- >>>> gcc/testsuite/g++.dg/torture/pr110742.C | 47 +++++++++++++++++++++++++ >>>> gcc/tree-vect-slp.cc | 8 +++-- >>>> 2 files changed, 53 insertions(+), 2 deletions(-) >>>> create mode 100644 gcc/testsuite/g++.dg/torture/pr110742.C >>>>=20 >>>> diff --git a/gcc/testsuite/g++.dg/torture/pr110742.C b/gcc/testsuite/g+= +.dg/torture/pr110742.C >>>> new file mode 100644 >>>> index 00000000000..d41ac0479d2 >>>> --- /dev/null >>>> +++ b/gcc/testsuite/g++.dg/torture/pr110742.C >>>> @@ -0,0 +1,47 @@ >>>> +// { dg-do compile } >>>> + >>>> +struct HARD_REG_SET { >>>> + HARD_REG_SET operator~() const { >>>> + HARD_REG_SET res; >>>> + for (unsigned int i =3D 0; i < (sizeof(elts) / sizeof((elts)[0]));= ++i) >>>> + res.elts[i] =3D ~elts[i]; >>>> + return res; >>>> + } >>>> + HARD_REG_SET operator&(const HARD_REG_SET &other) const { >>>> + HARD_REG_SET res; >>>> + for (unsigned int i =3D 0; i < (sizeof(elts) / sizeof((elts)[0]));= ++i) >>>> + res.elts[i] =3D elts[i] & other.elts[i]; >>>> + return res; >>>> + } >>>> + unsigned long elts[4]; >>>> +}; >>>> +typedef const HARD_REG_SET &const_hard_reg_set; >>>> +inline bool hard_reg_set_subset_p(const_hard_reg_set x, const_hard_reg= _set y) { >>>> + unsigned long bad =3D 0; >>>> + for (unsigned int i =3D 0; i < (sizeof(x.elts) / sizeof((x.elts)[0])= ); ++i) >>>> + bad |=3D (x.elts[i] & ~y.elts[i]); >>>> + return bad =3D=3D 0; >>>> +} >>>> +inline bool hard_reg_set_empty_p(const_hard_reg_set x) { >>>> + unsigned long bad =3D 0; >>>> + for (unsigned int i =3D 0; i < (sizeof(x.elts) / sizeof((x.elts)[0])= ); ++i) >>>> + bad |=3D x.elts[i]; >>>> + return bad =3D=3D 0; >>>> +} >>>> +extern HARD_REG_SET rr[2]; >>>> +extern int t[2]; >>>> +extern HARD_REG_SET nn; >>>> +static HARD_REG_SET mm; >>>> +void setup_reg_class_relations(void) { >>>> + HARD_REG_SET intersection_set, union_set, temp_set2; >>>> + for (int cl2 =3D 0; cl2 < 2; cl2++) { >>>> + temp_set2 =3D rr[cl2] & ~nn; >>>> + if (hard_reg_set_empty_p(mm) && hard_reg_set_empty_p(temp_set2)) {= >>>> + mm =3D rr[0] & nn; >>>> + if (hard_reg_set_subset_p(mm, intersection_set)) >>>> + if (!hard_reg_set_subset_p(mm, temp_set2) || >>>> + hard_reg_set_subset_p(rr[0], rr[t[cl2]])) >>>> + t[cl2] =3D 0; >>>> + } >>>> + } >>>> +} >>>> diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc >>>> index 693621ca990..1d79c77e8ce 100644 >>>> --- a/gcc/tree-vect-slp.cc >>>> +++ b/gcc/tree-vect-slp.cc >>>> @@ -5198,7 +5198,10 @@ vect_optimize_slp_pass::get_result_with_layout (= slp_tree node, >>>> return result; >>>>=20 >>>> if (SLP_TREE_DEF_TYPE (node) =3D=3D vect_constant_def >>>> - || SLP_TREE_DEF_TYPE (node) =3D=3D vect_external_def) >>>> + || (SLP_TREE_DEF_TYPE (node) =3D=3D vect_external_def >>>> + && (to_layout_i =3D=3D 0 >>>> + /* We can't permute vector defs. */ >>>> + || SLP_TREE_VEC_DEFS (node).is_empty ()))) >>>=20 >>> Guess it's personal preference, but IMO it's easier to follow without th= e >>> to_layout_i condition, so that it ties directly to the create_partitions= >>> test. >>=20 >> I don=E2=80=99t understand- in the code guarding this we seem to expect t= o_layout_i =3D=3D 0 and that=E2=80=99s the case we can handle as noop. I di= dn=E2=80=99t understand why the function doesn=E2=80=99t always just do noth= ing in this case though, so I must have missed something. >=20 > OK, so I guess that disproves that my way is easier to understand :) >=20 > I think logically, the code is doing the equivalent of: >=20 > int partition_i =3D m_vertices[node->vertex].partition; > if (partition < 0) > { > /* If the vector is uniform or unchanged, there's nothing to do. */ > ... =20 > } > else > { > ... Return node if to_layout_i matches this partition's chosen layout= ... > } >=20 > And I guess I should have written it that way. >=20 > So when there is no partition, we have a constant or external def > built from individual scalars. We can use the node as-is if the > caller wants an unpermuted node or if all elements are equal > (so that the permutation doesn't matter). Otherwise we need > to permute the scalars. >=20 > When there is a partition, we can use the node as-is if the caller > wants the layout that was chosen for that partition. Otherwise we > need a new VEC_PERM_EXPR node. >=20 > In the particular case of external defs built from vectors, we're > guaranteed that the node's chosen layout is 0 (i.e. the original layout), > and so both ways work. Hmm, but I arrived here with that not being the case =E2=80=A6 (the chosen L= ay-out not zero) > But in principle this case fits the "else" arm > better than the "then" arm, because we're dealing with a node that is in > a partition, and that is not built from scalars. >=20 > Thanks, > Richard