public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] vect: Allow same precision for bit-precision conversions.
@ 2023-10-30 18:31 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2023-10-30 18:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a3311fd16fea0c55d309f689f09f840ffac0b3a5

commit a3311fd16fea0c55d309f689f09f840ffac0b3a5
Author: Robin Dapp <rdapp@ventanamicro.com>
Date:   Sun Oct 15 22:36:59 2023 +0200

    vect: Allow same precision for bit-precision conversions.
    
    In PR111794 we miss a vectorization because on riscv type precision and
    mode precision differ for mask types.  We can still vectorize when
    allowing assignments with the same precision for dest and source which
    is what this patch does.
    
    gcc/ChangeLog:
    
            PR tree-optimization/111794
            * tree-vect-stmts.cc (vectorizable_assignment): Add
            same-precision exception for dest and source.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/riscv/rvv/autovec/slp-mask-1.c: New test.
            * gcc.target/riscv/rvv/autovec/slp-mask-run-1.c: New test.
    
    (cherry picked from commit 32b74c9e1d46932a4bbb1f46353bfc43c702c20a)

Diff:
---
 .../gcc.target/riscv/rvv/autovec/slp-mask-1.c      | 18 +++++++++++++
 .../gcc.target/riscv/rvv/autovec/slp-mask-run-1.c  | 31 ++++++++++++++++++++++
 gcc/tree-vect-stmts.cc                             |  6 ++---
 3 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-1.c
new file mode 100644
index 000000000000..ee1baa58d634
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-1.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-std=gnu99 -O3 -march=rv64gcv -mabi=lp64d --param=riscv-autovec-preference=scalable -fdump-tree-slp-details" } */
+
+void
+__attribute__ ((noipa))
+f (int *restrict x, short *restrict y, int *restrict res)
+{
+  res[0] = x[0] == 1 & y[0] == 2;
+  res[1] = x[1] == 1 & y[1] == 2;
+  res[2] = x[2] == 1 & y[2] == 2;
+  res[3] = x[3] == 1 & y[3] == 2;
+  res[4] = x[4] == 1 & y[4] == 2;
+  res[5] = x[5] == 1 & y[5] == 2;
+  res[6] = x[6] == 1 & y[6] == 2;
+  res[7] = x[7] == 1 & y[7] == 2;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorizing stmts using SLP" 1 "slp2" } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-run-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-run-1.c
new file mode 100644
index 000000000000..b3469c41c878
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/slp-mask-run-1.c
@@ -0,0 +1,31 @@
+/* { dg-do run { target { riscv_v } } } */
+/* { dg-additional-options "-std=gnu99 -O3 -march=rv64gcv -mabi=lp64d --param=riscv-autovec-preference=scalable" } */
+
+#include <malloc.h>
+#include <stdio.h>
+
+#include "slp-mask-1.c"
+
+#define SZ 8
+
+__attribute__ ((optimize ("1")))
+int main ()
+{
+  int *a = malloc (SZ * sizeof (*a));
+  short *b = malloc (SZ * sizeof (*b));
+  int *res = malloc (SZ * sizeof (*res));
+  int *ref = malloc (SZ * sizeof (*ref));
+
+  for (int i = 0; i < SZ; i++)
+    {
+      a[i] = i & 1;
+      b[i] = 2;
+      ref[i] = a[i] == 1 & b[i] == 2;
+    }
+
+  f (a, b, res);
+
+  for (int i = 0; i < SZ; i++)
+    if (res[i] != ref[i])
+      __builtin_abort ();
+}
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 2f9cdcb282f0..f89ca4b24cfb 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -5952,9 +5952,9 @@ vectorizable_assignment (vec_info *vinfo,
 	   && TYPE_UNSIGNED (TREE_TYPE (op))))
     {
       if (dump_enabled_p ())
-        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                         "type conversion to/from bit-precision "
-                         "unsupported.\n");
+	dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+			 "type conversion to/from bit-precision "
+			 "unsupported.\n");
       return false;
     }

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

only message in thread, other threads:[~2023-10-30 18:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 18:31 [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] vect: Allow same precision for bit-precision conversions 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).