public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][GCC 13] RISC-V: Fix recursive vsetvli checking [PR114172]
@ 2024-04-24 10:09 Kito Cheng
  2024-04-24 10:11 ` juzhe.zhong
  0 siblings, 1 reply; 3+ messages in thread
From: Kito Cheng @ 2024-04-24 10:09 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, rdapp, juzhe.zhong; +Cc: Kito Cheng

extract_single_source will recursive checking the sources to
make sure if it's single source, however it may cause infinite
recursive when the source is come from itself, so it should just skip
first source to prevent that.

NOTE: This logic has existing on trunk/GCC 14, but it included in a big
vsetvli improvement patch, which is not backport to GCC 13.

```

void saxpy_rvv_m8(float *y, long vl)
{
    for (;;)
    {
        vl = __riscv_vsetvl_e32m8(vl); //ICE
        vfloat32m8_t y_vec;
        __riscv_vse32_v_f32m8(y, y_vec, vl);
    }
}
```

gcc/ChangeLog:

	PR target/114172
	* gcc/config/riscv/riscv-vsetvl.cc (extract_single_source):
	Skip first set.

gcc/testsuite/ChangeLog:

	PR target/114172
	* gcc.target/riscv/rvv/vsetvl/pr114172.c: New.
---
 gcc/config/riscv/riscv-vsetvl.cc                   |  4 ++++
 .../gcc.target/riscv/rvv/vsetvl/pr114172.c         | 14 ++++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c

diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 9dca2ce709d..36d2e6e6f20 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -1196,6 +1196,10 @@ extract_single_source (set_info *set)
     return nullptr;
   for (const set_info *set : sets)
     {
+      /* Skip first set, this can prevent us run into infinite recursive
+	 checking if first set is come from itself.  */
+      if (set == *sets.begin ())
+	continue;
       /* If there is a head or end insn, we conservative return
 	 NULL so that VSETVL PASS will insert vsetvl directly.  */
       if (set->insn ()->is_artificial ())
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
new file mode 100644
index 00000000000..ed1494666d6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void e(long, vfloat32m4_t);
+
+void b(long c) {
+  for (;;) {
+    c = __riscv_vsetvl_e32m4(c);
+    vfloat32m4_t d;
+    e(c, d);
+  }
+}
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][GCC 13] RISC-V: Fix recursive vsetvli checking [PR114172]
  2024-04-24 10:09 [PATCH][GCC 13] RISC-V: Fix recursive vsetvli checking [PR114172] Kito Cheng
@ 2024-04-24 10:11 ` juzhe.zhong
  2024-04-24 13:18   ` Kito Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: juzhe.zhong @ 2024-04-24 10:11 UTC (permalink / raw)
  To: Kito.cheng, gcc-patches, kito.cheng, Robin Dapp; +Cc: Kito.cheng

[-- Attachment #1: Type: text/plain, Size: 2501 bytes --]

lgtm.



juzhe.zhong@rivai.ai
 
From: Kito Cheng
Date: 2024-04-24 18:09
To: gcc-patches; kito.cheng; rdapp; juzhe.zhong
CC: Kito Cheng
Subject: [PATCH][GCC 13] RISC-V: Fix recursive vsetvli checking [PR114172]
extract_single_source will recursive checking the sources to
make sure if it's single source, however it may cause infinite
recursive when the source is come from itself, so it should just skip
first source to prevent that.
 
NOTE: This logic has existing on trunk/GCC 14, but it included in a big
vsetvli improvement patch, which is not backport to GCC 13.
 
```
 
