From patchwork Thu Apr 20 03:58:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 85704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp55059vqo; Wed, 19 Apr 2023 20:59:10 -0700 (PDT) X-Google-Smtp-Source: AKy350aq5ceK5fVr1orHvSd8uR5+VemoJRLNOFU0VSg5i9H11VnqQ3CKrJ3cDYYWq87DqJe/1EOu X-Received: by 2002:a17:906:c1d0:b0:94f:cee:56f2 with SMTP id bw16-20020a170906c1d000b0094f0cee56f2mr185106ejb.4.1681963150377; Wed, 19 Apr 2023 20:59:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681963150; cv=none; d=google.com; s=arc-20160816; b=mx41prtDBwPJ/vR+GyM5qd2hOflXkXub0vDGW4DR4f9Vjh5A/39DexVcV+OAKqwr0w ilBec84Lf+ibvakIgDsaijVNx2TpJYUag2ua2YRfcMdCht8GWzLiAjqrssJf+KraE+eQ LE067cl9ELBWp+rLy7Ts9E6RErR0mcEHVFdg1tIygyb4WqWFLjbkbs9s+SLs/4egi6WD cP4ZL2wWM2GfX8WySIWibUHmJ0VexqSGkMCjRzQ2/O7LS5UL1EpUmaSsiaC+DVPR6I8L N/lIVgc89i/M6NrNT0X/mWWC5kle+RNlV2ysD/76pRwLJSkJx4RfIMfcc5vNsHqu7CiM 9g0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=HuPywuAC+WGsnR9wL7bez//QHWLYjYkIp901txP1ebA=; b=lZhdgDNtnKmPpMqQxiWXREdPd1Uu88qG1/d5kPJ9FH3LjUKHakHZKKWwj7euquu6aB XEP87thDNaoShpqJUnpdS3HyYZadRAP+3BF5cGT/h+oX1tZplNDVutBexa3uChQ7FMZe M5jxQZUQlw/joBrNMEjcHnR/3OPBo1WmbopVvP8/5wQTuTXDW6rWT/bKhgTHazlO4YMJ Rh7cENvGg406HQjYVw223zhhyejpvJqujPc8NoyoE7YyJP4R9K0fGQ6kcW8/HkcJacFP pJsdG0zotOWi/VtD0VA7bFSb43HljAZmpzEa+vFI96bMa/SkYKXUGwZdJOrz/kdbX6dL xNdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=lg3C44h7; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o5-20020a17090611c500b009514ac7c254si615310eja.842.2023.04.19.20.59.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 20:59:10 -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=lg3C44h7; 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 499C13858438 for ; Thu, 20 Apr 2023 03:59:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 499C13858438 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681963149; bh=HuPywuAC+WGsnR9wL7bez//QHWLYjYkIp901txP1ebA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=lg3C44h77QYP3JIp7/G/+E04qNs3hcZXXcOxFTU9D/+4/9gSX56AsVDPxevk4f5TE uGCn7Ip1M2i6IwAniA6gXYPIcmzSVg7hVO3IU0YO2oPIRVyFAVR1efRJCEzpxE6n6w leN3Fc0/0UlgT+VJ7isghrZJHhj5ZjVEmVrJLPtI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by sourceware.org (Postfix) with ESMTPS id 3A27F3858D33 for ; Thu, 20 Apr 2023 03:58:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A27F3858D33 X-IronPort-AV: E=McAfee;i="6600,9927,10685"; a="344374452" X-IronPort-AV: E=Sophos;i="5.99,211,1677571200"; d="scan'208";a="344374452" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2023 20:58:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10685"; a="781093998" X-IronPort-AV: E=Sophos;i="5.99,211,1677571200"; d="scan'208";a="781093998" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by FMSMGA003.fm.intel.com with ESMTP; 19 Apr 2023 20:58:22 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 7CE4010081D6; Thu, 20 Apr 2023 11:58:21 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] Canonicalize vec_merge when mask is constant. Date: Thu, 20 Apr 2023 11:58:21 +0800 Message-Id: <20230420035821.4113007-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.39.1.388.g2fc9e9ca3c MIME-Version: 1.0 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, 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 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: liuhongt via Gcc-patches From: liuhongt Reply-To: liuhongt 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?1763666192588852442?= X-GMAIL-MSGID: =?utf-8?q?1763666192588852442?= Use swap_communattive_operands_p for canonicalization. When both value has same operand precedence value, then first bit in the mask should select first operand. The canonicalization should help backends for pattern match. .i.e. x86 backend has lots of vec_merge patterns, combine will create any form of vec_merge(mask, or inverted mask), then backend need to add 2 patterns to match exact 1 instruction. The canonicalization can simplify 2 patterns to 1. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}, aarch64-linux-gnu. Ok for trunk? gcc/ChangeLog: * combine.cc (maybe_swap_commutative_operands): Canonicalize vec_merge when mask is constant. --- gcc/combine.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gcc/combine.cc b/gcc/combine.cc index 0106092e456..5aa0ec5c45a 100644 --- a/gcc/combine.cc +++ b/gcc/combine.cc @@ -5631,6 +5631,28 @@ maybe_swap_commutative_operands (rtx x) SUBST (XEXP (x, 0), XEXP (x, 1)); SUBST (XEXP (x, 1), temp); } + + unsigned n_elts = 0; + if (GET_CODE (x) == VEC_MERGE + && CONST_INT_P (XEXP (x, 2)) + && GET_MODE_NUNITS (GET_MODE (x)).is_constant (&n_elts) + && (swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)) + /* Two operands have same precedence, then + first bit of mask select first operand. */ + || (!swap_commutative_operands_p (XEXP (x, 1), XEXP (x, 0)) + && !(UINTVAL (XEXP (x, 2)) & 1)))) + { + rtx temp = XEXP (x, 0); + unsigned HOST_WIDE_INT sel = UINTVAL (XEXP (x, 2)); + unsigned HOST_WIDE_INT mask = HOST_WIDE_INT_1U; + if (n_elts == HOST_BITS_PER_WIDE_INT) + mask = -1; + else + mask = (HOST_WIDE_INT_1U << n_elts) - 1; + SUBST (XEXP (x, 0), XEXP (x, 1)); + SUBST (XEXP (x, 1), temp); + SUBST (XEXP (x, 2), GEN_INT (~sel & mask)); + } } /* Simplify X, a piece of RTL. We just operate on the expression at the