public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Juzhe-Zhong <juzhe.zhong@rivai.ai>
To: gcc-patches@gcc.gnu.org
Cc: Juzhe-Zhong <juzhe.zhong@rivai.ai>
Subject: [Committed] RISC-V: Tweak generic vector COST model
Date: Fri, 15 Dec 2023 06:24:32 +0800	[thread overview]
Message-ID: <20231214222432.60088-1-juzhe.zhong@rivai.ai> (raw)

Notice current generic vector cost model make PR112387 failed to vectorize.

Adapt it same as ARM SVE generic vector cost model which can fix it.

Committed as it is obvious fix.

	PR target/112387

gcc/ChangeLog:

	* config/riscv/riscv.cc: Adapt generic cost model same ARM SVE.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/costmodel/riscv/rvv/pr112387.c: Moved to...
	* gcc.dg/vect/costmodel/riscv/rvv/pr112387-1.c: ...here.
	* gcc.dg/vect/costmodel/riscv/rvv/pr112387-2.c: New test.

---
 gcc/config/riscv/riscv.cc                     | 24 +++++++++----------
 .../riscv/rvv/{pr112387.c => pr112387-1.c}    |  0
 .../vect/costmodel/riscv/rvv/pr112387-2.c     | 19 +++++++++++++++
 3 files changed, 31 insertions(+), 12 deletions(-)
 rename gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/{pr112387.c => pr112387-1.c} (100%)
 create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387-2.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 2dc44244309..481ad77dd49 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -355,13 +355,13 @@ static const common_vector_cost generic_vls_vector_cost = {
   1, /* fp_stmt_cost  */
   1, /* gather_load_cost  */
   1, /* scatter_store_cost  */
-  1, /* vec_to_scalar_cost  */
+  2, /* vec_to_scalar_cost  */
   1, /* scalar_to_vec_cost  */
-  1, /* permute_cost  */
-  3, /* align_load_cost  */
-  3, /* align_store_cost  */
-  3, /* unalign_load_cost  */
-  3, /* unalign_store_cost  */
+  2, /* permute_cost  */
+  1, /* align_load_cost  */
+  1, /* align_store_cost  */
+  1, /* unalign_load_cost  */
+  1, /* unalign_store_cost  */
 };
 
 /* Generic costs for VLA vector operations.  */
@@ -371,13 +371,13 @@ static const scalable_vector_cost generic_vla_vector_cost = {
     1, /* fp_stmt_cost  */
     1, /* gather_load_cost  */
     1, /* scatter_store_cost  */
-    1, /* vec_to_scalar_cost  */
+    2, /* vec_to_scalar_cost  */
     1, /* scalar_to_vec_cost  */
-    1, /* permute_cost  */
-    3, /* align_load_cost  */
-    3, /* align_store_cost  */
-    3, /* unalign_load_cost  */
-    3, /* unalign_store_cost  */
+    2, /* permute_cost  */
+    1, /* align_load_cost  */
+    1, /* align_store_cost  */
+    1, /* unalign_load_cost  */
+    1, /* unalign_store_cost  */
   },
 };
 
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387-1.c
similarity index 100%
rename from gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387.c
rename to gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387-1.c
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387-2.c b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387-2.c
new file mode 100644
index 00000000000..d9fcad6de9f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr112387-2.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -mtune=generic-ooo -O3 -ftree-vectorize -fdump-tree-vect-details" } */
+
+#include <stdint-gcc.h>
+
+void
+f2 (uint64_t *__restrict y, uint64_t *__restrict x,
+    uint64_t *__restrict indices, uint64_t n)
+{
+  for (int64_t i = 0; i < n; ++i)
+    {
+      y[i * 2] = x[indices[i * 2]] + 1;
+      y[i * 2 + 1] = x[indices[i * 2 + 1]] + 2;
+    }
+}
+
+/* { dg-final { scan-tree-dump "Loop contains only SLP stmts" vect } } */
+/* { dg-final { scan-assembler-not "vlseg" } } */
+/* { dg-final { scan-assembler-not "vsseg" } } */
-- 
2.36.3


                 reply	other threads:[~2023-12-14 22:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231214222432.60088-1-juzhe.zhong@rivai.ai \
    --to=juzhe.zhong@rivai.ai \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).