Commited to trunk

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

> From: Ju-Zhe Zhong <juzhe.zh...@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

Reply via email to