From patchwork Thu Jul 20 12:38:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 123240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3087250vqt; Thu, 20 Jul 2023 05:39:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlGYwn1SJBltl2Kjl66rLRCGsqChvDzl1WuHUJs+jDtHEj5Gh2ULkJ3IGTebaNmsFAIHWuzV X-Received: by 2002:a17:906:2895:b0:988:71c8:9f3a with SMTP id o21-20020a170906289500b0098871c89f3amr5283719ejd.16.1689856761214; Thu, 20 Jul 2023 05:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689856761; cv=none; d=google.com; s=arc-20160816; b=HxR5J0dYP77ydwHeRjloj1tA6Eo870W31aHbDVUNqlTXZYTLSKKUZqLg4duunXy9tV 1ffvyLxcNGCVKY97/F7lMwasYNcK6oA+ZopRhQ5uWm/b64a+uiJjBZ8ufwA1xEFtq75z KEVlFChPym+LQUqWba+jl91JF5LbSvifiYD2DofBWXRFC5rktz/vU0GDzmm40f3n00S5 99h1t7xW3o3N0tjDLN3rHgGqtG4exYQ9RDmO99CkqPI8O+irRsTnZ2+wvlABbDpqwz2s Fh2zszwTDG+MIIcF+jYgvosY/VMzQRiZX7+pjS7AQCk/rXVOWWUktsPlWGWJ1SkvqMAm ZbFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=DDkdgb0YcXCtoiYZiNLwBnhYLpoRhWyFstmrt79Gtd4=; fh=YqA+5s9oAwnNzotQ4oUKFF8r+ylKGgHXnNsFpvcI6Dw=; b=0GTzSisbqbhfYnooo8PWGa4DU/VhN4aXEEDi29Slph5eKV0tJlAI8DLvbaouzgou2t fUmhKAv3Tx/di0Z2EHe2hxdDNgDWuZhAvw4n3Ev0i7ol+nzLIfUQ18lKbOFQ9GpGnh89 oJ5VAuMzHLsCtsTT7X5dXEHD2Heyw+oPDAU90PeZ8eIMIu4hURkwihHMNsUK3EO+/iVZ gVa9BYlkgGBUKtoxarcJWfYEwhZp7F0fv41KnEiZA0J6IXFjqSspQuYiulJ0yEbfGMLj 3nmoRF3Ql4/L9D2VHAWynSQFHgZt5Rr6lWTYpGiRvFkv6iZJXGGIM+BodGOFY4a7TVSc NKcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jIqMytmM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s4-20020a170906454400b009933205fdb5si620594ejq.141.2023.07.20.05.39.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:39:21 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jIqMytmM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ECBCE3858C33 for ; Thu, 20 Jul 2023 12:39:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ECBCE3858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689856760; bh=DDkdgb0YcXCtoiYZiNLwBnhYLpoRhWyFstmrt79Gtd4=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jIqMytmM7gRpKgTYeWF/lb+hrbC3B2f2CLK1umr13Frh7aVyw5BUGGlHaC964uwUX G0WP7YTyurbJvFXCfnom5rXfCWQH/BhZ+KzbLKcfPrBXsVEmnpelevPd6ykZnA6hp1 qo+zDV1Nc3+Bf3nTm390DLNSxWZPNPtPTS2R3djg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id BE2653858409 for ; Thu, 20 Jul 2023 12:38:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BE2653858409 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D4E0B2069D; Thu, 20 Jul 2023 12:38:36 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C339B2C142; Thu, 20 Jul 2023 12:38:36 +0000 (UTC) Date: Thu, 20 Jul 2023 12:38:36 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: richard.sandiford@arm.com Subject: [PATCH] tree-optimization/110742 - fix latent issue with permuting existing vectors User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230720123919.ECBCE3858C33@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771943243154096625 X-GMAIL-MSGID: 1771943243154096625 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 ()))) { /* 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)