void saxpy_rvv_m8(float *y, long vl)
{
    for (;;)
    {
        vl = __riscv_vsetvl_e32m8(vl); //ICE
        vfloat32m8_t y_vec;
        __riscv_vse32_v_f32m8(y, y_vec, vl);
    }
}
```
 
gcc/ChangeLog:
 
PR target/114172
* gcc/config/riscv/riscv-vsetvl.cc (extract_single_source):
Skip first set.
 
gcc/testsuite/ChangeLog:
 
PR target/114172
* gcc.target/riscv/rvv/vsetvl/pr114172.c: New.
---
gcc/config/riscv/riscv-vsetvl.cc                   |  4 ++++
.../gcc.target/riscv/rvv/vsetvl/pr114172.c         | 14 ++++++++++++++
2 files changed, 18 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
 
diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 9dca2ce709d..36d2e6e6f20 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -1196,6 +1196,10 @@ extract_single_source (set_info *set)
     return nullptr;
   for (const set_info *set : sets)
     {
+      /* Skip first set, this can prevent us run into infinite recursive
+ checking if first set is come from itself.  */
+      if (set == *sets.begin ())
+ continue;
       /* If there is a head or end insn, we conservative return
NULL so that VSETVL PASS will insert vsetvl directly.  */
       if (set->insn ()->is_artificial ())
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
new file mode 100644
index 00000000000..ed1494666d6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void e(long, vfloat32m4_t);
+
+void b(long c) {
+  for (;;) {
+    c = __riscv_vsetvl_e32m4(c);
+    vfloat32m4_t d;
+    e(c, d);
+  }
+}
-- 
2.34.1
 
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][GCC 13] RISC-V: Fix recursive vsetvli checking [PR114172]
  2024-04-24 10:11 ` juzhe.zhong
@ 2024-04-24 13:18   ` Kito Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Kito Cheng @ 2024-04-24 13:18 UTC (permalink / raw)
  To: juzhe.zhong; +Cc: Kito.cheng, gcc-patches, Robin Dapp

thanks, committed :)

On Wed, Apr 24, 2024 at 6:12 PM juzhe.zhong@rivai.ai
<juzhe.zhong@rivai.ai> wrote:
>
> lgtm.
>
> ________________________________
> juzhe.zhong@rivai.ai
>
>
> From: Kito Cheng
> Date: 2024-04-24 18:09
> To: gcc-patches; kito.cheng; rdapp; juzhe.zhong
> CC: Kito Cheng
> Subject: [PATCH][GCC 13] RISC-V: Fix recursive vsetvli checking [PR114172]
> extract_single_source will recursive checking the sources to
> make sure if it's single source, however it may cause infinite
> recursive when the source is come from itself, so it should just skip
> first source to prevent that.
>
> NOTE: This logic has existing on trunk/GCC 14, but it included in a big
> vsetvli improvement patch, which is not backport to GCC 13.
>
> ```
>
> void saxpy_rvv_m8(float *y, long vl)
> {
>     for (;;)
>     {
>         vl = __riscv_vsetvl_e32m8(vl); //ICE
>         vfloat32m8_t y_vec;
>         __riscv_vse32_v_f32m8(y, y_vec, vl);
>     }
> }
> ```
>
> gcc/ChangeLog:
>
> PR target/114172
> * gcc/config/riscv/riscv-vsetvl.cc (extract_single_source):
> Skip first set.
>
> gcc/testsuite/ChangeLog:
>
> PR target/114172
> * gcc.target/riscv/rvv/vsetvl/pr114172.c: New.
> ---
> gcc/config/riscv/riscv-vsetvl.cc                   |  4 ++++
> .../gcc.target/riscv/rvv/vsetvl/pr114172.c         | 14 ++++++++++++++
> 2 files changed, 18 insertions(+)
> create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
>
> diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
> index 9dca2ce709d..36d2e6e6f20 100644
> --- a/gcc/config/riscv/riscv-vsetvl.cc
> +++ b/gcc/config/riscv/riscv-vsetvl.cc
> @@ -1196,6 +1196,10 @@ extract_single_source (set_info *set)
>      return nullptr;
>    for (const set_info *set : sets)
>      {
> +      /* Skip first set, this can prevent us run into infinite recursive
> + checking if first set is come from itself.  */
> +      if (set == *sets.begin ())
> + continue;
>        /* If there is a head or end insn, we conservative return
> NULL so that VSETVL PASS will insert vsetvl directly.  */
>        if (set->insn ()->is_artificial ())
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
> new file mode 100644
> index 00000000000..ed1494666d6
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv64gcv -mabi=lp64 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void e(long, vfloat32m4_t);
> +
> +void b(long c) {
> +  for (;;) {
> +    c = __riscv_vsetvl_e32m4(c);
> +    vfloat32m4_t d;
> +    e(c, d);
> +  }
> +}
> --
> 2.34.1
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-24 13:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24 10:09 [PATCH][GCC 13] RISC-V: Fix recursive vsetvli checking [PR114172] Kito Cheng
2024-04-24 10:11 ` juzhe.zhong
2024-04-24 13:18   ` Kito Cheng

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).