From patchwork Sat Aug 12 08:05:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 134830 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1584810vqi; Sat, 12 Aug 2023 01:06:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG86CXMnIe69o+uZQpf7KZUZJ6bT+VE0aWQhSKaYGAW/0oWG1VO8w0n/vEH5IR06E60jVTq X-Received: by 2002:aa7:d048:0:b0:522:18b6:c01f with SMTP id n8-20020aa7d048000000b0052218b6c01fmr4983109edo.3.1691827583862; Sat, 12 Aug 2023 01:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691827583; cv=none; d=google.com; s=arc-20160816; b=XJPcuds2oZcMhCDRI/aM5xsVqioIKVAK96cMlrfmoLugTXDXayAYTQQ9/2OKhNarLc KBUT0NmEl0rPwabk+gpoKtIBEoDF7W1LcZmEwkMwFC0Jc08HLPWbuq7+Kow6UYVBQWtR TkekcWkdyCsVmSSqMfp4Z6CBzJgjLMTxwTkpYNm0+zzOEXGpw52lUBiZvHdVXm2G4Di8 HxrUMEBXBnP4ZNFIEBoaII90mqapT+DDR8ZLl3RtqRixUSl5i0EGN1m54eFLTok7Tmpq MQ9jarX06GTBYxdQMg3msUWevvvg1WGoxytGnNoNhDIeMr8nThcJ+Nsf9nzAh1zD/7Q7 bbQA== 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=bbifM8e+Z5vIoKT+AmVYyY8NkOa/jAqZwPOczPSkFbY=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=tKNuDQFCyKTFZM0Bq13ieD/zljDtzsCOaYU2dxRexI++dweWPdDNZVYe1xnigZBkW4 h70lt56rniw08sdkX9Wc7ONagn+68ApMp54QMw7hQU73ItXZvG7jNqb8ShVEyg1m/WSc FsSuxEn4S3Z+Ju93cc5Z5vXtXlXT3VBL5z4gYVsFQ1oBJwK3c48a0Z9cWNdb4UTs7JSx f9CxjJwit+hM+dtIAo9ARwzr4UUzR7bnV54KNpJLolaGOzYWzlMPU/kLN4KDpoLVkJpZ 6o+UqfVkbU0Wn7wq305WgDHy60k2V55REMSb6F9E/W1dfLL2HI4tVJBNsp5FJf02CEq6 43YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fKX1C5nN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b3-20020aa7c6c3000000b0052337f4402asi4857160eds.474.2023.08.12.01.06.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Aug 2023 01:06:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fKX1C5nN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 884C03858D1E for ; Sat, 12 Aug 2023 08:06:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 884C03858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691827582; bh=bbifM8e+Z5vIoKT+AmVYyY8NkOa/jAqZwPOczPSkFbY=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=fKX1C5nNFvXTzXKGVX4dBz/AA82tpZ48OPAcuANv84IbVoxeesNrhKYQ5Cy5qtKq5 urZl61mig/g8oxMt3gjminGqeNqO21SGE1ruFhPv6XazyS3jvq47OHynMTx0MCF6K+ Y2PuyV+iKXK4eEqPN1v0nAFMa1ceuJdT1rhDLLO4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id B44363858D1E for ; Sat, 12 Aug 2023 08:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B44363858D1E Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37C5J3Sf016369 for ; Sat, 12 Aug 2023 01:05:38 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3se3d2regm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 12 Aug 2023 01:05:37 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 12 Aug 2023 01:05:35 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sat, 12 Aug 2023 01:05:35 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 852AE3F7041; Sat, 12 Aug 2023 01:05:35 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] Add support for vector conitional not Date: Sat, 12 Aug 2023 01:05:21 -0700 Message-ID: <20230812080521.2814979-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: sD0ORWfye299EjDxRBfxqqHP3zUjrcFt X-Proofpoint-ORIG-GUID: sD0ORWfye299EjDxRBfxqqHP3zUjrcFt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-12_06,2023-08-10_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774009800582066674 X-GMAIL-MSGID: 1774009800582066674 Like the support conditional neg (r12-4470-g20dcda98ed376cb61c74b2c71), this just adds conditional not too. Also we should be able to turn `(a ? -1 : 0) ^ b` into a conditional not. OK? Bootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu. gcc/ChangeLog: * internal-fn.def (COND_NOT): New internal function. * match.pd (UNCOND_UNARY, COND_UNARY): Add bit_not/not to the lists. (`vec (a ? -1 : 0) ^ b`): New pattern to convert into conditional not. * optabs.def (cond_one_cmpl): New optab. (cond_len_one_cmpl): Likewise. gcc/testsuite/ChangeLog: PR target/110986 * gcc.target/aarch64/sve/cond_unary_9.c: New test. --- gcc/internal-fn.def | 2 ++ gcc/match.pd | 15 ++++++++++++-- gcc/optabs.def | 2 ++ .../gcc.target/aarch64/sve/cond_unary_9.c | 20 +++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cond_unary_9.c diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index b3c410f4b6a..3e8693dfddb 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -69,6 +69,7 @@ along with GCC; see the file COPYING3. If not see lround2. - cond_binary: a conditional binary optab, such as cond_add + - cond_unary: a conditional unary optab, such as cond_neg - cond_ternary: a conditional ternary optab, such as cond_fma_rev - fold_left: for scalar = FN (scalar, vector), keyed off the vector mode @@ -276,6 +277,7 @@ DEF_INTERNAL_COND_FN (FNMA, ECF_CONST, fnma, ternary) DEF_INTERNAL_COND_FN (FNMS, ECF_CONST, fnms, ternary) DEF_INTERNAL_COND_FN (NEG, ECF_CONST, neg, unary) +DEF_INTERNAL_COND_FN (NOT, ECF_CONST, one_cmpl, unary) DEF_INTERNAL_OPTAB_FN (RSQRT, ECF_CONST, rsqrt, unary) diff --git a/gcc/match.pd b/gcc/match.pd index 6791060891d..2ee6d24ccee 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -84,9 +84,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Unary operations and their associated IFN_COND_* function. */ (define_operator_list UNCOND_UNARY - negate) + negate bit_not) (define_operator_list COND_UNARY - IFN_COND_NEG) + IFN_COND_NEG IFN_COND_NOT) /* Binary operations and their associated IFN_COND_* function. */ (define_operator_list UNCOND_BINARY @@ -8482,6 +8482,17 @@ and, && is_truth_type_for (op_type, TREE_TYPE (@0))) (cond_op (bit_not @0) @2 @1))))) +/* `(a ? -1 : 0) ^ b` can be converted into a conditional not. */ +(simplify + (bit_xor:c (vec_cond @0 uniform_integer_cst_p@1 uniform_integer_cst_p@2) @3) + (if (canonicalize_math_after_vectorization_p () + && vectorized_internal_fn_supported_p (IFN_COND_NOT, type) + && is_truth_type_for (type, TREE_TYPE (@0))) + (if (integer_all_onesp (@1) && integer_zerop (@2)) + (IFN_COND_NOT @0 @3 @3)) + (if (integer_all_onesp (@2) && integer_zerop (@1)) + (vec_cond (bit_not @0) @3 @3)))) + /* Simplify: a = a1 op a2 diff --git a/gcc/optabs.def b/gcc/optabs.def index 1ea1947b3b5..a58819bc665 100644 --- a/gcc/optabs.def +++ b/gcc/optabs.def @@ -254,6 +254,7 @@ OPTAB_D (cond_fms_optab, "cond_fms$a") OPTAB_D (cond_fnma_optab, "cond_fnma$a") OPTAB_D (cond_fnms_optab, "cond_fnms$a") OPTAB_D (cond_neg_optab, "cond_neg$a") +OPTAB_D (cond_one_cmpl_optab, "cond_one_cmpl$a") OPTAB_D (cond_len_add_optab, "cond_len_add$a") OPTAB_D (cond_len_sub_optab, "cond_len_sub$a") OPTAB_D (cond_len_smul_optab, "cond_len_mul$a") @@ -278,6 +279,7 @@ OPTAB_D (cond_len_fms_optab, "cond_len_fms$a") OPTAB_D (cond_len_fnma_optab, "cond_len_fnma$a") OPTAB_D (cond_len_fnms_optab, "cond_len_fnms$a") OPTAB_D (cond_len_neg_optab, "cond_len_neg$a") +OPTAB_D (cond_len_one_cmpl_optab, "cond_len_one_cmpl$a") OPTAB_D (cmov_optab, "cmov$a6") OPTAB_D (cstore_optab, "cstore$a4") OPTAB_D (ctrap_optab, "ctrap$a4") diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_9.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_9.c new file mode 100644 index 00000000000..d6bc0409630 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_unary_9.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256 -fdump-tree-optimized" } */ + +/* This is a reduced version of cond_unary_5.c */ + +void __attribute__ ((noipa)) +f (short *__restrict r, + short *__restrict a, + short *__restrict pred) +{ + for (int i = 0; i < 1024; ++i) + r[i] = pred[i] != 0 ? ~(a[i]) : a[i]; +} + +/* { dg-final { scan-assembler-times {\tnot\tz[0-9]+\.h, p[0-7]/m,} 1 } } */ + +/* { dg-final { scan-assembler-not {\teor\tz} } } */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.h, p[0-7]/m, #-1} } } */ + +/* { dg-final { scan-tree-dump-times ".COND_NOT " 1 "optimized" } } */