public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] Add support for vector conitional not
@ 2023-11-21  4:12 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2023-11-21  4:12 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:61999e80e49cca3a2f0e2957516915d11bb71ce9

commit 61999e80e49cca3a2f0e2957516915d11bb71ce9
Author: Andrew Pinski <apinski@marvell.com>
Date:   Fri Aug 11 18:19:01 2023 -0700

    Add support for vector conitional not
    
    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.
    
    (cherry picked from commit a32de58c9e6394e4e6aef0ac95b52d1c774ac8bc)

Diff:
---
 gcc/internal-fn.def                                 |  2 ++
 gcc/match.pd                                        |  2 +-
 gcc/optabs.def                                      |  1 +
 gcc/testsuite/gcc.target/aarch64/sve/cond_unary_9.c | 20 ++++++++++++++++++++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def
index 332b2bc8fff..0d7515eb6c9 100644
--- a/gcc/internal-fn.def
+++ b/gcc/internal-fn.def
@@ -71,6 +71,7 @@ along with GCC; see the file COPYING3.  If not see
      lround<srcmode><dstmode>2.
 
    - cond_binary: a conditional binary optab, such as cond_add<mode>
+   - cond_unary: a conditional unary optab, such as cond_neg<mode>
    - cond_ternary: a conditional ternary optab, such as cond_fma_rev<mode>
 
    - fold_left: for scalar = FN (scalar, vector), keyed off the vector mode
@@ -257,6 +258,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 27325d0acb0..1d7ab38d373 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -82,7 +82,7 @@ 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_NOT)
 (define_operator_list COND_LEN_UNARY
diff --git a/gcc/optabs.def b/gcc/optabs.def
index a9298bd7c3b..408d5a2feab 100644
--- a/gcc/optabs.def
+++ b/gcc/optabs.def
@@ -256,6 +256,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")
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" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-21  4:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21  4:12 [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] Add support for vector conitional not Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).