public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-2697] tree-optimization/110742 - fix latent issue with permuting existing vectors Date: Fri, 21 Jul 2023 07:29:05 +0000 (GMT) [thread overview] Message-ID: <20230721072905.D611B385483D@sourceware.org> (raw) https://gcc.gnu.org/g:9a8782e63790842d1bfa03e12eecf73c4aaeb1f8 commit r14-2697-g9a8782e63790842d1bfa03e12eecf73c4aaeb1f8 Author: Richard Biener <rguenther@suse.de> Date: Thu Jul 20 13:09:17 2023 +0200 tree-optimization/110742 - fix latent issue with permuting existing vectors 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. 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. Diff: --- gcc/testsuite/g++.dg/torture/pr110742.C | 47 +++++++++++++++++++++++++++++++++ gcc/tree-vect-slp.cc | 7 +++-- 2 files changed, 52 insertions(+), 2 deletions(-) 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..f4adbb28761 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -5198,7 +5198,9 @@ 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 + /* We can't permute vector defs in place. */ + && SLP_TREE_VEC_DEFS (node).is_empty ())) { /* 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 +5946,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)
reply other threads:[~2023-07-21 7:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230721072905.D611B385483D@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).