public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Add testcases for VSETVL PASS 4
@ 2022-12-14  8:19 juzhe.zhong
  2022-12-19 15:09 ` Kito Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: juzhe.zhong @ 2022-12-14  8:19 UTC (permalink / raw)
  To: gcc-patches; +Cc: kito.cheng, palmer, Ju-Zhe Zhong

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

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-21.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-22.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-23.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-24.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-4.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-5.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-6.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-7.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-8.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-9.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_call-1.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_call-2.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_call-3.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_call-4.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-1.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-2.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-1.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-10.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-11.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-12.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-2.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-4.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-5.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-6.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-8.c: New test.
        * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-9.c: New test.

---
 .../riscv/rvv/vsetvl/vlmax_bb_prop-1.c        | 182 ++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-10.c       | 230 +++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-11.c       |  43 ++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-12.c       | 266 ++++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-13.c       | 221 +++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-14.c       | 221 +++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-15.c       |  41 ++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-16.c       | 257 ++++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-17.c       | 177 ++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-18.c       | 177 ++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-19.c       |  34 ++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-2.c        | 182 ++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-20.c       | 203 +++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-21.c       | 155 +++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-22.c       | 155 +++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-23.c       |  30 +
 .../riscv/rvv/vsetvl/vlmax_bb_prop-24.c       | 180 ++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-25.c       | 572 ++++++++++++++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-26.c       | 492 +++++++++++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-27.c       | 491 +++++++++++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-28.c       |  86 +++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-3.c        |  35 ++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-4.c        | 210 +++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-5.c        | 167 +++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-6.c        | 167 +++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-7.c        |  32 +
 .../riscv/rvv/vsetvl/vlmax_bb_prop-8.c        | 194 ++++++
 .../riscv/rvv/vsetvl/vlmax_bb_prop-9.c        | 230 +++++++
 .../riscv/rvv/vsetvl/vlmax_call-1.c           | 239 ++++++++
 .../riscv/rvv/vsetvl/vlmax_call-2.c           | 207 +++++++
 .../riscv/rvv/vsetvl/vlmax_call-3.c           | 207 +++++++
 .../riscv/rvv/vsetvl/vlmax_call-4.c           |  39 ++
 .../riscv/rvv/vsetvl/vlmax_complex_loop-1.c   |  52 ++
 .../riscv/rvv/vsetvl/vlmax_complex_loop-2.c   |  56 ++
 .../riscv/rvv/vsetvl/vlmax_conflict-1.c       |  23 +
 .../riscv/rvv/vsetvl/vlmax_conflict-10.c      |  27 +
 .../riscv/rvv/vsetvl/vlmax_conflict-11.c      |  24 +
 .../riscv/rvv/vsetvl/vlmax_conflict-12.c      |  39 ++
 .../riscv/rvv/vsetvl/vlmax_conflict-2.c       |  23 +
 .../riscv/rvv/vsetvl/vlmax_conflict-3.c       |  30 +
 .../riscv/rvv/vsetvl/vlmax_conflict-4.c       |  29 +
 .../riscv/rvv/vsetvl/vlmax_conflict-5.c       |  32 +
 .../riscv/rvv/vsetvl/vlmax_conflict-6.c       |  26 +
 .../riscv/rvv/vsetvl/vlmax_conflict-7.c       |  26 +
 .../riscv/rvv/vsetvl/vlmax_conflict-8.c       |  27 +
 .../riscv/rvv/vsetvl/vlmax_conflict-9.c       |  27 +
 46 files changed, 6563 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-21.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-22.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-23.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-24.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-5.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-6.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-7.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-8.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-9.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-10.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-11.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-12.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-5.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-6.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-8.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-9.c

diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c
new file mode 100644
index 00000000000..3e27a8abf10
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c
@@ -0,0 +1,182 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 600);
+    *(vint8mf8_t*)(out + 600) = v;
+  } else {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 700);
+    *(vint8mf8_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 600);
+    *(vint8mf4_t*)(out + 600) = v;
+  } else {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 700);
+    *(vint8mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 600);
+    *(vint8mf2_t*)(out + 600) = v;
+  } else {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 700);
+    *(vint8mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 600);
+    *(vint16mf4_t*)(out + 600) = v;
+  } else {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 700);
+    *(vint16mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 600);
+    *(vint16mf2_t*)(out + 600) = v;
+  } else {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 700);
+    *(vint16mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 600);
+    *(vint32mf2_t*)(out + 600) = v;
+  } else {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 700);
+    *(vint32mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c
new file mode 100644
index 00000000000..51d3fcf7613
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c
@@ -0,0 +1,230 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 700);
+    *(vint8mf8_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 700);
+    *(vint8mf4_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 700);
+    *(vint8mf2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 700);
+    *(vint16mf4_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 700);
+    *(vint16mf2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 700);
+    *(vuint32mf2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c
new file mode 100644
index 00000000000..3c2badd7793
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c
@@ -0,0 +1,43 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 700);
+    *(vfloat32mf2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-12.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c
new file mode 100644
index 00000000000..6ace4c4ef18
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c
@@ -0,0 +1,266 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vbool64_t v = *(vbool64_t*)(in + 700);
+    *(vbool64_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vbool32_t v = *(vbool32_t*)(in + 700);
+    *(vbool32_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vbool16_t v = *(vbool16_t*)(in + 700);
+    *(vbool16_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vbool8_t v = *(vbool8_t*)(in + 700);
+    *(vbool8_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vbool4_t v = *(vbool4_t*)(in + 700);
+    *(vbool4_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vbool2_t v = *(vbool2_t*)(in + 700);
+    *(vbool2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f7 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vbool1_t v = *(vbool1_t*)(in + 700);
+    *(vbool1_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c
new file mode 100644
index 00000000000..8ce380bea07
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c
@@ -0,0 +1,221 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-14.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c
new file mode 100644
index 00000000000..a43aad71808
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c
@@ -0,0 +1,221 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
+    *(vuint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
+    *(vuint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
+    *(vuint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
+    *(vuint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
+    *(vuint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
+    *(vuint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
+    *(vuint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
+    *(vuint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
+    *(vuint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
+    *(vuint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-15.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c
new file mode 100644
index 00000000000..6938cf80723
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-16.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c
new file mode 100644
index 00000000000..10901a0b205
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c
@@ -0,0 +1,257 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f7 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c
new file mode 100644
index 00000000000..01345617fab
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c
@@ -0,0 +1,177 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint8mf8_t v = *(vint8mf8_t*)(in + 100);
+      *(vint8mf8_t*)(out + 100) = v;
+    }
+  else
+    {
+      vint8mf8_t v = *(vint8mf8_t*)(in + 200);
+      *(vint8mf8_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint8mf8_t v = *(vint8mf8_t*)(in + i);
+      *(vint8mf8_t*)(out + i) = v;
+    }
+}
+
+void f2 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint8mf4_t v = *(vint8mf4_t*)(in + 100);
+      *(vint8mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      vint8mf4_t v = *(vint8mf4_t*)(in + 200);
+      *(vint8mf4_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint8mf4_t v = *(vint8mf4_t*)(in + i);
+      *(vint8mf4_t*)(out + i) = v;
+    }
+}
+
+void f3 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint8mf2_t v = *(vint8mf2_t*)(in + 100);
+      *(vint8mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vint8mf2_t v = *(vint8mf2_t*)(in + 200);
+      *(vint8mf2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint8mf2_t v = *(vint8mf2_t*)(in + i);
+      *(vint8mf2_t*)(out + i) = v;
+    }
+}
+
+void f4 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint16mf4_t v = *(vint16mf4_t*)(in + 100);
+      *(vint16mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      vint16mf4_t v = *(vint16mf4_t*)(in + 200);
+      *(vint16mf4_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint16mf4_t v = *(vint16mf4_t*)(in + i);
+      *(vint16mf4_t*)(out + i) = v;
+    }
+}
+
+void f5 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint16mf2_t v = *(vint16mf2_t*)(in + 100);
+      *(vint16mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vint16mf2_t v = *(vint16mf2_t*)(in + 200);
+      *(vint16mf2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint16mf2_t v = *(vint16mf2_t*)(in + i);
+      *(vint16mf2_t*)(out + i) = v;
+    }
+}
+
+void f6 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint32mf2_t v = *(vint32mf2_t*)(in + 100);
+      *(vint32mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+      *(vint32mf2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint32mf2_t v = *(vint32mf2_t*)(in + i);
+      *(vint32mf2_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\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 {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-18.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c
new file mode 100644
index 00000000000..c296670e2d5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c
@@ -0,0 +1,177 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint8mf8_t v = *(vuint8mf8_t*)(in + 100);
+      *(vuint8mf8_t*)(out + 100) = v;
+    }
+  else
+    {
+      vuint8mf8_t v = *(vuint8mf8_t*)(in + 200);
+      *(vuint8mf8_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint8mf8_t v = *(vuint8mf8_t*)(in + i);
+      *(vuint8mf8_t*)(out + i) = v;
+    }
+}
+
+void f2 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint8mf4_t v = *(vuint8mf4_t*)(in + 100);
+      *(vuint8mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      vuint8mf4_t v = *(vuint8mf4_t*)(in + 200);
+      *(vuint8mf4_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint8mf4_t v = *(vuint8mf4_t*)(in + i);
+      *(vuint8mf4_t*)(out + i) = v;
+    }
+}
+
+void f3 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint8mf2_t v = *(vuint8mf2_t*)(in + 100);
+      *(vuint8mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vuint8mf2_t v = *(vuint8mf2_t*)(in + 200);
+      *(vuint8mf2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint8mf2_t v = *(vuint8mf2_t*)(in + i);
+      *(vuint8mf2_t*)(out + i) = v;
+    }
+}
+
+void f4 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint16mf4_t v = *(vuint16mf4_t*)(in + 100);
+      *(vuint16mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      vuint16mf4_t v = *(vuint16mf4_t*)(in + 200);
+      *(vuint16mf4_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint16mf4_t v = *(vuint16mf4_t*)(in + i);
+      *(vuint16mf4_t*)(out + i) = v;
+    }
+}
+
+void f5 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint16mf2_t v = *(vuint16mf2_t*)(in + 100);
+      *(vuint16mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vuint16mf2_t v = *(vuint16mf2_t*)(in + 200);
+      *(vuint16mf2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint16mf2_t v = *(vuint16mf2_t*)(in + i);
+      *(vuint16mf2_t*)(out + i) = v;
+    }
+}
+
+void f6 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint32mf2_t v = *(vuint32mf2_t*)(in + 100);
+      *(vuint32mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vuint32mf2_t v = *(vuint32mf2_t*)(in + 200);
+      *(vuint32mf2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint32mf2_t v = *(vuint32mf2_t*)(in + i);
+      *(vuint32mf2_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\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 {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-19.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c
new file mode 100644
index 00000000000..d87b2381daf
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c
@@ -0,0 +1,34 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f6 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 100);
+      *(vfloat32mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 200);
+      *(vfloat32mf2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i);
+      *(vfloat32mf2_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\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 {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-2.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c
new file mode 100644
index 00000000000..ce94f4a12b2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c
@@ -0,0 +1,182 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
+    *(vuint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 600);
+    *(vuint8mf8_t*)(out + 600) = v;
+  } else {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 700);
+    *(vuint8mf8_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
+    *(vuint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 600);
+    *(vuint8mf4_t*)(out + 600) = v;
+  } else {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 700);
+    *(vuint8mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
+    *(vuint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 600);
+    *(vuint8mf2_t*)(out + 600) = v;
+  } else {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 700);
+    *(vuint8mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
+    *(vuint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 600);
+    *(vuint16mf4_t*)(out + 600) = v;
+  } else {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 700);
+    *(vuint16mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
+    *(vuint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 600);
+    *(vuint16mf2_t*)(out + 600) = v;
+  } else {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 700);
+    *(vuint16mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 600);
+    *(vuint32mf2_t*)(out + 600) = v;
+  } else {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 700);
+    *(vuint32mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c
new file mode 100644
index 00000000000..273a2853282
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c
@@ -0,0 +1,203 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool64_t v = *(vbool64_t*)(in + 100);
+      *(vbool64_t*)(out + 100) = v;
+    }
+  else
+    {
+      vbool64_t v = *(vbool64_t*)(in + 200);
+      *(vbool64_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool64_t v = *(vbool64_t*)(in + i);
+      *(vbool64_t*)(out + i) = v;
+    }
+}
+
+void f2 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool32_t v = *(vbool32_t*)(in + 100);
+      *(vbool32_t*)(out + 100) = v;
+    }
+  else
+    {
+      vbool32_t v = *(vbool32_t*)(in + 200);
+      *(vbool32_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool32_t v = *(vbool32_t*)(in + i);
+      *(vbool32_t*)(out + i) = v;
+    }
+}
+
+void f3 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool16_t v = *(vbool16_t*)(in + 100);
+      *(vbool16_t*)(out + 100) = v;
+    }
+  else
+    {
+      vbool16_t v = *(vbool16_t*)(in + 200);
+      *(vbool16_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool16_t v = *(vbool16_t*)(in + i);
+      *(vbool16_t*)(out + i) = v;
+    }
+}
+
+void f4 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool8_t v = *(vbool8_t*)(in + 100);
+      *(vbool8_t*)(out + 100) = v;
+    }
+  else
+    {
+      vbool8_t v = *(vbool8_t*)(in + 200);
+      *(vbool8_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool8_t v = *(vbool8_t*)(in + i);
+      *(vbool8_t*)(out + i) = v;
+    }
+}
+
+void f5 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool4_t v = *(vbool4_t*)(in + 100);
+      *(vbool4_t*)(out + 100) = v;
+    }
+  else
+    {
+      vbool4_t v = *(vbool4_t*)(in + 200);
+      *(vbool4_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool4_t v = *(vbool4_t*)(in + i);
+      *(vbool4_t*)(out + i) = v;
+    }
+}
+
+void f6 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool2_t v = *(vbool2_t*)(in + 100);
+      *(vbool2_t*)(out + 100) = v;
+    }
+  else
+    {
+      vbool2_t v = *(vbool2_t*)(in + 200);
+      *(vbool2_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool2_t v = *(vbool2_t*)(in + i);
+      *(vbool2_t*)(out + i) = v;
+    }
+}
+
+void f7 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool1_t v = *(vbool1_t*)(in + 100);
+      *(vbool1_t*)(out + 100) = v;
+    }
+  else
+    {
+      vbool1_t v = *(vbool1_t*)(in + 200);
+      *(vbool1_t*)(out + 200) = v;
+      if (cond == 2)
+        {
+          out[1000] = 8000;
+        }
+      else
+        {
+          out[2000] = 9000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool1_t v = *(vbool1_t*)(in + i);
+      *(vbool1_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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 {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 6 { 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_bb_prop-21.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-21.c
new file mode 100644
index 00000000000..25ae317364b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-21.c
@@ -0,0 +1,155 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint8mf8_t v = *(vint8mf8_t*)(in + 100);
+      *(vint8mf8_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vint8mf8_t v = *(vint8mf8_t*)(in + 200);
+          *(vint8mf8_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint8mf8_t v = *(vint8mf8_t*)(in + i);
+      *(vint8mf8_t*)(out + i) = v;
+    }
+}
+
+void f2 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint8mf4_t v = *(vint8mf4_t*)(in + 100);
+      *(vint8mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vint8mf4_t v = *(vint8mf4_t*)(in + 200);
+          *(vint8mf4_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint8mf4_t v = *(vint8mf4_t*)(in + i);
+      *(vint8mf4_t*)(out + i) = v;
+    }
+}
+
+void f3 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint8mf2_t v = *(vint8mf2_t*)(in + 100);
+      *(vint8mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vint8mf2_t v = *(vint8mf2_t*)(in + 200);
+          *(vint8mf2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint8mf2_t v = *(vint8mf2_t*)(in + i);
+      *(vint8mf2_t*)(out + i) = v;
+    }
+}
+
+void f4 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint16mf4_t v = *(vint16mf4_t*)(in + 100);
+      *(vint16mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vint16mf4_t v = *(vint16mf4_t*)(in + 200);
+          *(vint16mf4_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint16mf4_t v = *(vint16mf4_t*)(in + i);
+      *(vint16mf4_t*)(out + i) = v;
+    }
+}
+
+void f5 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint16mf2_t v = *(vint16mf2_t*)(in + 100);
+      *(vint16mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vint16mf2_t v = *(vint16mf2_t*)(in + 200);
+          *(vint16mf2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint16mf2_t v = *(vint16mf2_t*)(in + i);
+      *(vint16mf2_t*)(out + i) = v;
+    }
+}
+
+void f6 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vint32mf2_t v = *(vint32mf2_t*)(in + 100);
+      *(vint32mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vint32mf2_t v = *(vint32mf2_t*)(in + 200);
+          *(vint32mf2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vint32mf2_t v = *(vint32mf2_t*)(in + i);
+      *(vint32mf2_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-22.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-22.c
new file mode 100644
index 00000000000..ecf68f24b4d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-22.c
@@ -0,0 +1,155 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint8mf8_t v = *(vuint8mf8_t*)(in + 100);
+      *(vuint8mf8_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vuint8mf8_t v = *(vuint8mf8_t*)(in + 200);
+          *(vuint8mf8_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint8mf8_t v = *(vuint8mf8_t*)(in + i);
+      *(vuint8mf8_t*)(out + i) = v;
+    }
+}
+
+void f2 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint8mf4_t v = *(vuint8mf4_t*)(in + 100);
+      *(vuint8mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vuint8mf4_t v = *(vuint8mf4_t*)(in + 200);
+          *(vuint8mf4_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint8mf4_t v = *(vuint8mf4_t*)(in + i);
+      *(vuint8mf4_t*)(out + i) = v;
+    }
+}
+
+void f3 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint8mf2_t v = *(vuint8mf2_t*)(in + 100);
+      *(vuint8mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vuint8mf2_t v = *(vuint8mf2_t*)(in + 200);
+          *(vuint8mf2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint8mf2_t v = *(vuint8mf2_t*)(in + i);
+      *(vuint8mf2_t*)(out + i) = v;
+    }
+}
+
+void f4 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint16mf4_t v = *(vuint16mf4_t*)(in + 100);
+      *(vuint16mf4_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vuint16mf4_t v = *(vuint16mf4_t*)(in + 200);
+          *(vuint16mf4_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint16mf4_t v = *(vuint16mf4_t*)(in + i);
+      *(vuint16mf4_t*)(out + i) = v;
+    }
+}
+
+void f5 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint16mf2_t v = *(vuint16mf2_t*)(in + 100);
+      *(vuint16mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vuint16mf2_t v = *(vuint16mf2_t*)(in + 200);
+          *(vuint16mf2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint16mf2_t v = *(vuint16mf2_t*)(in + i);
+      *(vuint16mf2_t*)(out + i) = v;
+    }
+}
+
+void f6 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint32mf2_t v = *(vuint32mf2_t*)(in + 100);
+      *(vuint32mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vuint32mf2_t v = *(vuint32mf2_t*)(in + 200);
+          *(vuint32mf2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint32mf2_t v = *(vuint32mf2_t*)(in + i);
+      *(vuint32mf2_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-23.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-23.c
new file mode 100644
index 00000000000..87ae0f59684
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-23.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vuint32mf2_t v = *(vuint32mf2_t*)(in + 100);
+      *(vuint32mf2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vuint32mf2_t v = *(vuint32mf2_t*)(in + 200);
+          *(vuint32mf2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vuint32mf2_t v = *(vuint32mf2_t*)(in + i);
+      *(vuint32mf2_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-24.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-24.c
new file mode 100644
index 00000000000..b87c64bcef1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-24.c
@@ -0,0 +1,180 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool64_t v = *(vbool64_t*)(in + 100);
+      *(vbool64_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vbool64_t v = *(vbool64_t*)(in + 200);
+          *(vbool64_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool64_t v = *(vbool64_t*)(in + i);
+      *(vbool64_t*)(out + i) = v;
+    }
+}
+
+void f2 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool32_t v = *(vbool32_t*)(in + 100);
+      *(vbool32_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vbool32_t v = *(vbool32_t*)(in + 200);
+          *(vbool32_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool32_t v = *(vbool32_t*)(in + i);
+      *(vbool32_t*)(out + i) = v;
+    }
+}
+
+void f3 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool16_t v = *(vbool16_t*)(in + 100);
+      *(vbool16_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vbool16_t v = *(vbool16_t*)(in + 200);
+          *(vbool16_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool16_t v = *(vbool16_t*)(in + i);
+      *(vbool16_t*)(out + i) = v;
+    }
+}
+
+void f4 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool8_t v = *(vbool8_t*)(in + 100);
+      *(vbool8_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vbool8_t v = *(vbool8_t*)(in + 200);
+          *(vbool8_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool8_t v = *(vbool8_t*)(in + i);
+      *(vbool8_t*)(out + i) = v;
+    }
+}
+
+void f5 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool4_t v = *(vbool4_t*)(in + 100);
+      *(vbool4_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vbool4_t v = *(vbool4_t*)(in + 200);
+          *(vbool4_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool4_t v = *(vbool4_t*)(in + i);
+      *(vbool4_t*)(out + i) = v;
+    }
+}
+
+void f6 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool2_t v = *(vbool2_t*)(in + 100);
+      *(vbool2_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vbool2_t v = *(vbool2_t*)(in + 200);
+          *(vbool2_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool2_t v = *(vbool2_t*)(in + i);
+      *(vbool2_t*)(out + i) = v;
+    }
+}
+
+void f7 (int * restrict in, int * restrict out, int n, int cond)
+{
+  if (cond == 1)
+    {
+      vbool1_t v = *(vbool1_t*)(in + 100);
+      *(vbool1_t*)(out + 100) = v;
+    }
+  else
+    {
+      if (cond == 2)
+        {
+          vbool1_t v = *(vbool1_t*)(in + 200);
+          *(vbool1_t*)(out + 200) = v;
+          out[1000] = 8000;
+        }
+    }
+  for (int i = 0; i < n; i++)
+    {
+      vbool1_t v = *(vbool1_t*)(in + i);
+      *(vbool1_t*)(out + i) = v;
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-25.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c
new file mode 100644
index 00000000000..a3ed7d82a19
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c
@@ -0,0 +1,572 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool64_t v = *(vbool64_t*)(in + 600);
+    *(vbool64_t*)(out + 600) = v;
+  } else {
+    vbool64_t v = *(vbool64_t*)(in + 700);
+    *(vbool64_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool64_t v = *(vbool64_t*)(in + 600);
+    *(vbool64_t*)(out + 600) = v;
+  } else {
+    vbool64_t v = *(vbool64_t*)(in + 700);
+    *(vbool64_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool32_t v = *(vbool32_t*)(in + 600);
+    *(vbool32_t*)(out + 600) = v;
+  } else {
+    vbool32_t v = *(vbool32_t*)(in + 700);
+    *(vbool32_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool32_t v = *(vbool32_t*)(in + 600);
+    *(vbool32_t*)(out + 600) = v;
+  } else {
+    vbool32_t v = *(vbool32_t*)(in + 700);
+    *(vbool32_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool16_t v = *(vbool16_t*)(in + 600);
+    *(vbool16_t*)(out + 600) = v;
+  } else {
+    vbool16_t v = *(vbool16_t*)(in + 700);
+    *(vbool16_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool16_t v = *(vbool16_t*)(in + 600);
+    *(vbool16_t*)(out + 600) = v;
+  } else {
+    vbool16_t v = *(vbool16_t*)(in + 700);
+    *(vbool16_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool8_t v = *(vbool8_t*)(in + 600);
+    *(vbool8_t*)(out + 600) = v;
+  } else {
+    vbool8_t v = *(vbool8_t*)(in + 700);
+    *(vbool8_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool8_t v = *(vbool8_t*)(in + 600);
+    *(vbool8_t*)(out + 600) = v;
+  } else {
+    vbool8_t v = *(vbool8_t*)(in + 700);
+    *(vbool8_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool4_t v = *(vbool4_t*)(in + 600);
+    *(vbool4_t*)(out + 600) = v;
+  } else {
+    vbool4_t v = *(vbool4_t*)(in + 700);
+    *(vbool4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool4_t v = *(vbool4_t*)(in + 600);
+    *(vbool4_t*)(out + 600) = v;
+  } else {
+    vbool4_t v = *(vbool4_t*)(in + 700);
+    *(vbool4_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool2_t v = *(vbool2_t*)(in + 600);
+    *(vbool2_t*)(out + 600) = v;
+  } else {
+    vbool2_t v = *(vbool2_t*)(in + 700);
+    *(vbool2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool2_t v = *(vbool2_t*)(in + 600);
+    *(vbool2_t*)(out + 600) = v;
+  } else {
+    vbool2_t v = *(vbool2_t*)(in + 700);
+    *(vbool2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f7 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool1_t v = *(vbool1_t*)(in + 600);
+    *(vbool1_t*)(out + 600) = v;
+  } else {
+    vbool1_t v = *(vbool1_t*)(in + 700);
+    *(vbool1_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool1_t v = *(vbool1_t*)(in + 600);
+    *(vbool1_t*)(out + 600) = v;
+  } else {
+    vbool1_t v = *(vbool1_t*)(in + 700);
+    *(vbool1_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 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_bb_prop-26.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c
new file mode 100644
index 00000000000..ae6fa93bdfb
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c
@@ -0,0 +1,492 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 600);
+    *(vint8mf8_t*)(out + 600) = v;
+  } else {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 700);
+    *(vint8mf8_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 600);
+    *(vint8mf8_t*)(out + 600) = v;
+  } else {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 700);
+    *(vint8mf8_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 600);
+    *(vint8mf4_t*)(out + 600) = v;
+  } else {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 700);
+    *(vint8mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 600);
+    *(vint8mf4_t*)(out + 600) = v;
+  } else {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 700);
+    *(vint8mf4_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 600);
+    *(vint8mf2_t*)(out + 600) = v;
+  } else {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 700);
+    *(vint8mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 600);
+    *(vint8mf2_t*)(out + 600) = v;
+  } else {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 700);
+    *(vint8mf2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 600);
+    *(vint16mf4_t*)(out + 600) = v;
+  } else {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 700);
+    *(vint16mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 600);
+    *(vint16mf4_t*)(out + 600) = v;
+  } else {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 700);
+    *(vint16mf4_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 600);
+    *(vint16mf2_t*)(out + 600) = v;
+  } else {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 700);
+    *(vint16mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 600);
+    *(vint16mf2_t*)(out + 600) = v;
+  } else {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 700);
+    *(vint16mf2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 600);
+    *(vint32mf2_t*)(out + 600) = v;
+  } else {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 700);
+    *(vint32mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 600);
+    *(vint32mf2_t*)(out + 600) = v;
+  } else {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 700);
+    *(vint32mf2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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" } } } } */
+
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c
new file mode 100644
index 00000000000..e0495653047
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c
@@ -0,0 +1,491 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
+    *(vuint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 600);
+    *(vuint8mf8_t*)(out + 600) = v;
+  } else {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 700);
+    *(vuint8mf8_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
+    *(vuint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 600);
+    *(vuint8mf8_t*)(out + 600) = v;
+  } else {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 700);
+    *(vuint8mf8_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
+    *(vuint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 600);
+    *(vuint8mf4_t*)(out + 600) = v;
+  } else {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 700);
+    *(vuint8mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
+    *(vuint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 600);
+    *(vuint8mf4_t*)(out + 600) = v;
+  } else {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 700);
+    *(vuint8mf4_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
+    *(vuint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 600);
+    *(vuint8mf2_t*)(out + 600) = v;
+  } else {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 700);
+    *(vuint8mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
+    *(vuint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 600);
+    *(vuint8mf2_t*)(out + 600) = v;
+  } else {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 700);
+    *(vuint8mf2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
+    *(vuint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 600);
+    *(vuint16mf4_t*)(out + 600) = v;
+  } else {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 700);
+    *(vuint16mf4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
+    *(vuint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 600);
+    *(vuint16mf4_t*)(out + 600) = v;
+  } else {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 700);
+    *(vuint16mf4_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
+    *(vuint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 600);
+    *(vuint16mf2_t*)(out + 600) = v;
+  } else {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 700);
+    *(vuint16mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
+    *(vuint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 600);
+    *(vuint16mf2_t*)(out + 600) = v;
+  } else {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 700);
+    *(vuint16mf2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 600);
+    *(vuint32mf2_t*)(out + 600) = v;
+  } else {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 700);
+    *(vuint32mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 600);
+    *(vuint32mf2_t*)(out + 600) = v;
+  } else {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 700);
+    *(vuint32mf2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c
new file mode 100644
index 00000000000..c64572ec911
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c
@@ -0,0 +1,86 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 600);
+    *(vfloat32mf2_t*)(out + 600) = v;
+  } else {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 700);
+    *(vfloat32mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  if (n == 0) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 600);
+    *(vfloat32mf2_t*)(out + 600) = v;
+  } else {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 700);
+    *(vfloat32mf2_t*)(out + 700) = v;
+  }
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c
new file mode 100644
index 00000000000..b52cae3bb51
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 600);
+    *(vfloat32mf2_t*)(out + 600) = v;
+  } else {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 700);
+    *(vfloat32mf2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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 {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { 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_bb_prop-4.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-4.c
new file mode 100644
index 00000000000..c61d38e1476
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-4.c
@@ -0,0 +1,210 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool64_t v = *(vbool64_t*)(in + 600);
+    *(vbool64_t*)(out + 600) = v;
+  } else {
+    vbool64_t v = *(vbool64_t*)(in + 700);
+    *(vbool64_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool32_t v = *(vbool32_t*)(in + 600);
+    *(vbool32_t*)(out + 600) = v;
+  } else {
+    vbool32_t v = *(vbool32_t*)(in + 700);
+    *(vbool32_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool16_t v = *(vbool16_t*)(in + 600);
+    *(vbool16_t*)(out + 600) = v;
+  } else {
+    vbool16_t v = *(vbool16_t*)(in + 700);
+    *(vbool16_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool8_t v = *(vbool8_t*)(in + 600);
+    *(vbool8_t*)(out + 600) = v;
+  } else {
+    vbool8_t v = *(vbool8_t*)(in + 700);
+    *(vbool8_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool4_t v = *(vbool4_t*)(in + 600);
+    *(vbool4_t*)(out + 600) = v;
+  } else {
+    vbool4_t v = *(vbool4_t*)(in + 700);
+    *(vbool4_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool2_t v = *(vbool2_t*)(in + 600);
+    *(vbool2_t*)(out + 600) = v;
+  } else {
+    vbool2_t v = *(vbool2_t*)(in + 700);
+    *(vbool2_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f7 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool1_t v = *(vbool1_t*)(in + 600);
+    *(vbool1_t*)(out + 600) = v;
+  } else {
+    vbool1_t v = *(vbool1_t*)(in + 700);
+    *(vbool1_t*)(out + 700) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 6 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O2" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-5.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-5.c
new file mode 100644
index 00000000000..f59b4eeacb1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-5.c
@@ -0,0 +1,167 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 600);
+    *(vint8mf8_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 600);
+    *(vint8mf4_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 600);
+    *(vint8mf2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 600);
+    *(vint16mf4_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 600);
+    *(vint16mf2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 600);
+    *(vint32mf2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-6.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-6.c
new file mode 100644
index 00000000000..ac9ae26184a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-6.c
@@ -0,0 +1,167 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 600);
+    *(vint8mf8_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 600);
+    *(vint8mf4_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 600);
+    *(vint8mf2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 600);
+    *(vint16mf4_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 600);
+    *(vint16mf2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
+    *(vuint32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 600);
+    *(vuint32mf2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-7.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-7.c
new file mode 100644
index 00000000000..832404d49cd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-7.c
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
+    *(vfloat32mf2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 600);
+    *(vfloat32mf2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-8.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-8.c
new file mode 100644
index 00000000000..6f29253b3b7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-8.c
@@ -0,0 +1,194 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool64_t v = *(vbool64_t*)(in + 500);
+    *(vbool64_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool64_t v = *(vbool64_t*)(in + 600);
+    *(vbool64_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool32_t v = *(vbool32_t*)(in + 500);
+    *(vbool32_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool32_t v = *(vbool32_t*)(in + 600);
+    *(vbool32_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool16_t v = *(vbool16_t*)(in + 500);
+    *(vbool16_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool16_t v = *(vbool16_t*)(in + 600);
+    *(vbool16_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool8_t v = *(vbool8_t*)(in + 500);
+    *(vbool8_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool8_t v = *(vbool8_t*)(in + 600);
+    *(vbool8_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool4_t v = *(vbool4_t*)(in + 500);
+    *(vbool4_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool4_t v = *(vbool4_t*)(in + 600);
+    *(vbool4_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool2_t v = *(vbool2_t*)(in + 500);
+    *(vbool2_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool2_t v = *(vbool2_t*)(in + 600);
+    *(vbool2_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f7 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  if (n == 0) {
+    vbool1_t v = *(vbool1_t*)(in + 500);
+    *(vbool1_t*)(out + 500) = v;
+  } else if (n == 1) {
+    vbool1_t v = *(vbool1_t*)(in + 600);
+    *(vbool1_t*)(out + 600) = v;
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-9.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-9.c
new file mode 100644
index 00000000000..7b0924de69e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-9.c
@@ -0,0 +1,230 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
+    *(vint8mf8_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint8mf8_t v = *(vint8mf8_t*)(in + 700);
+    *(vint8mf8_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
+    *(vint8mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint8mf4_t v = *(vint8mf4_t*)(in + 700);
+    *(vint8mf4_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
+    *(vint8mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint8mf2_t v = *(vint8mf2_t*)(in + 700);
+    *(vint8mf2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
+    *(vint16mf4_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint16mf4_t v = *(vint16mf4_t*)(in + 700);
+    *(vint16mf4_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
+    *(vint16mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint16mf2_t v = *(vint16mf2_t*)(in + 700);
+    *(vint16mf2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  switch (n)
+  {
+  case 0:{
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  case 1:{
+    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
+    *(vint32mf2_t*)(out + 500) = v;
+    break;
+  }
+  default:{
+    vint32mf2_t v = *(vint32mf2_t*)(in + 700);
+    *(vint32mf2_t*)(out + 700) = v;
+    break;
+  }
+  }
+
+  for (int i = 0 ; i < n * n; i++)
+    out[i] = out[i] + out[i];
+  
+  for (int i = 0 ; i < n * n * n; i++)
+    out[i] = out[i] * out[i];
+
+  for (int i = 0 ; i < n * n * n * n; i++)
+    out[i] = out[i] * out[i];
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
+/* { dg-final { scan-assembler-times {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" no-opts "-O1" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-1.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-1.c
new file mode 100644
index 00000000000..ca501e0e1a1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-1.c
@@ -0,0 +1,239 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -O3 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void fn3 (void);
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool64_t v = *(vbool64_t*)(in + 900 + i);
+    *(vbool64_t*)(out + 900 + i) = v;
+  }
+
+}
+
+int f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool32_t v = *(vbool32_t*)(in + 900 + i);
+    *(vbool32_t*)(out + 900 + i) = v;
+  }
+
+}
+
+int f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool16_t v = *(vbool16_t*)(in + 900 + i);
+    *(vbool16_t*)(out + 900 + i) = v;
+  }
+
+}
+
+int f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool8_t v = *(vbool8_t*)(in + 900 + i);
+    *(vbool8_t*)(out + 900 + i) = v;
+  }
+
+}
+
+int f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool4_t v = *(vbool4_t*)(in + 900 + i);
+    *(vbool4_t*)(out + 900 + i) = v;
+  }
+
+}
+
+int f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool2_t v = *(vbool2_t*)(in + 900 + i);
+    *(vbool2_t*)(out + 900 + i) = v;
+  }
+
+}
+
+int f7 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vbool1_t v = *(vbool1_t*)(in + 900 + i);
+    *(vbool1_t*)(out + 900 + i) = v;
+  }
+
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 4 { 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_call-2.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-2.c
new file mode 100644
index 00000000000..69cc50f0219
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-2.c
@@ -0,0 +1,207 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -O3 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void fn3 (void);
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
+    *(vint8mf8_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
+    *(vint8mf4_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
+    *(vint8mf2_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
+    *(vint16mf4_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
+    *(vint16mf2_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
+    *(vint32mf2_t*)(out + 900 + i) = v;
+  }
+
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { 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_call-3.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-3.c
new file mode 100644
index 00000000000..3a350486cee
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-3.c
@@ -0,0 +1,207 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -O3 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void fn3 (void);
+
+void f (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
+    *(vuint8mf8_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f2 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
+    *(vuint8mf4_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f3 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
+    *(vuint8mf2_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f4 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
+    *(vuint16mf4_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f5 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
+    *(vuint16mf2_t*)(out + 900 + i) = v;
+  }
+
+}
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
+    *(vuint32mf2_t*)(out + 900 + i) = v;
+  }
+
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { 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_call-4.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-4.c
new file mode 100644
index 00000000000..178036f780b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-4.c
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -O3 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void fn3 (void);
+
+void f6 (int8_t * restrict in, int8_t * restrict out, int n)
+{
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+  fn3 ();
+  for (int i = 0 ; i < n * n * n * n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
+    *(vfloat32mf2_t*)(out + 900 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)} 5 { 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_complex_loop-1.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-1.c
new file mode 100644
index 00000000000..c5962e5a385
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-1.c
@@ -0,0 +1,52 @@
+/* { 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, size_t n, size_t m, int cond)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i % 2) {
+        
+        if (cond) {
+          vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 2000);
+          *(vfloat32mf2_t*)out = v;
+        } else {
+          vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 3000);
+          *(vfloat32mf2_t*)out = v;
+        }
+        
+        for (size_t j = 0; j < m; j += 1) {
+          if (j % 2 == 0) {
+            vint8mf8_t v = *(vint8mf8_t*)(in + i + j + 100);
+            *(vint8mf8_t*)out = v;
+          } else {
+            vint8mf8_t v = *(vint8mf8_t*)(in + i + j + 200);
+            *(vint8mf8_t*)out = v;
+          }
+        }
+        
+        if (cond) {
+          vuint16mf4_t v = *(vuint16mf4_t*)(in + i + 7000);
+          *(vuint16mf4_t*)out = v;
+        } else {
+          vuint16mf4_t v = *(vuint16mf4_t*)(in + i + 8000);
+          *(vuint16mf4_t*)out = v;
+        }
+      } else {
+        if (cond) {
+          vint8mf8_t v = *(vint8mf8_t*)(in + i + 4000);
+          *(vint8mf8_t*)out = v;
+        } else {
+          vint8mf8_t v = *(vint8mf8_t*)(in + i + 5000);
+          *(vint8mf8_t*)out = v;
+        }
+        
+        vbool64_t v = *(vbool64_t*)(in + i + 300);
+        *(vbool64_t*)out = 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_complex_loop-2.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-2.c
new file mode 100644
index 00000000000..9ec4879dade
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-2.c
@@ -0,0 +1,56 @@
+/* { 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, size_t n, size_t m, int cond)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i % 2) {
+        
+        if (cond) {
+          vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 2000);
+          *(vfloat32mf2_t*)(out + i + 2000) = v;
+        } else {
+          vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 3000);
+          *(vfloat32mf2_t*)(out + i + 3000) = v;
+        }
+        
+        for (size_t j = 0; j < m; j += 1) {
+          if (j % 2 == 0) {
+            vint8mf8_t v = *(vint8mf8_t*)(in + i + j + 100);
+            *(vint8mf8_t*)(out + i + j + 100) = v;
+          } else {
+            vint8mf8_t v = *(vint8mf8_t*)(in + i + j + 200);
+            *(vint8mf8_t*)(out + i + j + 200) = v;
+          }
+        }
+        
+        if (cond) {
+          vuint16mf4_t v = *(vuint16mf4_t*)(in + i + 7000);
+          *(vuint16mf4_t*)(out + i + 7000) = v;
+        } else {
+          vuint16mf4_t v = *(vuint16mf4_t*)(in + i + 8000);
+          *(vuint16mf4_t*)(out + i + 8000) = v;
+        }
+      } else {
+        if (cond) {
+          vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 4000);
+          *(vuint16mf2_t*)(out + i + 4000) = v;
+        } else {
+          vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 5000);
+          *(vuint16mf2_t*)(out + i + 5000) = v;
+        }
+        
+        vbool1_t v = *(vbool1_t*)(in + i + 300);
+        *(vbool1_t*)(out + i + 300) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 5 { target { no-opts "-O0"  no-opts "-O1"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-not {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]} { target { no-opts "-O0" no-opts "-O1"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]} { target { no-opts "-O0" no-opts "-O1"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]} { target { no-opts "-O0" no-opts "-O1"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]} { 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_conflict-1.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-1.c
new file mode 100644
index 00000000000..dff5437da72
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-1.c
@@ -0,0 +1,23 @@
+/* { 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, size_t n, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i != cond) {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      } else {
+        vbool1_t v = *(vbool1_t*)(in + i + 400);
+        *(vbool1_t*)(out + i + 400) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {\.L[0-9]+:\s+vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-10.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-10.c
new file mode 100644
index 00000000000..697b093f69f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-10.c
@@ -0,0 +1,27 @@
+/* { 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, size_t n, size_t m, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i != cond) {
+        vbool16_t v = *(vbool16_t*)(in + i + 400);
+        *(vbool16_t*)(out + i + 400) = v;
+        for (int j = 0; j < m; j++) {
+          vuint8mf2_t v = *(vuint8mf2_t*)(in + i + 100 + j);
+          *(vuint8mf2_t*)(out + i + 100 + j) = v;
+        }
+      } else if (i == cond2) {
+        vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 200);
+        *(vuint16mf2_t*)(out + i + 200) = v;
+      } else {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 5 { 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_conflict-11.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-11.c
new file mode 100644
index 00000000000..6ad2dc3f237
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-11.c
@@ -0,0 +1,24 @@
+/* { 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, size_t n, size_t m, size_t cond, size_t cond2)
+{
+  for (int i = 0; i < n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*) (in + i + 1);
+    *(vint8mf8_t*) (out + i + 1) = v;
+  }
+  for (int i = 0; i < n; i++) {
+    vfloat32mf2_t v = *(vfloat32mf2_t*) (in + i + 2);
+    *(vfloat32mf2_t*) (out + i + 2) = v;
+  }
+  for (int i = 0; i < n; i++) {
+    vfloat32mf2_t v;
+    *(vfloat32mf2_t*) (out + i + 3) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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*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_conflict-12.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-12.c
new file mode 100644
index 00000000000..c01f4b4acae
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-12.c
@@ -0,0 +1,39 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f2 (int32_t * restrict in, int32_t * restrict in2, int32_t * restrict out, int32_t * restrict out2, size_t n, size_t m, size_t cond, size_t cond2)
+{
+  for (int i = 0; i < n; i++){
+    out2[i] = in2[i] + out[i];
+  }
+  for (int i = 0; i < n; i++){
+    out[i] = in[i] & out2[i];
+  }
+  for (int i = 0; i < n; i++){
+    out2[i] = out[i] * out2[i];
+  }
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i > cond) {
+        if (cond2) {
+          for (int j = 0; j < m; j++) {
+            vint8mf8_t v2 = *(vint8mf8_t*)(in2 + i + 100 + j);
+            *(vint8mf8_t*)(out2 + i + 100 + j) = v2;
+          }
+        } else {
+          for (int j = 0; j < m; j++) {
+            vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in2 + i + 300 + j);
+            *(vfloat32mf2_t*)(out2 + i + 100 + j) = v3;
+          }
+        }
+      } else {
+        vbool64_t v = *(vbool64_t*)(in + i + 400);
+        *(vbool64_t*)(out + i + 400) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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_conflict-2.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-2.c
new file mode 100644
index 00000000000..d14f9ba34a1
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-2.c
@@ -0,0 +1,23 @@
+/* { 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, size_t n, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i == cond) {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      } else {
+        vbool1_t v = *(vbool1_t*)(in + i + 400);
+        *(vbool1_t*)(out + i + 400) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 3 { target { no-opts "-O0" no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c
new file mode 100644
index 00000000000..1ba0234788a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f2 (int32_t * restrict in, int32_t * restrict in2, int32_t * restrict out, int32_t * restrict out2, size_t n, size_t m, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i > cond) {
+        if (cond2) {
+          for (int j = 0; j < m; j++) {
+            vint8mf8_t v2 = *(vint8mf8_t*)(in2 + i + 100 + j);
+            *(vint8mf8_t*)(out2 + i + 100 + j) = v2;
+          }
+        } else {
+          for (int j = 0; j < m; j++) {
+            vfloat32mf2_t v3 = *(vfloat32mf2_t*)(in2 + i + 300 + j);
+            *(vfloat32mf2_t*)(out2 + i + 100 + j) = v3;
+          }
+        }
+      } else {
+        vbool64_t v = *(vbool64_t*)(in + i + 400);
+        *(vbool64_t*)(out + i + 400) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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_conflict-4.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-4.c
new file mode 100644
index 00000000000..c86af9d3907
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-4.c
@@ -0,0 +1,29 @@
+/* { 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, size_t n, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i == cond) {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      } else if (i == cond2) {
+        vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 200);
+        *(vfloat32mf2_t*)(out + i + 200) = v;
+      } else {
+        vbool1_t v = *(vbool1_t*)(in + i + 400);
+        *(vbool1_t*)(out + i + 400) = v;
+      }
+    }
+}
+
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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} 5 { 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_conflict-5.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-5.c
new file mode 100644
index 00000000000..34c40d46466
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-5.c
@@ -0,0 +1,32 @@
+/* { 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, size_t n, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i == cond) {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      } else if (i == cond2) {
+        vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 200);
+        *(vfloat32mf2_t*)(out + i + 200) = v;
+      } else if (i == (cond2 - 1)) {
+        vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 300);
+        *(vuint16mf2_t*)(out + i + 300) = v;
+      } else {
+        vbool1_t v = *(vbool1_t*)(in + i + 400);
+        *(vbool1_t*)(out + i + 400) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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} 7 { 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_conflict-6.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-6.c
new file mode 100644
index 00000000000..a009aadeecd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-6.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
+
+#include "riscv_vector.h"
+
+void f (int32_t * in, int32_t * out, int n, int cond)
+{
+  if (cond) {
+    vint32mf2_t v = *(vint32mf2_t*) (in + 100);
+    *(vint32mf2_t*) (out + 100) = v;
+  } else {
+    vint16mf2_t v = *(vint16mf2_t*) (in + 200);
+    *(vint16mf2_t*) (out + 200) = v;
+  }
+  
+  for (int i = 0; i < n; i++) {
+    vint8mf8_t v = *(vint8mf8_t*) (in + 300 + i);
+    *(vint8mf8_t*) (out + 300 + i) = v;
+  }
+}
+
+/* { dg-final { scan-assembler-times {\.L[0-9]+:\s+vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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 {\.L[0-9]+:\s+vle8\.v} 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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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_conflict-7.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c
new file mode 100644
index 00000000000..12ec25d5264
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c
@@ -0,0 +1,26 @@
+/* { 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, size_t n, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i != cond) {
+        vbool1_t v = *(vbool1_t*)(in + i + 400);
+        *(vbool1_t*)(out + i + 400) = v;
+      } else if (i == cond2) {
+        vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i + 200);
+        *(vfloat32mf2_t*)(out + i + 200) = v;
+      } else {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 4 { target { no-opts "-O0"  no-opts "-O1"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {j\s+\.L[0-9]+\s+\.L[0-9]+:\s+vlm\.v} 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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-8.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-8.c
new file mode 100644
index 00000000000..a7c9829c646
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-8.c
@@ -0,0 +1,27 @@
+/* { 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, size_t n, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i != cond) {
+        vbool1_t v = *(vbool1_t*)(in + i + 400);
+        *(vbool1_t*)(out + i + 400) = v;
+      } else if (i == cond2) {
+        vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 200);
+        *(vuint16mf2_t*)(out + i + 200) = v;
+      } else {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 5 { target { no-opts "-O0"  no-opts "-O1"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
+/* { dg-final { scan-assembler-times {j\s+\.L[0-9]+\s+\.L[0-9]+:\s+vlm\.v} 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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\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" } } } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-9.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-9.c
new file mode 100644
index 00000000000..bd6d552b22e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-9.c
@@ -0,0 +1,27 @@
+/* { 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, size_t n, size_t m, size_t cond, size_t cond2)
+{
+  for (size_t i = 0; i < n; i++)
+    {
+      if (i != cond) {
+        vbool1_t v = *(vbool1_t*)(in + i + 400);
+        *(vbool1_t*)(out + i + 400) = v;
+        for (int j = 0; j < m; j++) {
+          vint32mf2_t v = *(vint32mf2_t*)(in + i + 100 + j);
+          *(vint32mf2_t*)(out + i + 100 + j) = v;
+        }
+      } else if (i == cond2) {
+        vuint16mf2_t v = *(vuint16mf2_t*)(in + i + 200);
+        *(vuint16mf2_t*)(out + i + 200) = v;
+      } else {
+        vint8mf8_t v = *(vint8mf8_t*)(in + i + 100);
+        *(vint8mf8_t*)(out + i + 100) = v;
+      }
+    }
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 7 { target { no-opts "-O0"  no-opts "-O1"  no-opts "-Os" no-opts "-funroll-loops" no-opts "-g" } } } } */
-- 
2.36.3


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

* Re: [PATCH] RISC-V: Add testcases for VSETVL PASS 4
  2022-12-14  8:19 [PATCH] RISC-V: Add testcases for VSETVL PASS 4 juzhe.zhong
@ 2022-12-19 15:09 ` Kito Cheng
  0 siblings, 0 replies; 2+ messages in thread
