From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 17C13385C017 for ; Thu, 20 Jul 2023 14:08:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17C13385C017 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4463F2F4; Thu, 20 Jul 2023 07:09:28 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8140F3F738; Thu, 20 Jul 2023 07:08:44 -0700 (PDT) From: Richard Sandiford To: Richard Biener via Gcc-patches Mail-Followup-To: Richard Biener via Gcc-patches ,Richard Biener , richard.sandiford@arm.com Cc: Richard Biener Subject: Re: [PATCH] tree-optimization/110742 - fix latent issue with permuting existing vectors References: <20230720123855.334A4385AF91@sourceware.org> Date: Thu, 20 Jul 2023 15:08:43 +0100 In-Reply-To: <20230720123855.334A4385AF91@sourceware.org> (Richard Biener via Gcc-patches's message of "Thu, 20 Jul 2023 12:38:36 +0000 (UTC)") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-26.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,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: Richard 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. > > Bootstrapped and tested on x86_64-unknown-linux-gnu. > > OK? > > Thanks, > Richard. > > 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. > > * 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 > > 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 = 0; i < (sizeof(elts) / sizeof((elts)[0])); ++i) > + res.elts[i] = ~elts[i]; > + return res; > + } > + HARD_REG_SET operator&(const HARD_REG_SET &other) const { > + HARD_REG_SET res; > + for (unsigned int i = 0; i < (sizeof(elts) / sizeof((elts)[0])); ++i) > + res.elts[i] = 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 = 0; > + for (unsigned int i = 0; i < (sizeof(x.elts) / sizeof((x.elts)[0])); ++i) > + bad |= (x.elts[i] & ~y.elts[i]); > + return bad == 0; > +} > +inline bool hard_reg_set_empty_p(const_hard_reg_set x) { > + unsigned long bad = 0; > + for (unsigned int i = 0; i < (sizeof(x.elts) / sizeof((x.elts)[0])); ++i) > + bad |= x.elts[i]; > + return bad == 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 = 0; cl2 < 2; cl2++) { > + temp_set2 = rr[cl2] & ~nn; > + if (hard_reg_set_empty_p(mm) && hard_reg_set_empty_p(temp_set2)) { > + mm = 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] = 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; > > if (SLP_TREE_DEF_TYPE (node) == vect_constant_def > - || SLP_TREE_DEF_TYPE (node) == vect_external_def) > + || (SLP_TREE_DEF_TYPE (node) == vect_external_def > + && (to_layout_i == 0 > + /* We can't permute vector defs. */ > + || SLP_TREE_VEC_DEFS (node).is_empty ()))) Guess it's personal preference, but IMO it's easier to follow without the to_layout_i condition, so that it ties directly to the create_partitions test. (Would be nice to have a name for whatever a node matching the new condition is, but I don't have any good ideas.) LGTM otherwise FWIW. Thanks, Richard > { > /* If the vector is uniform or unchanged, there's nothing to do. */ > if (to_layout_i == 0 || vect_slp_tree_uniform_p (node)) > @@ -5944,7 +5947,8 @@ vect_slp_analyze_node_operations_1 (vec_info *vinfo, slp_tree node, > calculated by the recursive call). Otherwise it is the number of > scalar elements in one scalar iteration (DR_GROUP_SIZE) multiplied by > VF divided by the number of elements in a vector. */ > - if (!STMT_VINFO_DATA_REF (stmt_info) > + if (SLP_TREE_CODE (node) != VEC_PERM_EXPR > + && !STMT_VINFO_DATA_REF (stmt_info) > && REDUC_GROUP_FIRST_ELEMENT (stmt_info)) > { > for (unsigned i = 0; i < SLP_TREE_CHILDREN (node).length (); ++i)