[PATCH] RISC-V: Fix PR109399 VSETVL PASS bug
authorJuzhe-Zhong <juzhe.zhong@rivai.ai>
Wed, 5 Apr 2023 01:20:47 +0000 (19:20 -0600)
committerJeff Law <jlaw@ventanamicro>
Wed, 5 Apr 2023 01:21:48 +0000 (19:21 -0600)
        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
gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr109399.c [new file with mode: 0644]

index b5f5301..1b66e3b 100644 (file)
@@ -2683,7 +2683,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 (file)
index 0000000..b3abad7
--- /dev/null
@@ -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" } } } } */