From: Kito Cheng @ 2022-12-19 15:09 UTC (permalink / raw)
  To: 钟居哲; +Cc: GCC Patches, Palmer Dabbelt

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

Commited to trunk

<juzhe.zhong@rivai.ai> 於 2022年12月14日 週三 16:20 寫道:

> From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-21.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-22.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-23.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-24.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-4.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-5.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-6.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-7.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-8.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-9.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_call-1.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_call-2.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_call-3.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_call-4.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-1.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-2.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-1.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-10.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-11.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-12.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-2.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-4.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-5.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-6.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-8.c: New test.
>         * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-9.c: New test.
>
> ---
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-1.c        | 182 ++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-10.c       | 230 +++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-11.c       |  43 ++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-12.c       | 266 ++++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-13.c       | 221 +++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-14.c       | 221 +++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-15.c       |  41 ++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-16.c       | 257 ++++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-17.c       | 177 ++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-18.c       | 177 ++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-19.c       |  34 ++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-2.c        | 182 ++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-20.c       | 203 +++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-21.c       | 155 +++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-22.c       | 155 +++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-23.c       |  30 +
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-24.c       | 180 ++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-25.c       | 572 ++++++++++++++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-26.c       | 492 +++++++++++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-27.c       | 491 +++++++++++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-28.c       |  86 +++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-3.c        |  35 ++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-4.c        | 210 +++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-5.c        | 167 +++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-6.c        | 167 +++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-7.c        |  32 +
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-8.c        | 194 ++++++
>  .../riscv/rvv/vsetvl/vlmax_bb_prop-9.c        | 230 +++++++
>  .../riscv/rvv/vsetvl/vlmax_call-1.c           | 239 ++++++++
>  .../riscv/rvv/vsetvl/vlmax_call-2.c           | 207 +++++++
>  .../riscv/rvv/vsetvl/vlmax_call-3.c           | 207 +++++++
>  .../riscv/rvv/vsetvl/vlmax_call-4.c           |  39 ++
>  .../riscv/rvv/vsetvl/vlmax_complex_loop-1.c   |  52 ++
>  .../riscv/rvv/vsetvl/vlmax_complex_loop-2.c   |  56 ++
>  .../riscv/rvv/vsetvl/vlmax_conflict-1.c       |  23 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-10.c      |  27 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-11.c      |  24 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-12.c      |  39 ++
>  .../riscv/rvv/vsetvl/vlmax_conflict-2.c       |  23 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-3.c       |  30 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-4.c       |  29 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-5.c       |  32 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-6.c       |  26 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-7.c       |  26 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-8.c       |  27 +
>  .../riscv/rvv/vsetvl/vlmax_conflict-9.c       |  27 +
>  46 files changed, 6563 insertions(+)
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-21.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-22.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-23.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-24.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-25.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-26.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-27.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-28.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-3.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-4.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-5.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-6.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-7.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-8.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-9.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-1.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-2.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-3.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_call-4.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-1.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_complex_loop-2.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-1.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-10.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-11.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-12.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-2.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-4.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-5.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-6.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-7.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-8.c
>  create mode 100644
> gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_conflict-9.c
>
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c
> new file mode 100644
> index 00000000000..3e27a8abf10
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-1.c
> @@ -0,0 +1,182 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
> +    *(vint8mf8_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 600);
> +    *(vint8mf8_t*)(out + 600) = v;
> +  } else {
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 700);
> +    *(vint8mf8_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
> +    *(vint8mf8_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f2 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
> +    *(vint8mf4_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 600);
> +    *(vint8mf4_t*)(out + 600) = v;
> +  } else {
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 700);
> +    *(vint8mf4_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
> +    *(vint8mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f3 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
> +    *(vint8mf2_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 600);
> +    *(vint8mf2_t*)(out + 600) = v;
> +  } else {
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 700);
> +    *(vint8mf2_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
> +    *(vint8mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f4 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
> +    *(vint16mf4_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 600);
> +    *(vint16mf4_t*)(out + 600) = v;
> +  } else {
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 700);
> +    *(vint16mf4_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
> +    *(vint16mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f5 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
> +    *(vint16mf2_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 600);
> +    *(vint16mf2_t*)(out + 600) = v;
> +  } else {
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 700);
> +    *(vint16mf2_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
> +    *(vint16mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f6 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
> +    *(vint32mf2_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vint32mf2_t v = *(vint32mf2_t*)(in + 600);
> +    *(vint32mf2_t*)(out + 600) = v;
> +  } else {
> +    vint32mf2_t v = *(vint32mf2_t*)(in + 700);
> +    *(vint32mf2_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
> +    *(vint32mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" } } } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c
> new file mode 100644
> index 00000000000..51d3fcf7613
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-10.c
> @@ -0,0 +1,230 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
> +    *(vint8mf8_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
> +    *(vint8mf8_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 700);
> +    *(vint8mf8_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
> +    *(vint8mf8_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f2 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
> +    *(vint8mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
> +    *(vint8mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 700);
> +    *(vint8mf4_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
> +    *(vint8mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f3 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
> +    *(vint8mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
> +    *(vint8mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 700);
> +    *(vint8mf2_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
> +    *(vint8mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f4 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
> +    *(vint16mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
> +    *(vint16mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 700);
> +    *(vint16mf4_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
> +    *(vint16mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f5 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
> +    *(vint16mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
> +    *(vint16mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 700);
> +    *(vint16mf2_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
> +    *(vint16mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f6 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
> +    *(vuint32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
> +    *(vuint32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 700);
> +    *(vuint32mf2_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
> +    *(vuint32mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c
> new file mode 100644
> index 00000000000..3c2badd7793
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-11.c
> @@ -0,0 +1,43 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
> +    *(vfloat32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
> +    *(vfloat32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 700);
> +    *(vfloat32mf2_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
> +    *(vfloat32mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { 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_bb_prop-12.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c
> new file mode 100644
> index 00000000000..6ace4c4ef18
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-12.c
> @@ -0,0 +1,266 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool64_t v = *(vbool64_t*)(in + 500);
> +    *(vbool64_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool64_t v = *(vbool64_t*)(in + 500);
> +    *(vbool64_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vbool64_t v = *(vbool64_t*)(in + 700);
> +    *(vbool64_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool64_t v = *(vbool64_t*)(in + 900 + i);
> +    *(vbool64_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f2 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool32_t v = *(vbool32_t*)(in + 500);
> +    *(vbool32_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool32_t v = *(vbool32_t*)(in + 500);
> +    *(vbool32_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vbool32_t v = *(vbool32_t*)(in + 700);
> +    *(vbool32_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool32_t v = *(vbool32_t*)(in + 900 + i);
> +    *(vbool32_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f3 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool16_t v = *(vbool16_t*)(in + 500);
> +    *(vbool16_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool16_t v = *(vbool16_t*)(in + 500);
> +    *(vbool16_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vbool16_t v = *(vbool16_t*)(in + 700);
> +    *(vbool16_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool16_t v = *(vbool16_t*)(in + 900 + i);
> +    *(vbool16_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f4 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool8_t v = *(vbool8_t*)(in + 500);
> +    *(vbool8_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool8_t v = *(vbool8_t*)(in + 500);
> +    *(vbool8_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vbool8_t v = *(vbool8_t*)(in + 700);
> +    *(vbool8_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool8_t v = *(vbool8_t*)(in + 900 + i);
> +    *(vbool8_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f5 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool4_t v = *(vbool4_t*)(in + 500);
> +    *(vbool4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool4_t v = *(vbool4_t*)(in + 500);
> +    *(vbool4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vbool4_t v = *(vbool4_t*)(in + 700);
> +    *(vbool4_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool4_t v = *(vbool4_t*)(in + 900 + i);
> +    *(vbool4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f6 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool2_t v = *(vbool2_t*)(in + 500);
> +    *(vbool2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool2_t v = *(vbool2_t*)(in + 500);
> +    *(vbool2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vbool2_t v = *(vbool2_t*)(in + 700);
> +    *(vbool2_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool2_t v = *(vbool2_t*)(in + 900 + i);
> +    *(vbool2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f7 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool1_t v = *(vbool1_t*)(in + 500);
> +    *(vbool1_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool1_t v = *(vbool1_t*)(in + 500);
> +    *(vbool1_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    vbool1_t v = *(vbool1_t*)(in + 700);
> +    *(vbool1_t*)(out + 700) = v;
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool1_t v = *(vbool1_t*)(in + 900 + i);
> +    *(vbool1_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 5 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" no-opts "-O1" } } } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c
> new file mode 100644
> index 00000000000..8ce380bea07
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-13.c
> @@ -0,0 +1,221 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
> +    *(vint8mf8_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 500);
> +    *(vint8mf8_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf8_t v = *(vint8mf8_t*)(in + 900 + i);
> +    *(vint8mf8_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f2 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
> +    *(vint8mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 500);
> +    *(vint8mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf4_t v = *(vint8mf4_t*)(in + 900 + i);
> +    *(vint8mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f3 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
> +    *(vint8mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 500);
> +    *(vint8mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint8mf2_t v = *(vint8mf2_t*)(in + 900 + i);
> +    *(vint8mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f4 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
> +    *(vint16mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 500);
> +    *(vint16mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint16mf4_t v = *(vint16mf4_t*)(in + 900 + i);
> +    *(vint16mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f5 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
> +    *(vint16mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 500);
> +    *(vint16mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint16mf2_t v = *(vint16mf2_t*)(in + 900 + i);
> +    *(vint16mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f6 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
> +    *(vint32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vint32mf2_t v = *(vint32mf2_t*)(in + 500);
> +    *(vint32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vint32mf2_t v = *(vint32mf2_t*)(in + 900 + i);
> +    *(vint32mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { 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_bb_prop-14.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c
> new file mode 100644
> index 00000000000..a43aad71808
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-14.c
> @@ -0,0 +1,221 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
> +    *(vuint8mf8_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
> +    *(vuint8mf8_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
> +    *(vuint8mf8_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f2 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
> +    *(vuint8mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
> +    *(vuint8mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
> +    *(vuint8mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f3 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
> +    *(vuint8mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
> +    *(vuint8mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
> +    *(vuint8mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f4 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
> +    *(vuint16mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
> +    *(vuint16mf4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
> +    *(vuint16mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f5 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
> +    *(vuint16mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
> +    *(vuint16mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
> +    *(vuint16mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f6 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
> +    *(vuint32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
> +    *(vuint32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
> +    *(vuint32mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { 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_bb_prop-15.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c
> new file mode 100644
> index 00000000000..6938cf80723
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-15.c
> @@ -0,0 +1,41 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
> +    *(vfloat32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 500);
> +    *(vfloat32mf2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 900 + i);
> +    *(vfloat32mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { 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_bb_prop-16.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c
> new file mode 100644
> index 00000000000..10901a0b205
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-16.c
> @@ -0,0 +1,257 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool64_t v = *(vbool64_t*)(in + 500);
> +    *(vbool64_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool64_t v = *(vbool64_t*)(in + 500);
> +    *(vbool64_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool64_t v = *(vbool64_t*)(in + 900 + i);
> +    *(vbool64_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f2 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool32_t v = *(vbool32_t*)(in + 500);
> +    *(vbool32_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool32_t v = *(vbool32_t*)(in + 500);
> +    *(vbool32_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool32_t v = *(vbool32_t*)(in + 900 + i);
> +    *(vbool32_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f3 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool16_t v = *(vbool16_t*)(in + 500);
> +    *(vbool16_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool16_t v = *(vbool16_t*)(in + 500);
> +    *(vbool16_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool16_t v = *(vbool16_t*)(in + 900 + i);
> +    *(vbool16_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f4 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool8_t v = *(vbool8_t*)(in + 500);
> +    *(vbool8_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool8_t v = *(vbool8_t*)(in + 500);
> +    *(vbool8_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool8_t v = *(vbool8_t*)(in + 900 + i);
> +    *(vbool8_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f5 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool4_t v = *(vbool4_t*)(in + 500);
> +    *(vbool4_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool4_t v = *(vbool4_t*)(in + 500);
> +    *(vbool4_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool4_t v = *(vbool4_t*)(in + 900 + i);
> +    *(vbool4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f6 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool2_t v = *(vbool2_t*)(in + 500);
> +    *(vbool2_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool2_t v = *(vbool2_t*)(in + 500);
> +    *(vbool2_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool2_t v = *(vbool2_t*)(in + 900 + i);
> +    *(vbool2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f7 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  switch (n)
> +  {
> +  case 0:{
> +    vbool1_t v = *(vbool1_t*)(in + 500);
> +    *(vbool1_t*)(out + 500) = v;
> +    break;
> +  }
> +  case 1:{
> +    vbool1_t v = *(vbool1_t*)(in + 500);
> +    *(vbool1_t*)(out + 500) = v;
> +    break;
> +  }
> +  default:{
> +    break;
> +  }
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vbool1_t v = *(vbool1_t*)(in + 900 + i);
> +    *(vbool1_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m1,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m2,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m4,\s*t[au],\s*m[au]\s+\.L[0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*m8,\s*t[au],\s*m[au]\s+\.L[0-9][0-9][0-9]\:\s+vlm\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O1" } } } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c
> new file mode 100644
> index 00000000000..01345617fab
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-17.c
> @@ -0,0 +1,177 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vint8mf8_t v = *(vint8mf8_t*)(in + 100);
> +      *(vint8mf8_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vint8mf8_t v = *(vint8mf8_t*)(in + 200);
> +      *(vint8mf8_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vint8mf8_t v = *(vint8mf8_t*)(in + i);
> +      *(vint8mf8_t*)(out + i) = v;
> +    }
> +}
> +
> +void f2 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vint8mf4_t v = *(vint8mf4_t*)(in + 100);
> +      *(vint8mf4_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vint8mf4_t v = *(vint8mf4_t*)(in + 200);
> +      *(vint8mf4_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vint8mf4_t v = *(vint8mf4_t*)(in + i);
> +      *(vint8mf4_t*)(out + i) = v;
> +    }
> +}
> +
> +void f3 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vint8mf2_t v = *(vint8mf2_t*)(in + 100);
> +      *(vint8mf2_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vint8mf2_t v = *(vint8mf2_t*)(in + 200);
> +      *(vint8mf2_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vint8mf2_t v = *(vint8mf2_t*)(in + i);
> +      *(vint8mf2_t*)(out + i) = v;
> +    }
> +}
> +
> +void f4 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vint16mf4_t v = *(vint16mf4_t*)(in + 100);
> +      *(vint16mf4_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vint16mf4_t v = *(vint16mf4_t*)(in + 200);
> +      *(vint16mf4_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vint16mf4_t v = *(vint16mf4_t*)(in + i);
> +      *(vint16mf4_t*)(out + i) = v;
> +    }
> +}
> +
> +void f5 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vint16mf2_t v = *(vint16mf2_t*)(in + 100);
> +      *(vint16mf2_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vint16mf2_t v = *(vint16mf2_t*)(in + 200);
> +      *(vint16mf2_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vint16mf2_t v = *(vint16mf2_t*)(in + i);
> +      *(vint16mf2_t*)(out + i) = v;
> +    }
> +}
> +
> +void f6 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vint32mf2_t v = *(vint32mf2_t*)(in + 100);
> +      *(vint32mf2_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vint32mf2_t v = *(vint32mf2_t*)(in + 200);
> +      *(vint32mf2_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vint32mf2_t v = *(vint32mf2_t*)(in + i);
> +      *(vint32mf2_t*)(out + i) = v;
> +    }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\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
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { 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_bb_prop-18.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c
> new file mode 100644
> index 00000000000..c296670e2d5
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-18.c
> @@ -0,0 +1,177 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vuint8mf8_t v = *(vuint8mf8_t*)(in + 100);
> +      *(vuint8mf8_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vuint8mf8_t v = *(vuint8mf8_t*)(in + 200);
> +      *(vuint8mf8_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vuint8mf8_t v = *(vuint8mf8_t*)(in + i);
> +      *(vuint8mf8_t*)(out + i) = v;
> +    }
> +}
> +
> +void f2 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vuint8mf4_t v = *(vuint8mf4_t*)(in + 100);
> +      *(vuint8mf4_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vuint8mf4_t v = *(vuint8mf4_t*)(in + 200);
> +      *(vuint8mf4_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vuint8mf4_t v = *(vuint8mf4_t*)(in + i);
> +      *(vuint8mf4_t*)(out + i) = v;
> +    }
> +}
> +
> +void f3 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vuint8mf2_t v = *(vuint8mf2_t*)(in + 100);
> +      *(vuint8mf2_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vuint8mf2_t v = *(vuint8mf2_t*)(in + 200);
> +      *(vuint8mf2_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vuint8mf2_t v = *(vuint8mf2_t*)(in + i);
> +      *(vuint8mf2_t*)(out + i) = v;
> +    }
> +}
> +
> +void f4 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vuint16mf4_t v = *(vuint16mf4_t*)(in + 100);
> +      *(vuint16mf4_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vuint16mf4_t v = *(vuint16mf4_t*)(in + 200);
> +      *(vuint16mf4_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vuint16mf4_t v = *(vuint16mf4_t*)(in + i);
> +      *(vuint16mf4_t*)(out + i) = v;
> +    }
> +}
> +
> +void f5 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vuint16mf2_t v = *(vuint16mf2_t*)(in + 100);
> +      *(vuint16mf2_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vuint16mf2_t v = *(vuint16mf2_t*)(in + 200);
> +      *(vuint16mf2_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vuint16mf2_t v = *(vuint16mf2_t*)(in + i);
> +      *(vuint16mf2_t*)(out + i) = v;
> +    }
> +}
> +
> +void f6 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vuint32mf2_t v = *(vuint32mf2_t*)(in + 100);
> +      *(vuint32mf2_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vuint32mf2_t v = *(vuint32mf2_t*)(in + 200);
> +      *(vuint32mf2_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vuint32mf2_t v = *(vuint32mf2_t*)(in + i);
> +      *(vuint32mf2_t*)(out + i) = v;
> +    }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\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\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\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
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { 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_bb_prop-19.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c
> new file mode 100644
> index 00000000000..d87b2381daf
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-19.c
> @@ -0,0 +1,34 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f6 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 100);
> +      *(vfloat32mf2_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vfloat32mf2_t v = *(vfloat32mf2_t*)(in + 200);
> +      *(vfloat32mf2_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vfloat32mf2_t v = *(vfloat32mf2_t*)(in + i);
> +      *(vfloat32mf2_t*)(out + i) = v;
> +    }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\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
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { 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_bb_prop-2.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c
> new file mode 100644
> index 00000000000..ce94f4a12b2
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-2.c
> @@ -0,0 +1,182 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vuint8mf8_t v = *(vuint8mf8_t*)(in + 500);
> +    *(vuint8mf8_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vuint8mf8_t v = *(vuint8mf8_t*)(in + 600);
> +    *(vuint8mf8_t*)(out + 600) = v;
> +  } else {
> +    vuint8mf8_t v = *(vuint8mf8_t*)(in + 700);
> +    *(vuint8mf8_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint8mf8_t v = *(vuint8mf8_t*)(in + 900 + i);
> +    *(vuint8mf8_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f2 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vuint8mf4_t v = *(vuint8mf4_t*)(in + 500);
> +    *(vuint8mf4_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vuint8mf4_t v = *(vuint8mf4_t*)(in + 600);
> +    *(vuint8mf4_t*)(out + 600) = v;
> +  } else {
> +    vuint8mf4_t v = *(vuint8mf4_t*)(in + 700);
> +    *(vuint8mf4_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint8mf4_t v = *(vuint8mf4_t*)(in + 900 + i);
> +    *(vuint8mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f3 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vuint8mf2_t v = *(vuint8mf2_t*)(in + 500);
> +    *(vuint8mf2_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vuint8mf2_t v = *(vuint8mf2_t*)(in + 600);
> +    *(vuint8mf2_t*)(out + 600) = v;
> +  } else {
> +    vuint8mf2_t v = *(vuint8mf2_t*)(in + 700);
> +    *(vuint8mf2_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint8mf2_t v = *(vuint8mf2_t*)(in + 900 + i);
> +    *(vuint8mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f4 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vuint16mf4_t v = *(vuint16mf4_t*)(in + 500);
> +    *(vuint16mf4_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vuint16mf4_t v = *(vuint16mf4_t*)(in + 600);
> +    *(vuint16mf4_t*)(out + 600) = v;
> +  } else {
> +    vuint16mf4_t v = *(vuint16mf4_t*)(in + 700);
> +    *(vuint16mf4_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint16mf4_t v = *(vuint16mf4_t*)(in + 900 + i);
> +    *(vuint16mf4_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f5 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vuint16mf2_t v = *(vuint16mf2_t*)(in + 500);
> +    *(vuint16mf2_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vuint16mf2_t v = *(vuint16mf2_t*)(in + 600);
> +    *(vuint16mf2_t*)(out + 600) = v;
> +  } else {
> +    vuint16mf2_t v = *(vuint16mf2_t*)(in + 700);
> +    *(vuint16mf2_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint16mf2_t v = *(vuint16mf2_t*)(in + 900 + i);
> +    *(vuint16mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +void f6 (int8_t * restrict in, int8_t * restrict out, int n)
> +{
> +  if (n == 0) {
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 500);
> +    *(vuint32mf2_t*)(out + 500) = v;
> +  } else if (n == 1) {
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 600);
> +    *(vuint32mf2_t*)(out + 600) = v;
> +  } else {
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 700);
> +    *(vuint32mf2_t*)(out + 700) = v;
> +  }
> +
> +  for (int i = 0 ; i < n * n; i++)
> +    out[i] = out[i] + out[i];
> +
> +  for (int i = 0 ; i < n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++)
> +    out[i] = out[i] * out[i];
> +
> +  for (int i = 0 ; i < n * n * n * n; i++) {
> +    vuint32mf2_t v = *(vuint32mf2_t*)(in + 900 + i);
> +    *(vuint32mf2_t*)(out + 900 + i) = v;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf8,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e8,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle8\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf4,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e16,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle16\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 2 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {vsetvli\s+(?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7]),\s*zero,\s*e32,\s*mf2,\s*t[au],\s*m[au]}
> 3 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> +/* { dg-final { scan-assembler-times
> {add\ta[0-7],a[0-7],a[0-7]\s+\.L[0-9][0-9]\:\s+vle32\.v\s+(?:v[0-9]|v[1-2][0-9]|v3[0-1]),0\s*\((?:ra|[sgtf]p|t[0-6]|s[0-9]|s10|s11|a[0-7])\)}
> 1 { target { no-opts "-O0"  no-opts "-Os" no-opts "-funroll-loops" no-opts
> "-g" no-opts "-O2" no-opts "-O1" } } } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c
> b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c
> new file mode 100644
> index 00000000000..273a2853282
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/vlmax_bb_prop-20.c
> @@ -0,0 +1,203 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=rv32gcv -mabi=ilp32 -fno-tree-vectorize" } */
> +
> +#include "riscv_vector.h"
> +
> +void f (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vbool64_t v = *(vbool64_t*)(in + 100);
> +      *(vbool64_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vbool64_t v = *(vbool64_t*)(in + 200);
> +      *(vbool64_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vbool64_t v = *(vbool64_t*)(in + i);
> +      *(vbool64_t*)(out + i) = v;
> +    }
> +}
> +
> +void f2 (int * restrict in, int * restrict out, int n, int cond)
> +{
> +  if (cond == 1)
> +    {
> +      vbool32_t v = *(vbool32_t*)(in + 100);
> +      *(vbool32_t*)(out + 100) = v;
> +    }
> +  else
> +    {
> +      vbool32_t v = *(vbool32_t*)(in + 200);
> +      *(vbool32_t*)(out + 200) = v;
> +      if (cond == 2)
> +        {
> +          out[1000] = 8000;
> +        }
> +      else
> +        {
> +          out[2000] = 9000;
> +        }
> +    }
> +  for (int i = 0; i < n; i++)
> +    {
> +      vbool32_t v = *(vbool32_t*)(in

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

end of thread, other threads:[~2022-12-19 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14  8:19 [PATCH] RISC-V: Add testcases for VSETVL PASS 4 juzhe.zhong
2022-12-19 15:09 ` Kito Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).