aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJu-Zhe Zhong <juzhe.zhong@rivai.ai>2022-12-14 16:25:58 +0800
committerKito Cheng <kito.cheng@sifive.com>2022-12-19 22:23:29 +0800
commit6c098f7d23db4dd98e7fed74a35416248397be40 (patch)
treebf2606c6744744daa20c6328ebb849262d95596a /gcc
parent5a1b66b77cfbf617494e1baad8cbf0fd2d1a0c54 (diff)
downloadgcc-6c098f7d23db4dd98e7fed74a35416248397be40.zip
gcc-6c098f7d23db4dd98e7fed74a35416248397be40.tar.gz
gcc-6c098f7d23db4dd98e7fed74a35416248397be40.tar.bz2
RISC-V: Add testcases for VSETVL PASS 5
gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-1.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-10.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-11.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-12.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-13.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-14.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-15.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-16.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-17.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-18.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-19.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-2.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-20.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-21.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-22.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-23.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-24.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-25.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-26.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-27.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-28.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-29.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-3.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-30.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-31.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-32.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-33.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-34.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-35.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-36.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-37.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-38.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-39.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-4.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-40.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-41.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-42.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-43.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-44.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-45.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-46.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-5.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-6.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-7.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-8.c: New test. * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-9.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-1.c36
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-10.c59
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-11.c63
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-12.c64
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-13.c64
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-14.c58
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-15.c143
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-16.c54
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-17.c59
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-18.c58
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-19.c48
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-2.c50
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-20.c59
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-21.c50
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-22.c58
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-23.c41
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-24.c41
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-25.c96
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-26.c89
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-27.c51
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-28.c54
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-29.c54
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-3.c47
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-30.c44
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-31.c46
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-32.c46
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-33.c45
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-34.c45
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-35.c38
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-36.c47
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-37.c41
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-38.c73
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-39.c20
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-4.c104
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-40.c22
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-41.c26
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-42.c26
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-43.c27
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-44.c28
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-45.c34
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-46.c32
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-5.c48
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-6.c155
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-7.c43
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-8.c149
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-9.c44
46 files changed, 2579 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-1.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-1.c
new file mode 100644
index 0000000..fbf451f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-1.c
@@ -0,0 +1,36 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-10.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-10.c
new file mode 100644
index 0000000..ba289f2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-10.c
@@ -0,0 +1,59 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond, int cond2, int cond3)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0)
+ {
+ if (cond2 == 11)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 2;
+ }
+ }
+ else if (cond2 == 111)
+ {
+ if (cond3 == 300)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + out[i];
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-11.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-11.c
new file mode 100644
index 0000000..44e8a3f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-11.c
@@ -0,0 +1,63 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond, int cond2, int cond3)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + i);
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200 + i);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300 + i);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400 + i);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500 + i);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0)
+ {
+ if (cond2 == 11)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 2;
+ }
+ }
+ else if (cond2 == 111)
+ {
+ if (cond3 == 300)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + out[i];
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 2000 + i);
+ *(vfloat32mf2_t*)(out + i + 4000) = v;
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-12.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-12.c
new file mode 100644
index 0000000..a8f5af9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-12.c
@@ -0,0 +1,64 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond, int cond2, int cond3)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + i);
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200 + i);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300 + i);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400 + i);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500 + i);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0)
+ {
+ if (cond2 == 11)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 2;
+ }
+ }
+ else if (cond2 == 111)
+ {
+ if (cond3 == 300)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + out[i];
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vint8mf2_t v = *(vint8mf2_t*)(in + 2000 + i);
+ *(vint8mf2_t*)(out + i + 4000) = v;
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-13.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-13.c
new file mode 100644
index 0000000..31034bc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-13.c
@@ -0,0 +1,64 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond, int cond2, int cond3)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + i);
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200 + i);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300 + i);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400 + i);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500 + i);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0)
+ {
+ if (cond2 == 11)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 2;
+ }
+ }
+ else if (cond2 == 111)
+ {
+ if (cond3 == 300)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + out[i];
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vint8mf2_t v = *(vint8mf2_t*)(in + 2000 + i);
+ *(vint8mf2_t*)(out + i + 4000) = v;
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16m1_t v;
+ *(vint16m1_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e16,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-14.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-14.c
new file mode 100644
index 0000000..dececb4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-14.c
@@ -0,0 +1,58 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + i + 333) = v;
+ }
+ } else if (cond == 1){
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 444);
+ *(vint32mf2_t*)(out + i + 444) = v;
+ }
+ } else if (cond == 2) {
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 555);
+ *(vint64m1_t*)(out + i + 555) = v;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 666);
+ *(vfloat64m1_t*)(out + i + 666) = v;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-15.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-15.c
new file mode 100644
index 0000000..161d14c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-15.c
@@ -0,0 +1,143 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + i + 333) = v;
+ }
+ } else if (cond == 1){
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 444);
+ *(vint32mf2_t*)(out + i + 444) = v;
+ }
+ } else if (cond == 2) {
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 555);
+ *(vint64m1_t*)(out + i + 555) = v;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 666);
+ *(vfloat64m1_t*)(out + i + 666) = v;
+ }
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + i + 333) = v;
+ }
+ } else if (cond == 1){
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 444);
+ *(vint32mf2_t*)(out + i + 444) = v;
+ }
+ } else if (cond == 2) {
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 555);
+ *(vint64m1_t*)(out + i + 555) = v;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 666);
+ *(vfloat64m1_t*)(out + i + 666) = v;
+ }
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + i + 333) = v;
+ }
+ } else if (cond == 1){
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 444);
+ *(vint32mf2_t*)(out + i + 444) = v;
+ }
+ } else if (cond == 2) {
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 555);
+ *(vint64m1_t*)(out + i + 555) = v;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 666);
+ *(vfloat64m1_t*)(out + i + 666) = v;
+ }
+ }
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + i + 333) = v;
+ }
+ } else if (cond == 1){
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 444);
+ *(vint32mf2_t*)(out + i + 444) = v;
+ }
+ } else if (cond == 2) {
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 555);
+ *(vint64m1_t*)(out + i + 555) = v;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 666);
+ *(vfloat64m1_t*)(out + i + 666) = v;
+ }
+ }
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + i + 333) = v;
+ }
+ } else if (cond == 1){
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 444);
+ *(vint32mf2_t*)(out + i + 444) = v;
+ }
+ } else if (cond == 2) {
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 555);
+ *(vint64m1_t*)(out + i + 555) = v;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 666);
+ *(vfloat64m1_t*)(out + i + 666) = v;
+ }
+ }
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-16.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-16.c
new file mode 100644
index 0000000..84abe55
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-16.c
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 771);
+ *(vint8mf8_t*)(out + 771) = v;
+ vint32mf2_t v2 = *(vint32mf2_t*)(in + 71);
+ *(vint32mf2_t*)(out + 71) = v2;
+ vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in + 17);
+ *(vfloat32mf2_t*)(out + 17) = v3;
+ vuint32mf2_t v4 = *(vuint32mf2_t*)(in + 117);
+ *(vuint32mf2_t*)(out + 117) = v4;
+ } else {
+ vfloat32mf2_t v0 = *(vfloat32mf2_t*)(in + 1123);
+ *(vfloat32mf2_t*)(out + 1123) = v0;
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + 333) = v;
+ vbool64_t v2 = *(vbool64_t*)(in + 91);
+ *(vbool64_t*)(out + 91) = v2;
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-flto" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-17.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-17.c
new file mode 100644
index 0000000..1f3bae2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-17.c
@@ -0,0 +1,59 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++){
+ vint8mf8_t v = *(vint8mf8_t*)(in + 771 + i);
+ *(vint8mf8_t*)(out + 771 + i) = v;
+ vint32mf2_t v2 = *(vint32mf2_t*)(in + 71 + i);
+ *(vint32mf2_t*)(out + 71 + i) = v2;
+ vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in + 17 + i);
+ *(vfloat32mf2_t*)(out + 17 + i) = v3;
+ vuint32mf2_t v4 = *(vuint32mf2_t*)(in + 117 + i);
+ *(vuint32mf2_t*)(out + 117 + i) = v4;
+ }
+ } else {
+ for (int i = 0; i < n; i++){
+ vfloat32mf2_t v0 = *(vfloat32mf2_t*)(in + 1123 + i);
+ *(vfloat32mf2_t*)(out + 1123 + i) = v0;
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333 + i);
+ *(vint8mf8_t*)(out + 333 + i) = v;
+ vbool64_t v2 = *(vbool64_t*)(in + 91 + i);
+ *(vbool64_t*)(out + 91 + i) = v2;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-18.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-18.c
new file mode 100644
index 0000000..33885e7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-18.c
@@ -0,0 +1,58 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++){
+ vint8mf8_t v = *(vint8mf8_t*)(in + 771 + i);
+ *(vint8mf8_t*)(out + 771 + i) = v;
+ vint32mf2_t v2 = *(vint32mf2_t*)(in + 71 + i);
+ *(vint32mf2_t*)(out + 71 + i) = v2;
+ vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in + 17 + i);
+ *(vfloat32mf2_t*)(out + 17 + i) = v3;
+ vuint32mf2_t v4 = *(vuint32mf2_t*)(in + 117 + i);
+ *(vuint32mf2_t*)(out + 117 + i) = v4;
+ }
+ } else {
+ vfloat32mf2_t v0 = *(vfloat32mf2_t*)(in + 1123);
+ *(vfloat32mf2_t*)(out + 1123) = v0;
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + 333) = v;
+ vbool64_t v2 = *(vbool64_t*)(in + 91);
+ *(vbool64_t*)(out + 91) = v2;
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-19.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-19.c
new file mode 100644
index 0000000..213c48a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-19.c
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 771);
+ *(vint8mf8_t*)(out + 771) = v;
+ vint32mf2_t v2 = *(vint32mf2_t*)(in + 71);
+ *(vint32mf2_t*)(out + 71) = v2;
+ vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in + 17);
+ *(vfloat32mf2_t*)(out + 17) = v3;
+ vuint32mf2_t v4 = *(vuint32mf2_t*)(in + 117);
+ *(vuint32mf2_t*)(out + 117) = v4;
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-2.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-2.c
new file mode 100644
index 0000000..b8c2cc0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-2.c
@@ -0,0 +1,50 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 2;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + out[i];
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] * 2;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] * out[i];
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] * out[i] + 100;
+ }
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-20.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-20.c
new file mode 100644
index 0000000..1f3bae2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-20.c
@@ -0,0 +1,59 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++){
+ vint8mf8_t v = *(vint8mf8_t*)(in + 771 + i);
+ *(vint8mf8_t*)(out + 771 + i) = v;
+ vint32mf2_t v2 = *(vint32mf2_t*)(in + 71 + i);
+ *(vint32mf2_t*)(out + 71 + i) = v2;
+ vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in + 17 + i);
+ *(vfloat32mf2_t*)(out + 17 + i) = v3;
+ vuint32mf2_t v4 = *(vuint32mf2_t*)(in + 117 + i);
+ *(vuint32mf2_t*)(out + 117 + i) = v4;
+ }
+ } else {
+ for (int i = 0; i < n; i++){
+ vfloat32mf2_t v0 = *(vfloat32mf2_t*)(in + 1123 + i);
+ *(vfloat32mf2_t*)(out + 1123 + i) = v0;
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333 + i);
+ *(vint8mf8_t*)(out + 333 + i) = v;
+ vbool64_t v2 = *(vbool64_t*)(in + 91 + i);
+ *(vbool64_t*)(out + 91 + i) = v2;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-21.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-21.c
new file mode 100644
index 0000000..b60a652
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-21.c
@@ -0,0 +1,50 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++){
+ vint8mf8_t v = *(vint8mf8_t*)(in + 771 + i);
+ *(vint8mf8_t*)(out + 771 + i) = v;
+ vint32mf2_t v2 = *(vint32mf2_t*)(in + 71 + i);
+ *(vint32mf2_t*)(out + 71 + i) = v2;
+ vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in + 17 + i);
+ *(vfloat32mf2_t*)(out + 17 + i) = v3;
+ vuint32mf2_t v4 = *(vuint32mf2_t*)(in + 117 + i);
+ *(vuint32mf2_t*)(out + 117 + i) = v4;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-22.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-22.c
new file mode 100644
index 0000000..c4a0451
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-22.c
@@ -0,0 +1,58 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++){
+ vint8mf8_t v = *(vint8mf8_t*)(in + 771 + i);
+ *(vint8mf8_t*)(out + 771 + i) = v;
+ vint32mf2_t v2 = *(vint32mf2_t*)(in + 71 + i);
+ *(vint32mf2_t*)(out + 71 + i) = v2;
+ vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in + 17 + i);
+ *(vfloat32mf2_t*)(out + 17 + i) = v3;
+ vuint32mf2_t v4 = *(vuint32mf2_t*)(in + 117 + i);
+ *(vuint32mf2_t*)(out + 117 + i) = v4;
+ }
+ } else {
+ vfloat32mf2_t v0 = *(vfloat32mf2_t*)(in + 1123);
+ *(vfloat32mf2_t*)(out + 1123) = v0;
+ vint8mf8_t v = *(vint8mf8_t*)(in + 333);
+ *(vint8mf8_t*)(out + 333) = v;
+ vbool64_t v2 = *(vbool64_t*)(in + 91);
+ *(vbool64_t*)(out + 91) = v2;
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-23.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-23.c
new file mode 100644
index 0000000..36a18a4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-23.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ vint32mf2_t v;
+ *(vint32mf2_t*)(out + 7000) = v;
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 4 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-24.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-24.c
new file mode 100644
index 0000000..b4d4240b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-24.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ vint32mf2_t v;
+ *(vint32mf2_t*)(out + 7000) = v;
+
+ for (int i = 0; i < n; i++) {
+ vbool64_t v;
+ *(vbool64_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-25.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-25.c
new file mode 100644
index 0000000..4295ac3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-25.c
@@ -0,0 +1,96 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, int n, int cond)
+{
+ if (cond == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 100);
+ *(vint8mf8_t*)(out + 100) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v2;
+ *(vint16mf4_t*)(out + i + 100) = v2;
+ }
+ } else if (cond == 1) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 200);
+ *(vint8mf8_t*)(out + 200) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint32mf2_t v2;
+ *(vint32mf2_t*)(out + i + 200) = v2;
+ }
+ } else if (cond == 2) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 300);
+ *(vint8mf8_t*)(out + 300) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v2;
+ *(vint8mf8_t*)(out + i + 300) = v2;
+ }
+ } else if (cond == 3) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 400);
+ *(vint8mf8_t*)(out + 400) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint64m1_t v2;
+ *(vint64m1_t*)(out + i + 400) = v2;
+ }
+ } else if (cond == 4) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+ *(vint8mf8_t*)(out + 500) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v2;
+ *(vfloat32mf2_t*)(out + i + 500) = v2;
+ }
+ } else if (cond == 5) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 600);
+ *(vuint8mf8_t*)(out + 600) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint16mf4_t v2;
+ *(vuint16mf4_t*)(out + i + 600) = v2;
+ }
+ } else if (cond == 6) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 700);
+ *(vuint8mf8_t*)(out + 700) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint32mf2_t v2;
+ *(vuint32mf2_t*)(out + i + 700) = v2;
+ }
+ } else if (cond == 7) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 800);
+ *(vuint8mf8_t*)(out + 800) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint8mf8_t v2;
+ *(vuint8mf8_t*)(out + i + 800) = v2;
+ }
+ } else if (cond == 8) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 900);
+ *(vuint8mf8_t*)(out + 900) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint64m1_t v2;
+ *(vuint64m1_t*)(out + i + 900) = v2;
+ }
+ } else {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 1000);
+ *(vuint8mf8_t*)(out + 1000) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v2;
+ *(vfloat32mf2_t*)(out + i + 1000) = v2;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 4 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e64,\s*m1,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 10 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 20 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-26.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-26.c
new file mode 100644
index 0000000..59e069f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-26.c
@@ -0,0 +1,89 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, int n, int cond)
+{
+ if (cond == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 100);
+ *(vint8mf8_t*)(out + 100) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v2;
+ *(vint16mf4_t*)(out + i + 100) = v2;
+ }
+ } else if (cond == 1) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 200);
+ *(vint8mf8_t*)(out + 200) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint32mf2_t v2;
+ *(vint32mf2_t*)(out + i + 200) = v2;
+ }
+ } else if (cond == 2) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 300);
+ *(vint8mf8_t*)(out + 300) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v2;
+ *(vint8mf8_t*)(out + i + 300) = v2;
+ }
+ } else if (cond == 3) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 400);
+ *(vint8mf8_t*)(out + 400) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint64m1_t v2;
+ *(vint64m1_t*)(out + i + 400) = v2;
+ }
+ } else if (cond == 4) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+ *(vint8mf8_t*)(out + 500) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v2;
+ *(vfloat32mf2_t*)(out + i + 500) = v2;
+ }
+ } else if (cond == 5) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 600);
+ *(vuint8mf8_t*)(out + 600) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint16mf4_t v2;
+ *(vuint16mf4_t*)(out + i + 600) = v2;
+ }
+ } else if (cond == 6) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 700);
+ *(vuint8mf8_t*)(out + 700) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint32mf2_t v2;
+ *(vuint32mf2_t*)(out + i + 700) = v2;
+ }
+ } else if (cond == 7) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 800);
+ *(vuint8mf8_t*)(out + 800) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint8mf8_t v2;
+ *(vuint8mf8_t*)(out + i + 800) = v2;
+ }
+ } else if (cond == 8) {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 900);
+ *(vuint8mf8_t*)(out + 900) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vuint64m1_t v2;
+ *(vuint64m1_t*)(out + i + 900) = v2;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e64,\s*m1,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 8 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 17 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-27.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-27.c
new file mode 100644
index 0000000..e148a1c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-27.c
@@ -0,0 +1,51 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, void * restrict in2, void * restrict out2, int n, int cond)
+{
+ if (cond == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 100);
+ *(vint8mf8_t*)(out + 100) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v2;
+ *(vint16mf4_t*)(out + i + 100) = v2;
+ }
+ } else {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 1000);
+ *(vuint8mf8_t*)(out + 1000) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v2;
+ *(vfloat32mf2_t*)(out + i + 1000) = v2;
+ vbool64_t v3;
+ *(vbool64_t*)(out + i + 2000) = v3;
+ vbool32_t v4;
+ *(vbool32_t*)(out + i + 3000) = v4;
+ vbool16_t v5;
+ *(vbool16_t*)(out + i + 4000) = v5;
+ vbool8_t v6;
+ *(vbool8_t*)(out + i + 5000) = v6;
+ vbool4_t v7;
+ *(vbool4_t*)(out + i + 6000) = v7;
+ vbool2_t v8;
+ *(vbool2_t*)(out + i + 7000) = v8;
+ vbool1_t v9;
+ *(vbool1_t*)(out + i + 8000) = v9;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 9 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-28.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-28.c
new file mode 100644
index 0000000..e8340a6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-28.c
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, void * restrict in2, void * restrict out2, int n, int cond)
+{
+ if (cond == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 100);
+ *(vint8mf8_t*)(out + 100) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v2;
+ *(vint16mf4_t*)(out + i + 100) = v2;
+ }
+ } else {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + 1000);
+ *(vuint8mf8_t*)(out + 1000) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v2;
+ *(vfloat32mf2_t*)(out + i + 1000) = v2;
+ vbool64_t v3;
+ *(vbool64_t*)(out + i + 2000) = v3;
+ vbool32_t v4;
+ *(vbool32_t*)(out + i + 3000) = v4;
+ vbool16_t v5;
+ *(vbool16_t*)(out + i + 4000) = v5;
+ vbool8_t v6;
+ *(vbool8_t*)(out + i + 5000) = v6;
+ vbool4_t v7;
+ *(vbool4_t*)(out + i + 6000) = v7;
+ vbool2_t v8;
+ *(vbool2_t*)(out + i + 7000) = v8;
+ vbool1_t v9;
+ *(vbool1_t*)(out + i + 8000) = v9;
+ vuint32mf2_t v10;
+ *(vuint32mf2_t*)(out + i + 100000) = v10;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 10 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-29.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-29.c
new file mode 100644
index 0000000..74584e7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-29.c
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, void * restrict in2, void * restrict out2, int n, int cond)
+{
+ if (cond == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + 100);
+ *(vint8mf8_t*)(out + 100) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v2;
+ *(vint16mf4_t*)(out + i + 100) = v2;
+ }
+ } else {
+ vuint8mf8_t v;
+ *(vuint8mf8_t*)(out + 1000) = v;
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v2;
+ *(vfloat32mf2_t*)(out + i + 1000) = v2;
+ vbool64_t v3;
+ *(vbool64_t*)(out + i + 2000) = v3;
+ vbool32_t v4;
+ *(vbool32_t*)(out + i + 3000) = v4;
+ vbool16_t v5;
+ *(vbool16_t*)(out + i + 4000) = v5;
+ vbool8_t v6;
+ *(vbool8_t*)(out + i + 5000) = v6;
+ vbool4_t v7;
+ *(vbool4_t*)(out + i + 6000) = v7;
+ vbool2_t v8;
+ *(vbool2_t*)(out + i + 7000) = v8;
+ vbool1_t v9;
+ *(vbool1_t*)(out + i + 8000) = v9;
+ vuint32mf2_t v10;
+ *(vuint32mf2_t*)(out + i + 100000) = v10;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 11 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-3.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-3.c
new file mode 100644
index 0000000..63f6c72
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-3.c
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 2;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 3;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-30.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-30.c
new file mode 100644
index 0000000..92bf3ab
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-30.c
@@ -0,0 +1,44 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, void * restrict in2, void * restrict out2, int n, int cond)
+{
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v2 = *(vfloat32mf2_t*)(in + i + 1000);
+ *(vfloat32mf2_t*)(out + i + 1000) = v2;
+ vbool32_t v4;
+ *(vbool32_t*)(out + i + 3000) = v4;
+ vbool16_t v5;
+ *(vbool16_t*)(out + i + 4000) = v5;
+ vbool8_t v6;
+ *(vbool8_t*)(out + i + 5000) = v6;
+ vbool4_t v7;
+ *(vbool4_t*)(out + i + 6000) = v7;
+ vbool2_t v8;
+ *(vbool2_t*)(out + i + 7000) = v8;
+ vbool1_t v9;
+ *(vbool1_t*)(out + i + 8000) = v9;
+ vuint32mf2_t v10 = *(vuint32mf2_t*)(in + i + 100000);
+ *(vuint32mf2_t*)(out + i + 100000) = v10;
+ }
+
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1;
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli} 9 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-31.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-31.c
new file mode 100644
index 0000000..4d25457
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-31.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, void * restrict in2, void * restrict out2, int n, int cond)
+{
+ for (int i = 0; i < n; i++)
+ {
+ vuint16mf4_t v2 = *(vuint16mf4_t*)(in + i + 1000);
+ *(vuint16mf4_t*)(out + i + 1000) = v2;
+ vbool32_t v4;
+ *(vbool32_t*)(out + i + 3000) = v4;
+ vbool16_t v5;
+ *(vbool16_t*)(out + i + 4000) = v5;
+ vbool8_t v6;
+ *(vbool8_t*)(out + i + 5000) = v6;
+ vbool4_t v7;
+ *(vbool4_t*)(out + i + 6000) = v7;
+ vbool2_t v8;
+ *(vbool2_t*)(out + i + 7000) = v8;
+ vbool1_t v9;
+ *(vbool1_t*)(out + i + 8000) = v9;
+ vuint32mf2_t v10 = *(vuint32mf2_t*)(in + i + 100000);
+ *(vuint32mf2_t*)(out + i + 100000) = v10;
+ }
+
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1;
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli} 9 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-32.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-32.c
new file mode 100644
index 0000000..284df72
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-32.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, void * restrict in2, void * restrict out2, int n, int cond)
+{
+ for (int i = 0; i < n; i++)
+ {
+ vuint16mf4_t v2 = *(vuint16mf4_t*)(in + i + 1000);
+ *(vuint16mf4_t*)(out + i + 1000) = v2;
+ vbool32_t v4;
+ *(vbool32_t*)(out + i + 3000) = v4;
+ vbool16_t v5;
+ *(vbool16_t*)(out + i + 4000) = v5;
+ vbool8_t v6;
+ *(vbool8_t*)(out + i + 5000) = v6;
+ vbool4_t v7;
+ *(vbool4_t*)(out + i + 6000) = v7;
+ vbool2_t v8;
+ *(vbool2_t*)(out + i + 7000) = v8;
+ vbool1_t v9;
+ *(vbool1_t*)(out + i + 8000) = v9;
+ vuint32mf2_t v10;
+ *(vuint32mf2_t*)(out + i + 100000) = v10;
+ }
+
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1 = *(vint8mf8_t*)(in + i + 100000);
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9]:+} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli} 8 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-33.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-33.c
new file mode 100644
index 0000000..1057b1b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-33.c
@@ -0,0 +1,45 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (void * restrict in, void * restrict out, void * restrict in2, void * restrict out2, int n, int cond)
+{
+ for (int i = 0; i < n; i++)
+ {
+ vuint16mf4_t v2;
+ *(vuint16mf4_t*)(out + i + 1000) = v2;
+ vbool32_t v4;
+ *(vbool32_t*)(out + i + 3000) = v4;
+ vbool16_t v5;
+ *(vbool16_t*)(out + i + 4000) = v5;
+ vbool8_t v6;
+ *(vbool8_t*)(out + i + 5000) = v6;
+ vbool4_t v7;
+ *(vbool4_t*)(out + i + 6000) = v7;
+ vbool2_t v8;
+ *(vbool2_t*)(out + i + 7000) = v8;
+ vbool1_t v9;
+ *(vbool1_t*)(out + i + 8000) = v9;
+ vuint32mf2_t v10;
+ *(vuint32mf2_t*)(out + i + 100000) = v10;
+ }
+
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1 = *(vint8mf8_t*)(in + i + 100000);
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli} 8 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-34.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-34.c
new file mode 100644
index 0000000..9746ebe
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-34.c
@@ -0,0 +1,45 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int32_t * restrict in2, int32_t * restrict out2, int n, int cond)
+{
+ if (cond == 0)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] + in[i];
+ }
+ }
+ else if (cond == 1)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] + in[i];
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out2[i] / in[i];
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] * in[i];
+ }
+ }
+ else
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = in[i] + 4;
+ }
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1;
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-35.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-35.c
new file mode 100644
index 0000000..0547d62
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-35.c
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int32_t * restrict in2, int32_t * restrict out2, int n, int cond)
+{
+ if (cond == 0)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] + in[i];
+ }
+ }
+ else if (cond == 1)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] + in[i];
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out2[i] / in[i];
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] * in[i];
+ }
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1;
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-36.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-36.c
new file mode 100644
index 0000000..a82b86f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-36.c
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int32_t * restrict in2, int32_t * restrict out2, int n, int cond)
+{
+ if (cond == 0)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] + in[i];
+ }
+ }
+ else if (cond == 1)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] + in[i];
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out2[i] / in[i];
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out2[i] = out[i] * in[i];
+ }
+ }
+ else
+ {
+ for (int i = 0; i < n; i++)
+ {
+ vint32mf2_t v1 = *(vint32mf2_t*)in2;
+ *(vint32mf2_t*)(out + i + 10) = v1;
+ }
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1;
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9]+:} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-37.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-37.c
new file mode 100644
index 0000000..981e90e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-37.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void fn3 (void);
+
+void f (int32_t * restrict in, int32_t * restrict out, int32_t * restrict in2, int32_t * restrict out2, int n, int cond)
+{
+ if (cond == 0)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v1 = *(vfloat32mf2_t*)(in + 1000);
+ *(vfloat32mf2_t*)(out + i + 1000) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint32mf2_t v1 = *(vint32mf2_t*)in;
+ *(vint32mf2_t*)(out + i + 10) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v1 = *(vint16mf4_t*)(in + 100);
+ *(vint16mf4_t*)(out + i + 100) = v1;
+ }
+ }
+ else
+ {
+ fn3 ();
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1;
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-38.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-38.c
new file mode 100644
index 0000000..79dbeefb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-38.c
@@ -0,0 +1,73 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int32_t * restrict in2, int32_t * restrict out2, int n, int cond, int cond2)
+{
+ if (cond == 0)
+ {
+ if (cond2) {
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v1 = *(vfloat32mf2_t*)(in + 1000);
+ *(vfloat32mf2_t*)(out + i + 1000) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint32mf2_t v1 = *(vint32mf2_t*)in;
+ *(vint32mf2_t*)(out + i + 10) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v1 = *(vint16mf4_t*)(in + 100);
+ *(vint16mf4_t*)(out + i + 100) = v1;
+ }
+ } else {
+ for (int i = 0; i < n; i++)
+ {
+ vfloat32mf2_t v1 = *(vfloat32mf2_t*)(in + 2000);
+ *(vfloat32mf2_t*)(out + i + 2000) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint32mf2_t v1 = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 200) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v1 = *(vint16mf4_t*)(in + 300);
+ *(vint16mf4_t*)(out + i + 300) = v1;
+ }
+ }
+ }
+ else
+ {
+ for (int i = 0; i < n; i++)
+ {
+ vint16mf4_t v1 = *(vint16mf4_t*)(in + 30000);
+ *(vint16mf4_t*)(out + i + 30000) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint32mf2_t v1 = *(vint32mf2_t*)(in + 40000);
+ *(vint32mf2_t*)(out + i + 40000) = v1;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vuint32mf2_t v1 = *(vuint32mf2_t*)(in + 50000);
+ *(vuint32mf2_t*)(out + i + 50000) = v1;
+ }
+ }
+ for (int i = 0; i < n; i++)
+ {
+ vint8mf8_t v1;
+ *(vint8mf8_t*)(out + i + 10) = v1;
+ }
+}
+
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 4 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-39.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-39.c
new file mode 100644
index 0000000..c3eb6f9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-39.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_3 (int32_t * restrict in, int32_t * restrict out, size_t n, int cond)
+{
+ vint8mf2_t v;
+ for (size_t i = 0; i < n; i++)
+ {
+ if (i % 2 == 0) {
+ v = *(vint8mf2_t*)(in + i);
+ } else {
+ *(vint8mf2_t*)(out + i) = v;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+j\s+\.L[0-9]+} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-4.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-4.c
new file mode 100644
index 0000000..0ba6004
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-4.c
@@ -0,0 +1,104 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 2;
+ }
+ } else if (cond == 1){
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 3;
+ }
+ } else if (cond == 2) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 5;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 6;
+ }
+ } else if (cond == 4) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 8;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 9;
+ }
+ } else if (cond == 5) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 10;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 11;
+ }
+ } else if (cond == 6) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 12;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 13;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] * out[i];
+ }
+ } else if (cond == 7) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 15;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 16;
+ }
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + out[i];
+ }
+ } else if (cond == 8) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 101;
+ }
+ } else if (cond == 9) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] * 101;
+ }
+ } else if (cond == 10) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] >> 3;
+ }
+ } else {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] << 1;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-40.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-40.c
new file mode 100644
index 0000000..67f1a33
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-40.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_4 (int32_t * restrict in, int32_t * restrict out, size_t n, size_t m, int cond)
+{
+ vint8mf2_t v;
+ for (size_t i = 0; i < n; i++)
+ {
+ for (size_t j = 0; j < m; j += 1) {
+ if (j % 2 == 0) {
+ v = *(vint8mf2_t*)(in + i + j);
+ } else {
+ *(vint8mf2_t*)(out + i + j) = v;
+ }
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9]+} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-41.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-41.c
new file mode 100644
index 0000000..b2f4fee
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-41.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_5 (int32_t * restrict in, int32_t * restrict out, size_t n, size_t m, int cond)
+{
+ vint8mf2_t v;
+ for (size_t i = 0; i < n; i++)
+ {
+ if (i % 2) {
+ for (size_t j = 0; j < m; j += 1) {
+ if (j % 2 == 0) {
+ v = *(vint8mf2_t*)(in + i + j);
+ } else {
+ *(vint8mf2_t*)(out + i + j) = v;
+ }
+ }
+ } else {
+ *(vint8mf2_t*)(out + i) = v;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-42.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-42.c
new file mode 100644
index 0000000..4eb57de
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-42.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_6 (int32_t * restrict in, int32_t * restrict out, size_t n, size_t m, int cond)
+{
+ vint8mf2_t v;
+ for (size_t i = 0; i < n; i++)
+ {
+ if (i % 2) {
+ for (size_t j = 0; j < m; j += 1) {
+ if (j % 2 == 0) {
+ v = *(vint8mf2_t*)(in + i + j);
+ } else {
+ *(vint8mf2_t*)(out + i + j) = v;
+ }
+ }
+ } else {
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-43.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-43.c
new file mode 100644
index 0000000..047369e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-43.c
@@ -0,0 +1,27 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_3 (int32_t * restrict in, int32_t * restrict out, size_t n, int cond)
+{
+ for (size_t i = 0; i < n; i++)
+ {
+ if (i % 16 == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+ *(vint8mf8_t*)(out + i + 100) = v;
+ } else if (i % 8 == 0) {
+ vint16mf4_t v = *(vint16mf4_t*)(in + i + 200);
+ *(vint16mf4_t*)(out + i + 200) = v;
+ } else if (i % 4 == 0) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + i + 300);
+ *(vint32mf2_t*)(out + i + 300) = v;
+ } else {
+ vbool64_t v = *(vbool64_t*)(in + i + 400);
+ *(vbool64_t*)(out + i + 400) = v;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-44.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-44.c
new file mode 100644
index 0000000..05e9810
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-44.c
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_4 (int32_t * restrict in, int32_t * restrict out, size_t n, size_t m, int cond)
+{
+ for (size_t i = 0; i < n; i++)
+ {
+ for (size_t j = 0; j < m; j += 1) {
+ if (i % 16 == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + i + 100 + j);
+ *(vint8mf8_t*)(out + i + 100 + j) = v;
+ } else if (i % 8 == 0) {
+ vint16mf4_t v = *(vint16mf4_t*)(in + i + 200 + j);
+ *(vint16mf4_t*)(out + i + 200 + j) = v;
+ } else if (i % 4 == 0) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + i + 300 + j);
+ *(vint32mf2_t*)(out + i + 300 + j) = v;
+ } else {
+ vbool64_t v = *(vbool64_t*)(in + i + 400 + j);
+ *(vbool64_t*)(out + i + 400 + j) = v;
+ }
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-45.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-45.c
new file mode 100644
index 0000000..0f6b96e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-45.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_5 (int32_t * restrict in, int32_t * restrict out, size_t n, size_t m, int cond)
+{
+ for (size_t i = 0; i < n; i++)
+ {
+ if (i % 2) {
+ for (size_t j = 0; j < m; j += 1) {
+ if (i % 16 == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + i + 100 + j);
+ *(vint8mf8_t*)(out + i + 100 + j) = v;
+ } else if (i % 8 == 0) {
+ vint16mf4_t v = *(vint16mf4_t*)(in + i + 200 + j);
+ *(vint16mf4_t*)(out + i + 200 + j) = v;
+ } else if (i % 4 == 0) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + i + 300 + j);
+ *(vint32mf2_t*)(out + i + 300 + j) = v;
+ } else {
+ vbool64_t v = *(vbool64_t*)(in + i + 400 + j);
+ *(vbool64_t*)(out + i + 400 + j) = v;
+ }
+ }
+ } else {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 88888);
+ *(vfloat32mf2_t*)(out + 88888) = v;
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+j\s+\.L[0-9]+} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-46.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-46.c
new file mode 100644
index 0000000..a211bed
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-46.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void foo5_6 (int32_t * restrict in, int32_t * restrict out, size_t n, size_t m, int cond)
+{
+ for (size_t i = 0; i < n; i++)
+ {
+ if (i % 2) {
+ for (size_t j = 0; j < m; j += 1) {
+ if (i % 16 == 0) {
+ vint8mf8_t v = *(vint8mf8_t*)(in + i + 100 + j);
+ *(vint8mf8_t*)(out + i + 100 + j) = v;
+ } else if (i % 8 == 0) {
+ vint16mf4_t v = *(vint16mf4_t*)(in + i + 200 + j);
+ *(vint16mf4_t*)(out + i + 200 + j) = v;
+ } else if (i % 4 == 0) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + i + 300 + j);
+ *(vint32mf2_t*)(out + i + 300 + j) = v;
+ } else {
+ vbool64_t v = *(vbool64_t*)(in + i + 400 + j);
+ *(vbool64_t*)(out + i + 400 + j) = v;
+ }
+ }
+ } else {
+ }
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-5.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-5.c
new file mode 100644
index 0000000..b38e362
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-5.c
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ switch (cond)
+ {
+ case 0:
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 2;
+ }
+ break;
+
+ default:
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 3;
+ }
+ break;
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-6.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-6.c
new file mode 100644
index 0000000..2edc181
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-6.c
@@ -0,0 +1,155 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ switch (cond)
+ {
+ case 0:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 2;
+ }
+ }
+ break;
+ case 1:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 3;
+ }
+ }
+ break;
+ case 2:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 5;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 6;
+ }
+ }
+ break;
+ case 4:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 8;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 9;
+ }
+ }
+ break;
+ case 5:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 10;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 11;
+ }
+ }
+ break;
+ case 6:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 12;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 13;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] * out[i];
+ }
+ }
+ break;
+ case 7:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 15;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 16;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + out[i];
+ }
+ }
+ break;
+ case 8:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 101;
+ }
+ }
+ break;
+ case 9:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] * 101;
+ }
+ }
+ break;
+ case 10:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] >> 3;
+ }
+ }
+ break;
+ default:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] << 1;
+ }
+ }
+ break;
+ }
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-7.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-7.c
new file mode 100644
index 0000000..68d595f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-7.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 2;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-8.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-8.c
new file mode 100644
index 0000000..f49eebd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-8.c
@@ -0,0 +1,149 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ switch (cond)
+ {
+ case 0:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 2;
+ }
+ }
+ break;
+ case 1:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 3;
+ }
+ }
+ break;
+ case 2:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 5;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 6;
+ }
+ }
+ break;
+ case 4:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 8;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 9;
+ }
+ }
+ break;
+ case 5:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 10;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 11;
+ }
+ }
+ break;
+ case 6:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 12;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 13;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] * out[i];
+ }
+ }
+ break;
+ case 7:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 15;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 16;
+ }
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + out[i];
+ }
+ }
+ break;
+ case 8:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] + 101;
+ }
+ }
+ break;
+ case 9:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] * 101;
+ }
+ }
+ break;
+ case 10:
+ {
+ for (int i = 0; i < n; i++)
+ {
+ out[i] = out[i] >> 3;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-9.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-9.c
new file mode 100644
index 0000000..8483cdc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-9.c
@@ -0,0 +1,44 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * restrict in, int32_t * restrict out, int n, int cond)
+{
+ for (int i = 0; i < n; i++) {
+ vint8mf8_t v = *(vint8mf8_t*)in;
+ *(vint8mf8_t*)(out + i + 200) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+ *(vint32mf2_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vint64m1_t v = *(vint64m1_t*)(in + 300);
+ *(vint64m1_t*)(out + i + 400) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 400);
+ *(vfloat32mf2_t*)(out + i + 500) = v;
+ }
+ for (int i = 0; i < n; i++) {
+ vfloat64m1_t v = *(vfloat64m1_t*)(in + 500);
+ *(vfloat64m1_t*)(out + i + 600) = v;
+ }
+
+ if (cond == 0) {
+ for (int i = 0; i < n; i++) {
+ out[i] = out[i] + 2;
+ }
+ }
+
+ for (int i = 0; i < n; i++) {
+ vint16mf4_t v;
+ *(vint16mf4_t*)(out + i + 700) = v;
+ }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+[a-x0-9]+,\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+zero,\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 1 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-O1" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+