From patchwork Mon Sep 26 06:56:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liwei Xu X-Patchwork-Id: 1442 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1352359wrt; Sun, 25 Sep 2022 23:59:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7An7izGihzYjby2qvsXT30wcRuOSEURE6lZLPr+OZgwYWcCsVHJOrlRCgsGP6ecxaBQgbR X-Received: by 2002:a05:6402:1009:b0:456:f370:5263 with SMTP id c9-20020a056402100900b00456f3705263mr10460157edu.392.1664175594294; Sun, 25 Sep 2022 23:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664175594; cv=none; d=google.com; s=arc-20160816; b=vhl2wVp83tDMio/k23GcWRAU/eWpjgspRQTSA4apNgZoTQIRoLAgzUjALlkuGFbeDn /ffjt7EhZPWGHDnaax0ZFMtEJ725QSzsH6lsSKVhoEhT3tc6oR/zyN897vw8n0zApU8w IeffhvoCDd2bUTOtLzk/yy6Aj81GinD6f5HM4TBOJO0A2oGedCxUjkYKn/wyiIuQrKX6 NKT51cyeb9fiJWmUnbSIHpyx9VUhNneQu8Ui2xuzWW1QKQgmrFkQULr9SACi5vjqEppo hBr8KvNSOr3QbgfzntmkfNpBtBDI8dC9i1cZoMnZur/m8BXoTiSVdSvLtErD/5cV9YJa 8iHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=WoRprUvywVRLZto6j3mUi0dPGL3t4xqsZwdZFtGJ2nw=; b=iH9pbi/mXXZuneehIICijReL1hqBa14q8cDQQIsD+CEmizPDKWn82bvrik5jjBiuk4 LoVeiNszTphLf6DIdeT2ql80108wdt1QGMltjNZ3Mas03btAeZyNkoX/CO1JMVSFLN49 nYGGvA7rrawOo5DcssSW6pC0tveDKT+OwPEMEmJ7M9+BdtBQ3T8nD0iAHmXh58Hfyn3k RJa4SoEFo6/ukKUqT3g2Ni02spNAOfrS5KZ05czxgwleHFmsykYxnAFlS1iaE8ROPFbZ ByN0+hl3Ko7rF3rrP6RHZ2UVYG5BtvErf83Ho9yQcQGgOpxwo/HDA/NKpXrfAvMRfNzg +mbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="XwZz/Ond"; 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qa15-20020a170907868f00b0072b83ed8d42si17807524ejc.82.2022.09.25.23.59.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 23:59:54 -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="XwZz/Ond"; 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 6D2313856941 for ; Mon, 26 Sep 2022 06:59:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D2313856941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664175546; bh=WoRprUvywVRLZto6j3mUi0dPGL3t4xqsZwdZFtGJ2nw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=XwZz/Ond6owWESmx7jlP/ueZGbWsMO3lRbMqcKLHORVE2X4/9mI1H6nyWtp6dFxnR /xyVLF+TjFizzbzq7o4OBv87mkCGYmZXe5ix3x8/Z4TECAfpt6BcwQ+JYj7izEiwdR YsXISzAaIP3pYn3PJlQ6F5ddMWS+PXIZc3rtSph0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id 58CBA3858CDA for ; Mon, 26 Sep 2022 06:58:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 58CBA3858CDA X-IronPort-AV: E=McAfee;i="6500,9779,10481"; a="301854893" X-IronPort-AV: E=Sophos;i="5.93,345,1654585200"; d="scan'208";a="301854893" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Sep 2022 23:58:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10481"; a="623226285" X-IronPort-AV: E=Sophos;i="5.93,345,1654585200"; d="scan'208";a="623226285" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga007.fm.intel.com with ESMTP; 25 Sep 2022 23:58:05 -0700 Received: from shliclel314.sh.intel.com (shliclel314.sh.intel.com [10.239.240.214]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 8C7951005687; Mon, 26 Sep 2022 14:58:04 +0800 (CST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Optimize nested permutation to single VEC_PERM_EXPR [PR54346] Date: Mon, 26 Sep 2022 14:56:04 +0800 Message-Id: <20220926065604.783193-1-liwei.xu@intel.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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: Liwei Xu via Gcc-patches From: Liwei Xu Reply-To: Liwei Xu Cc: wilson@tuliptree.org, admin@levyhsu.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745014588045762163?= X-GMAIL-MSGID: =?utf-8?q?1745014588045762163?= This patch implemented the optimization in PR 54346, which Merges c = VEC_PERM_EXPR ; d = VEC_PERM_EXPR ; to d = VEC_PERM_EXPR ; Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,} tree-ssa/forwprop-19.c fail to pass but I'm not sure whether it is ok to removed it. gcc/ChangeLog: PR target/54346 * match.pd: Merge the index of VCST then generates the new vec_perm. gcc/testsuite/ChangeLog: PR target/54346 * gcc.dg/pr54346.c: New test. Co-authored-by: liuhongt --- gcc/match.pd | 41 ++++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr54346.c | 13 +++++++++++ 2 files changed, 54 insertions(+) create mode 100755 gcc/testsuite/gcc.dg/pr54346.c diff --git a/gcc/match.pd b/gcc/match.pd index 345bcb701a5..9219b0a10e1 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8086,6 +8086,47 @@ and, (minus (mult (vec_perm @1 @1 @3) @2) @4))) +/* (PR54346) Merge + c = VEC_PERM_EXPR ; + d = VEC_PERM_EXPR ; + to + d = VEC_PERM_EXPR ; */ + +(simplify + (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4) + (with + { + if(!TYPE_VECTOR_SUBPARTS (type).is_constant()) + return NULL_TREE; + + tree op0; + machine_mode result_mode = TYPE_MODE (type); + machine_mode op_mode = TYPE_MODE (TREE_TYPE (@1)); + int nelts = TYPE_VECTOR_SUBPARTS (type).to_constant(); + vec_perm_builder builder0; + vec_perm_builder builder1; + vec_perm_builder builder2 (nelts, nelts, 1); + + if (!tree_to_vec_perm_builder (&builder0, @3) + || !tree_to_vec_perm_builder (&builder1, @4)) + return NULL_TREE; + + vec_perm_indices sel0 (builder0, 2, nelts); + vec_perm_indices sel1 (builder1, 1, nelts); + + for (int i = 0; i < nelts; i++) + builder2.quick_push (sel0[sel1[i].to_constant()]); + + vec_perm_indices sel2 (builder2, 2, nelts); + + if (!can_vec_perm_const_p (result_mode, op_mode, sel2, false)) + return NULL_TREE; + + op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2); + } + (vec_perm @1 @2 { op0; }))) + + /* Match count trailing zeroes for simplify_count_trailing_zeroes in fwprop. The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic constant which when multiplied by a power of 2 contains a unique value diff --git a/gcc/testsuite/gcc.dg/pr54346.c b/gcc/testsuite/gcc.dg/pr54346.c new file mode 100755 index 00000000000..d87dc3a79a5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr54346.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-dse1" } */ + +typedef int veci __attribute__ ((vector_size (4 * sizeof (int)))); + +void fun (veci a, veci b, veci *i) +{ + veci c = __builtin_shuffle (a, b, __extension__ (veci) {1, 4, 2, 7}); + *i = __builtin_shuffle (c, __extension__ (veci) { 7, 2, 1, 5 }); +} + +/* { dg-final { scan-tree-dump "VEC_PERM_EXPR.*{ 3, 6, 0, 0 }" "dse1" } } */ +/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 1 "dse1" } } */ \ No newline at end of file