public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Fix PR109399 VSETVL PASS bug
@ 2023-04-04  8:46 juzhe.zhong
  2023-04-05  1:26 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: juzhe.zhong @ 2023-04-04  8:46 UTC (permalink / raw)
  To: gcc-patches; +Cc: kito.cheng, palmer, Juzhe-Zhong

From: Juzhe-Zhong <juzhe.zhong@rivai.ai>

This patch fix bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109399

        PR 109399

gcc/ChangeLog:

        * config/riscv/riscv-vsetvl.cc (pass_vsetvl::compute_local_backward_infos): Update user vsetvl in local demand fusion.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/vsetvl/pr109399.c: New test.

---
 gcc/config/riscv/riscv-vsetvl.cc                   |  8 +++++++-
 .../gcc.target/riscv/rvv/vsetvl/pr109399.c         | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr109399.c

diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 4d043c0645b..7e8a5376705 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -2715,7 +2715,13 @@ pass_vsetvl::compute_local_backward_infos (const bb_info *bb)
 	      if (!(propagate_avl_across_demands_p (change, info)
 		    && !reg_available_p (insn, change))
 		  && change.compatible_p (info))
-		info = change.merge (info);
+		{
+		  info = change.merge (info);
+		  /* Fix PR109399, we should update user vsetvl instruction
+		     if there is a change in demand fusion.  */
+		  if (vsetvl_insn_p (insn->rtl ()))
+		    change_vsetvl_insn (insn, info);
+		}
 	    }
 	  change = info;
 	}
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr109399.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr109399.c
new file mode 100644
index 00000000000..b3abad7a8bf
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr109399.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize -fno-schedule-insns -fno-schedule-insns2" } */
+
+#include "riscv_vector.h"
+
+void foo(void *in1, void *in2, void *in3, void *out, size_t n) {
+  size_t vl = __riscv_vsetvlmax_e32m1();
+  vint32m1_t a = __riscv_vle32_v_i32m1(in1, vl);
+  vint32m1_t b = __riscv_vle32_v_i32m1_tu(a, in2, vl);
+  vint32m1_t c = __riscv_vle32_v_i32m1_tu(b, in3, vl);
+  __riscv_vse32_v_i32m1(out, c, vl);
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*m1,\s*tu,\s*m[au]} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-Oz" no-opts "-funroll-loops" no-opts "-g" } } } } */
-- 
2.36.3


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

* Re: [PATCH] RISC-V: Fix PR109399 VSETVL PASS bug
  2023-04-04  8:46 [PATCH] RISC-V: Fix PR109399 VSETVL PASS bug juzhe.zhong
@ 2023-04-05  1:26 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2023-04-05  1:26 UTC (permalink / raw)
  To: juzhe.zhong, gcc-patches; +Cc: kito.cheng, palmer



On 4/4/23 02:46, juzhe.zhong@rivai.ai wrote:
> From: Juzhe-Zhong <juzhe.zhong@rivai.ai>
> 
> This patch fix bug:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109399
> 
>          PR 109399
> 
> gcc/ChangeLog:
> 
>          * config/riscv/riscv-vsetvl.cc (pass_vsetvl::compute_local_backward_infos): Update user vsetvl in local demand fusion.
> 
> gcc/testsuite/ChangeLog:
> 
>          * gcc.target/riscv/rvv/vsetvl/pr109399.c: New test.
Thanks.  Installed.

I noted that change_vsetvl_insn does not have a function comment.  Can 
you please add one.  Perhaps something like this:

/* INSN is either a vector configuration insn, or an insn with a vtype
    that is immediately preceded by a vector configuration insn.  In
    both cases, change the vector configuration insn to utilize the
    vector configuration state in INFO.  */


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

end of thread, other threads:[~2023-04-05  1:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-04  8:46 [PATCH] RISC-V: Fix PR109399 VSETVL PASS bug juzhe.zhong
2023-04-05  1:26 ` 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).