From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 2EA1D3858422 for ; Mon, 14 Aug 2023 21:54:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EA1D3858422 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-26814e27a9eso2614795a91.0 for ; Mon, 14 Aug 2023 14:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692050057; x=1692654857; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RqV3mWDg2maTyZCKACxPteIXEZLBZ8YAeNgGCjVie5A=; b=j/cOvNuuf49yzsqFb696doxQGXpQ+snddKEt+9Kr2wxpQyGbhJ1BSpqXcyHc45ontw JfFXKpvCd0A0ToNZwajPaKIuN6Onf9LaaSYWIvGrhiDFumkNk5a5vQE4w0kKKNjnE5y9 O73KqRxfUSWJhHwwglvVSjwVCL5jpVIpcvDlglRQpfv5DCMWlx1LyeF3drOKF1Smvp1K Ieyz3bX9J5oQs0/LhKdRMZxUFotR2DqH/vjkUIO0w1hXBLWCuLtudmnKWmMN8DE4zTbf iyo/pNQMCJER2CKDW3cSVXgkIutogBmVDWqjs/mYJY4biVaBvJpZw/MwSJuUATOqmOB+ Z3Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692050057; x=1692654857; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RqV3mWDg2maTyZCKACxPteIXEZLBZ8YAeNgGCjVie5A=; b=G/qXkYPFntGXxFHe5tyi7BFR/e+TV2oz8vFHt6bduhclTuyxFD3viA3VbrDHTF8GB0 UA/2pfWpeWuyyjLkvz8y4knG+MGKup16HlJdXa7JfG+/4S2VoKAm48Rr56VF4PQ2K58T dnGs3fKvgeaBIo58BesTtobJQTsHWS+MkLxSj3tqiadRsLTuDN8GwNtx3++M4o+GtyKI vu+89SPSCIX25h3NLDyqKYDejMTsIhReDLU2wikWW10xEvxct9iSJT/TO1ZIdPkYgAv1 qmrw30WnjxiiVM/+eVtIdz+8Irn7+hsHewgP+O1fjQ+j72DQnPKHDL+i3VJ7AkSGIX4Q lKbw== X-Gm-Message-State: AOJu0YznhK+Dwn+h2sfDEeZzOu8BB+z9oWTW/J1Y9UYOq2r54qIz4LQh bgN5ccOelYgXtQ32hH5EvJlkBVa9mhPE1/Dj6Dk= X-Google-Smtp-Source: AGHT+IG5K31UDDRhx+Ktnw8lij+mW0s/8ZndIKXvUhA4oZx5ad1mWN97mUk5kItmg9Trrr5qgsQ9wDRKAtb0J8fbzCs= X-Received: by 2002:a17:90a:86ca:b0:26b:6a2f:7d90 with SMTP id y10-20020a17090a86ca00b0026b6a2f7d90mr1803075pjv.23.1692050056897; Mon, 14 Aug 2023 14:54:16 -0700 (PDT) MIME-Version: 1.0 References: <20230812080521.2814979-1-apinski@marvell.com> In-Reply-To: From: Andrew Pinski Date: Mon, 14 Aug 2023 14:54:04 -0700 Message-ID: Subject: Re: [PATCH] Add support for vector conitional not To: Richard Sandiford , Andrew Pinski via Gcc-patches , Andrew Pinski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 List-Id: On Mon, Aug 14, 2023 at 2:37=E2=80=AFPM Richard Sandiford via Gcc-patches wrote: > > Andrew Pinski via Gcc-patches writes: > > 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 =3D FN (scalar, vector), keyed off the vect= or mode > > @@ -276,6 +277,7 @@ DEF_INTERNAL_COND_FN (FNMA, ECF_CONST, fnma, ternar= y) > > 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)))) > > Looks like this should be IFN_COND_NOT rather than vec_cond. Yes that should have been IFN_COND_NOT, when I was converting it to be explicitly IFN_COND_NOT rather than depending on vec_cond, I had missed that part of the conversion. Thanks for noticing that. > > LGTM otherwise, but please give Richi 24hrs to comment. Will do. Thanks, Andrew > > Thanks, > Richard > > > + > > /* Simplify: > > > > a =3D 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=3Dsve_width=3D256 -fd= ump-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 =3D 0; i < 1024; ++i) > > + r[i] =3D pred[i] !=3D 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" } } */