From patchwork Wed Jul 26 13:27:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 126358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp403522vqo; Wed, 26 Jul 2023 06:29:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGUD8eXl8sRCgxAzl5upbRB/5jryH2U7Uk4Ur5ILM1HckXhzxyiNjEWstDt9dZ0ptHKB9TT X-Received: by 2002:a17:906:3f49:b0:991:d8b2:ea31 with SMTP id f9-20020a1709063f4900b00991d8b2ea31mr1848241ejj.52.1690378154273; Wed, 26 Jul 2023 06:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690378154; cv=none; d=google.com; s=arc-20160816; b=isTqYlrUg73Bv+umrnAGYC+Cyto0lUh1guSzLI9cALuj1e2TvW/eJQIab/jwTWj9S7 J+Bb7u0o2oevmLvzrw+16cLgwEFMWmLJDCfemzXGgNpb7WcJkCD9gzAwdOPnkkz2KQqf EbYDQoBhiLMQ3lygt3RRMIDm2XvwgNy2vzQunazvY+YNvyZUWL/SXffywF3WsP59rtAK Xp620O6bnAcAfAjezOfoK82X8Jz4qzxJ1d7nk031e9krmPvIH5nFRsAgwuM78J0xKcXD pjplUaQPD+HcoESndCmyXEySC+YgK18Mhar8Px+vnGJVB3cE4sNeOO301D8IUxwEFlBi Q5xQ== 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:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ZChCuTjf9aJ1OiVlMjxBbHXGZAWUoKZzueETde3rH2A=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=rSDolw5kdds3uwkihNV9SGbC70COjsxGQ548zDiz8un04CDSrh+y/nbFMl6Vwojj4X BGTgXF8CcIxTrPiTrwRlFoZ160a13e4ph5AVk0/+jUe9cJ4VZdg/e9lB8S5Nnf9hD6d4 /ohYqvnCfxZXfvNl8B0Uej/ZksHy2wAb3zekzSkX6SGXe8BNGPWttW5bPV2XWA9Lz5fZ M2MmIqYj8gaxtGOywVNgV7QsMPtiTZSpjBk0AgwpRI8KhsuESxdo77yECDOlubG/T96G QWU9hM5rSLRXZlept017ScqG9M3lqEnT4OWQgCFK28EXIzVI4km3Moy7m9TnhxuXJhD7 Ai7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CXYGur0+; 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 l25-20020a170906a41900b0098896420108si9069792ejz.170.2023.07.26.06.29.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 06:29:14 -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=CXYGur0+; 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 D12B5385C8B0 for ; Wed, 26 Jul 2023 13:28:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D12B5385C8B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690378114; bh=ZChCuTjf9aJ1OiVlMjxBbHXGZAWUoKZzueETde3rH2A=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CXYGur0+zBdQeov8YFhU3zsPMhKA2sLKop82iZysJtXf1d8rtvdaflIN4xugutXTI ieq4KeJV2lH5pWgNmA4zU8n6ATK7YDShmnhlP/2GTxvaQ/FkleNMzBWOxwITfoH5tv tt0+LwcHpgsNFw2paJLb45MnsDZhco7uqFvt9kC8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 3A0A73856254 for ; Wed, 26 Jul 2023 13:27:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A0A73856254 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 15228218E5 for ; Wed, 26 Jul 2023 13:27:34 +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 0AA692C142 for ; Wed, 26 Jul 2023 13:27:33 +0000 (UTC) Date: Wed, 26 Jul 2023 13:27:33 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106081 - elide redundant permute 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: <20230726132834.D12B5385C8B0@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772489963215204618 X-GMAIL-MSGID: 1772489963215204618 The following patch makes sure to elide a redundant permute that can be merged with existing splats represented as load permutations as we now do for non-grouped SLP loads. This is the last bit missing to fix this PR where the main fix was already done by r14-2117-gdd86a5a69cbda4 Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/106081 * tree-vect-slp.cc (vect_optimize_slp_pass::start_choosing_layouts): Assign layout -1 to splats. * gcc.dg/vect/pr106081.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr106081.c | 33 ++++++++++++++++++++++++++++ gcc/tree-vect-slp.cc | 5 ++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr106081.c diff --git a/gcc/testsuite/gcc.dg/vect/pr106081.c b/gcc/testsuite/gcc.dg/vect/pr106081.c new file mode 100644 index 00000000000..8f97af2d642 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr106081.c @@ -0,0 +1,33 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ffast-math -fdump-tree-optimized" } */ +/* { dg-additional-options "-mavx2" { target x86_64-*-* i?86-*-* } } */ +/* { dg-require-effective-target vect_double } */ +/* { dg-require-effective-target vect_unpack } */ +/* { dg-require-effective-target vect_intdouble_cvt } */ +/* { dg-require-effective-target vect_perm } */ + +struct pixels +{ + short a,b,c,d; +} *pixels; +struct dpixels +{ + double a,b,c,d; +}; + +double +test(double *k) +{ + struct dpixels results={}; + for (int u=0; u<1000*16;u++,k--) + { + results.a += *k*pixels[u].a; + results.b += *k*pixels[u].b; + results.c += *k*pixels[u].c; + results.d += *k*pixels[u].d; + } + return results.a+results.b*2+results.c*3+results.d*4; +} + +/* { dg-final { scan-tree-dump "vectorized 1 loops" "vect" } } */ +/* { dg-final { scan-tree-dump-times "VEC_PERM" 4 "optimized" { target x86_64-*-* i?86-*-* } } } */ diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index e4430248ab5..a1b153035e1 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -4605,7 +4605,10 @@ vect_optimize_slp_pass::start_choosing_layouts () IFN_MASK_LOADs). */ gcc_assert (partition.layout == 0 && !m_slpg->vertices[node_i].succ); if (!STMT_VINFO_GROUPED_ACCESS (dr_stmt)) - continue; + { + partition.layout = -1; + continue; + } dr_stmt = DR_GROUP_FIRST_ELEMENT (dr_stmt); imin = DR_GROUP_SIZE (dr_stmt) + 1; tmp_perm.safe_splice (SLP_TREE_LOAD_PERMUTATION (node));