Hi,

This patch makes -mrvv-max-lmul=conv-dynamic spill aware.
As reported by Anton, Peter in PR127075, we don't consider spilling when
letting the LMUL decision just be dependent on the size ratio of largest
and smallest type.  This causes spills when building x264 with the
conv-dynamic mode.

Although the original idea was to have a more deterministic approach
than pure "dynamic", determinism alone is not too helpful when spills 
are still possible.

Thus, this patch merges the spill estimate of "dynamic" into
"conv-dynamic" and also corrects some mistakes in "dynamic".
It had VLS assumptions that haven't been true for a while, i.e. that we
cannot use length masking when niters is unknown.

There is a bit of overlap with Bohan's patch from this morning.  I guess 
I'll wait for it and rebase once it's in.  I also have two follow-ups in 
flight that fix a few issues in "dynamic", refactor more of the code and 
improve performance slightly.

Regtested on rv64gcv_zvl512b.

Regards
 Robin

        PR target/127075

gcc/ChangeLog:

        * config/riscv/riscv-vector-costs.cc (compute_estimated_lmul):
        Fix VLS LMUL computation.
        (costs::compute_live_ranges_and_lmul): Store conv-dynamic lmul.
        (costs::has_unexpected_spills_p): Rename...
        (costs::has_spills_p): ...To This.
        (costs::record_lmul_spills): Call renamed function.
        (costs::record_potential_unexpected_spills): Rename...
        (costs::record_potential_spills): ...To This.
        (costs::better_main_loop_than_p): Reject spilling conv-dynamic
        loops.
        * config/riscv/riscv-vector-costs.h: Rename functions.

gcc/testsuite/ChangeLog:

        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-1.c: Adjust test
        expectations.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-2.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-3.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-4.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-5.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-6.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-7.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-1.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-2.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-3.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-4.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-5.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-1.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-12.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-2.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-3.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-5.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-7.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-1.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-10.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-13.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-14.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-15.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-2.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-3.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-4.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-5.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-6.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-7.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-8.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-9.c: Ditto.
        * gcc.dg/vect/costmodel/riscv/rvv/pr127075.c: New test.
---
 gcc/config/riscv/riscv-vector-costs.cc        | 90 ++++++++++---------
 gcc/config/riscv/riscv-vector-costs.h         | 10 +--
 .../costmodel/riscv/rvv/dynamic-lmul1-1.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul1-2.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul1-3.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul1-4.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul1-5.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul1-6.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul1-7.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul2-1.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul2-2.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul2-3.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul2-4.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul2-5.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul4-1.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul4-12.c    |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul4-2.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul4-3.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul4-5.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul4-7.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-1.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-10.c    |  4 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-11.c    |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-13.c    |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-14.c    |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-15.c    |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-2.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-3.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-4.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-5.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-6.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-7.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-8.c     |  6 +-
 .../costmodel/riscv/rvv/dynamic-lmul8-9.c     |  4 +-
 .../vect/costmodel/riscv/rvv/pr127075.c       | 29 ++++++
 35 files changed, 177 insertions(+), 140 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr127075.c

diff --git a/gcc/config/riscv/riscv-vector-costs.cc 
b/gcc/config/riscv/riscv-vector-costs.cc
index 41a15ae220a..e6914ab612f 100644
--- a/gcc/config/riscv/riscv-vector-costs.cc
+++ b/gcc/config/riscv/riscv-vector-costs.cc
@@ -648,20 +648,13 @@ static int
 compute_estimated_lmul (loop_vec_info loop_vinfo, machine_mode mode)
 {
   gcc_assert (GET_MODE_BITSIZE (mode).is_constant ());
-  int regno_alignment = riscv_get_v_regno_alignment (loop_vinfo->vector_mode);
-  if (riscv_vls_mode_p (loop_vinfo->vector_mode))
-    return regno_alignment;
+  int estimated_vf = vect_vf_for_cost (loop_vinfo);
+  int estimated_lmul = estimated_vf * GET_MODE_BITSIZE (mode).to_constant ()
+    / TARGET_MIN_VLEN;
+  if (estimated_lmul > RVV_M8)
+    return RVV_M8;
   else
-    {
-      int estimated_vf = vect_vf_for_cost (loop_vinfo);
-      int estimated_lmul = estimated_vf * GET_MODE_BITSIZE (mode).to_constant 
()
-                          / TARGET_MIN_VLEN;
-      if (estimated_lmul > RVV_M8)
-       return RVV_M8;
-      else
-       return estimated_lmul;
-    }
-  return 0;
+    return estimated_lmul;
 }
 
 /* Compute LMUL based on the ratio of biggest to smallest type size.
@@ -886,9 +879,16 @@ costs::compute_live_ranges_and_lmul (loop_vec_info 
loop_vinfo,
                            live_ranges_per_bb, &biggest_mode);
 
   if (rvv_max_lmul == RVV_CONV_DYNAMIC)
-    lmul = compute_lmul_from_conversion_ratio (biggest_mode, smallest_mode);
-  else
-    lmul = compute_estimated_lmul (loop_vinfo, biggest_mode);
+    {
+      /* Store the computed LMUL and biggest mode for later comparison
+        in cost model.  */
+      m_computed_lmul_from_conv
+       = compute_lmul_from_conversion_ratio (biggest_mode, smallest_mode);
+      m_biggest_mode_for_conv = biggest_mode;
+    }
+
+  lmul = compute_estimated_lmul (loop_vinfo, biggest_mode);
+  lmul = std::max (lmul, 1);
 
   gcc_assert (lmul <= RVV_M8);
 }
@@ -928,17 +928,12 @@ costs::compute_conversion_dynamic_lmul (loop_vec_info 
loop_vinfo)
                                live_ranges_per_bb, biggest_mode,
                                smallest_mode, lmul);
 
-  /* Store the computed LMUL and biggest mode for later comparison
-     in cost model.  */
-  m_computed_lmul_from_conv = lmul;
-  m_biggest_mode_for_conv = biggest_mode;
-
   cleanup_live_range_data (program_points_per_bb, live_ranges_per_bb);
 }
 
-/* Compute the maximum live V_REGS and check for unexpected spills.  */
+/* Compute the maximum live V_REGS and check for spills.  */
 bool
-costs::has_unexpected_spills_p (loop_vec_info loop_vinfo)
+costs::has_spills_p (loop_vec_info loop_vinfo)
 {
   hash_map<basic_block, vec<stmt_point>> program_points_per_bb;
   hash_map<basic_block, hash_map<tree, pair>> live_ranges_per_bb;
@@ -1004,26 +999,29 @@ costs::analyze_loop_vinfo (loop_vec_info loop_vinfo)
 void
 costs::record_lmul_spills (loop_vec_info loop_vinfo)
 {
-  /* Detect whether the LOOP has unexpected spills.  */
-  record_potential_unexpected_spills (loop_vinfo);
+  /* Detect whether the LOOP spills.  */
+  record_potential_spills (loop_vinfo);
 }
 
 /* Analyze the vectorized program statements and use dynamic LMUL
-   heuristic to detect whether the loop has unexpected spills.  */
+   heuristic to detect whether the loop spills.  */
 void
-costs::record_potential_unexpected_spills (loop_vec_info loop_vinfo)
+costs::record_potential_spills (loop_vec_info loop_vinfo)
 {
   /* We only want to apply the heuristic if LOOP_VINFO is being
-     vectorized for VLA and known NITERS VLS loop.  */
-  if (rvv_max_lmul == RVV_DYNAMIC
+     vectorized with VLA modes and known NITERS or a partial-vector
+     VLS loop.  */
+  if ((rvv_max_lmul == RVV_DYNAMIC
+       || rvv_max_lmul == RVV_CONV_DYNAMIC)
       && (m_cost_type == VLA_VECTOR_COST
          || (m_cost_type == VLS_VECTOR_COST
-             && LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo))))
+             && (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
+                 || LOOP_VINFO_USING_PARTIAL_VECTORS_P (loop_vinfo)))))
     {
       bool post_dom_available_p = dom_info_available_p (CDI_POST_DOMINATORS);
       if (!post_dom_available_p)
        calculate_dominance_info (CDI_POST_DOMINATORS);
-      m_has_unexpected_spills_p = has_unexpected_spills_p (loop_vinfo);
+      m_has_spills_p = has_spills_p (loop_vinfo);
       if (!post_dom_available_p)
        free_dominance_info (CDI_POST_DOMINATORS);
     }
@@ -1217,7 +1215,8 @@ costs::better_main_loop_than_p (const vector_costs 
*uncast_other) const
          int target_lmul = this->m_computed_lmul_from_conv;
 
          /* Prefer the LMUL that exactly matches our computed ratio.  */
-         if (this_lmul == target_lmul && other_lmul != target_lmul)
+         if (this_lmul == target_lmul && other_lmul != target_lmul
+             && !this->m_has_spills_p)
            {
              if (dump_enabled_p ())
                dump_printf_loc (MSG_NOTE, vect_location,
@@ -1226,7 +1225,8 @@ costs::better_main_loop_than_p (const vector_costs 
*uncast_other) const
                                 this_lmul, other_lmul);
              return true;
            }
-         else if (this_lmul != target_lmul && other_lmul == target_lmul)
+         else if (this_lmul != target_lmul && other_lmul == target_lmul
+                  && !other->m_has_spills_p)
            {
              if (dump_enabled_p ())
                dump_printf_loc (MSG_NOTE, vect_location,
@@ -1235,11 +1235,20 @@ costs::better_main_loop_than_p (const vector_costs 
*uncast_other) const
                                 " (this LMUL=%d)\n", other_lmul, this_lmul);
              return false;
            }
+
+         if (other->m_has_spills_p)
+           {
+             if (dump_enabled_p ())
+               dump_printf_loc (MSG_NOTE, vect_location,
+                                "Preferring smaller LMUL loop because"
+                                " it has unexpected spills\n");
+             return true;
+           }
        }
     }
   else if (rvv_max_lmul == RVV_DYNAMIC)
     {
-      if (other->m_has_unexpected_spills_p)
+      if (other->m_has_spills_p)
        {
          if (dump_enabled_p ())
            dump_printf_loc (MSG_NOTE, vect_location,
@@ -1261,7 +1270,7 @@ costs::better_main_loop_than_p (const vector_costs 
*uncast_other) const
                  return false;
                }
            }
-         else
+         else if (!LOOP_VINFO_NITERS_KNOWN_P (other_loop_vinfo))
            {
              if (dump_enabled_p ())
                dump_printf_loc (MSG_NOTE, vect_location,
@@ -1271,13 +1280,12 @@ costs::better_main_loop_than_p (const vector_costs 
*uncast_other) const
            }
        }
     }
-  /* If NITERS is unknown, we should not use VLS modes to vectorize
-     the loop since we don't support partial vectors for VLS modes,
-     that is, we will have full vectors (VLSmodes) on loop body
-     and partial vectors (VLAmodes) on loop epilogue which is very
-     inefficient.  Instead, we should apply partial vectors (VLAmodes)
-     on loop body without an epilogue on unknown NITERS loop.  */
+  /* If the number of iterations are unknown and we don't use partial
+     vectors for a loop, decline this attempt.  We don't usually want
+     VLS-style loops with an epilogue where the epilogue uses VLA
+     modes.  */
   else if (!LOOP_VINFO_NITERS_KNOWN_P (this_loop_vinfo)
+          && !LOOP_VINFO_USING_PARTIAL_VECTORS_P (this_loop_vinfo)
           && m_cost_type == VLS_VECTOR_COST)
     return false;
 
diff --git a/gcc/config/riscv/riscv-vector-costs.h 
b/gcc/config/riscv/riscv-vector-costs.h
index 74f1eab4001..9bf71afc865 100644
--- a/gcc/config/riscv/riscv-vector-costs.h
+++ b/gcc/config/riscv/riscv-vector-costs.h
@@ -101,10 +101,10 @@ private:
   /* Analyze the vectorized program statements and compute the maximum live
      V_REGS live at some program point if we enable dynamic LMUL cost model.
 
-     It's true when LMUL of loop vectorization factor > 1 and has unexpected
-     V_REGS spills according to the analysis.  */
-  bool m_has_unexpected_spills_p = false;
-  void record_potential_unexpected_spills (loop_vec_info);
+     It's true when LMUL of loop vectorization factor > 1 and spills V_REGS
+     according to the analysis.  */
+  bool m_has_spills_p = false;
+  void record_potential_spills (loop_vec_info);
 
   /* For RVV_DYNAMIC_CONV mode, store the LMUL computed from conversion ratio
      and the biggest mode used in the computation.  */
@@ -128,7 +128,7 @@ private:
                                     machine_mode &, machine_mode &, int &);
   void cleanup_live_range_data (hash_map<basic_block, vec<stmt_point>> &,
                                hash_map<basic_block, hash_map<tree, pair>> &);
-  bool has_unexpected_spills_p (loop_vec_info);
+  bool has_spills_p (loop_vec_info);
   void compute_conversion_dynamic_lmul (loop_vec_info);
   bool need_additional_vector_vars_p (stmt_vec_info, slp_tree);
 
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-1.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-1.c
index d5fd0f2e320..deef07f8ea9 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-1.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-1.c
@@ -86,6 +86,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b,    int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e32,m1} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 3 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-2.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-2.c
index a0e61303e80..a08f17c9827 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-2.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-2.c
@@ -58,6 +58,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b,    int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e32,m1} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 3 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-3.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-3.c
index 2111c0bbc9a..fec53e47a7e 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-3.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-3.c
@@ -86,6 +86,6 @@ foo (int8_t *__restrict a, int8_t *__restrict b,    int8_t 
*__restrict c,
 /* { dg-final { scan-assembler {e8,m1} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 3 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-4.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-4.c
index c47a4c4ceb1..3157fb14687 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-4.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-4.c
@@ -116,6 +116,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b,    
int32_t *__restrict c,
 /* { dg-final { scan-assembler {e32,m1} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 3 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-5.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-5.c
index e4b74f037e3..6c083aae3e7 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-5.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-5.c
@@ -144,6 +144,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b,    
int32_t *__restrict c,
 /* { dg-final { scan-assembler {e32,m1} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 3 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-6.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-6.c
index 73d16dab732..9f03eb1b36d 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-6.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-6.c
@@ -145,6 +145,6 @@ foo (int8_t *__restrict a, int8_t *__restrict b,    int8_t 
*__restrict c,
 /* { dg-final { scan-assembler {e8,m1} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 3 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-7.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-7.c
index b76bb4b06b4..4e48521c08d 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-7.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul1-7.c
@@ -43,6 +43,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b, int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e32,m1} } } */
 /* { dg-final { scan-assembler-not {csrr} { xfail "*-*-*" } } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 3 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-1.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-1.c
index 6637f3c3e3f..1c5a58b429c 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-1.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-1.c
@@ -46,6 +46,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b,    int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e32,m2} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-2.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-2.c
index 554512245c0..aa5d9ed77d7 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-2.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-2.c
@@ -46,6 +46,6 @@ foo (int8_t *__restrict a, int8_t *__restrict b,    int8_t 
*__restrict c,
 /* { dg-final { scan-assembler {e8,m2} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-3.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-3.c
index 6637f3c3e3f..1c5a58b429c 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-3.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-3.c
@@ -46,6 +46,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b,    int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e32,m2} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-4.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-4.c
index a8e603f90f3..1350729a4e5 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-4.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-4.c
@@ -44,6 +44,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b, int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e32,m2} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-5.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-5.c
index dcb20a302c8..9875a02e202 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-5.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul2-5.c
@@ -47,6 +47,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b, int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e8,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-1.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-1.c
index 65082139182..a7bc7e8f67f 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-1.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-1.c
@@ -30,6 +30,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b, int32_t 
*__restrict c,
 /* { dg-final { scan-assembler {e32,m4} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-12.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-12.c
index 29e6dfc223e..690a51a2d67 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-12.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-12.c
@@ -35,6 +35,6 @@ f2 (int *restrict a, int *restrict b, int *restrict c, int 
*restrict d,
 /* { dg-final { scan-assembler-not {e32,m1} } } */
 /* { dg-final { scan-assembler-times {ret} 2 } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 4 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 4 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 4 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-2.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-2.c
index 95742e2a7a1..b2c2178db1e 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-2.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-2.c
@@ -30,6 +30,6 @@ foo (int8_t *__restrict a, int8_t *__restrict b, int8_t 
*__restrict c,
 /* { dg-final { scan-assembler {e8,m4} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-3.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-3.c
index 85e3021f1c2..4d793fdb263 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-3.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-3.c
@@ -43,6 +43,6 @@ void foo2 (int64_t *__restrict a,
 /* { dg-final { scan-assembler {e64,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-5.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-5.c
index 387c3847cf2..9ec8fca52d6 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-5.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-5.c
@@ -42,6 +42,6 @@ void foo2 (int16_t *__restrict a,
 /* { dg-final { scan-assembler {e16,m2} { xfail *-*-* } } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 1 "vect" { xfail *-*-* } } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-7.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-7.c
index 259885f6739..f3cc8215e43 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-7.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul4-7.c
@@ -42,6 +42,6 @@ void foo2 (int8_t *__restrict a,
 /* { dg-final { scan-assembler {e64,m4} { xfail *-*-* } } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-times "Preferring smaller LMUL loop because it 
has unexpected spills" 1 "vect" { xfail *-*-* } } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-1.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-1.c
index 87e6b099069..f6aa06ad394 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-1.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-1.c
@@ -13,6 +13,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b, int n)
 /* { dg-final { scan-assembler {e32,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-10.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-10.c
index c5e78a12ac6..a25c9e625a3 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-10.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-10.c
@@ -17,5 +17,5 @@ foo (int *x, int n, int res)
 /* { dg-final { scan-assembler {e32,m8} } } */
 /* { dg-final { scan-assembler-times {csrr} 1 } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c
index c9e28251225..dd9864576c1 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-11.c
@@ -42,6 +42,6 @@ void foo2 (int64_t *__restrict a,
 /* { dg-final { scan-assembler {e64,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-13.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-13.c
index 40a3acd4088..0af0b5b546c 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-13.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-13.c
@@ -69,6 +69,6 @@ f5 (int *restrict a, int *restrict b, int *restrict c, int 
*restrict d, int n)
 /* { dg-final { scan-assembler-not {e32,m1} } } */
 /* { dg-final { scan-assembler-times {ret} 5 } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 5 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 5 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 5 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 10 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 10 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 10 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-14.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-14.c
index 9a9bb487504..0ff9cde88f2 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-14.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-14.c
@@ -59,6 +59,6 @@ f4 (int *restrict a, int *restrict b, int *restrict c, int 
*restrict d, int n)
 /* { dg-final { scan-assembler-not {e32,m1} } } */
 /* { dg-final { scan-assembler-times {ret} 4 } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 4 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 4 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 4 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 8 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 8 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 8 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-15.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-15.c
index dfaca768ba9..a1fbc23faea 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-15.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-15.c
@@ -42,6 +42,6 @@ void foo2 (int64_t *__restrict a,
 /* { dg-final { scan-assembler {e64,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-2.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-2.c
index 15c615fa1cf..e6c7fe889b3 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-2.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-2.c
@@ -13,6 +13,6 @@ foo (int32_t *__restrict a, int16_t *__restrict b, int n)
 /* { dg-final { scan-assembler {e16,m4} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-3.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-3.c
index c0f55a49a79..c76cd7d6050 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-3.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-3.c
@@ -13,6 +13,6 @@ foo (int8_t *__restrict a, int8_t *__restrict b, int n)
 /* { dg-final { scan-assembler {e8,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-4.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-4.c
index 91af60d717a..7397f803bbd 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-4.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-4.c
@@ -14,6 +14,6 @@ foo (size_t *__restrict a, size_t *__restrict b, int n)
 /* { dg-final { scan-assembler {e64,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 4 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-5.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-5.c
index ba2822f2e53..deeb31aea6d 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-5.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-5.c
@@ -20,6 +20,6 @@ foo (int8_t *__restrict a, int8_t *__restrict b, int n)
 /* { dg-final { scan-assembler {e8,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-6.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-6.c
index d8c365330b4..35278977ba8 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-6.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-6.c
@@ -18,6 +18,6 @@ foo (int8_t *__restrict a, int8_t *__restrict b, int8_t 
*__restrict a2,
 /* { dg-final { scan-assembler {e8,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-7.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-7.c
index 33012ec11d4..807b4e93994 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-7.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-7.c
@@ -18,6 +18,6 @@ foo (int32_t *__restrict a, int32_t *__restrict b, int32_t 
*__restrict a2,
 /* { dg-final { scan-assembler {e32,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-8.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-8.c
index aad04c48b67..160508714ee 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-8.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-8.c
@@ -14,6 +14,6 @@ foo (int8_t *__restrict a, int8_t init, int n)
 /* { dg-final { scan-assembler {e8,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 8" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-9.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-9.c
index 56234580fa8..f5cb764417d 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-9.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/dynamic-lmul8-9.c
@@ -14,5 +14,5 @@ foo (int64_t *__restrict a, int64_t init, int n)
 /* { dg-final { scan-assembler {e64,m8} } } */
 /* { dg-final { scan-assembler-not {csrr} } } */
 /* { dg-final { scan-tree-dump-not "Preferring smaller LMUL loop because it 
has unexpected spills" "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 1 "vect" } } */
-/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 1 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 4" 2 "vect" } } */
+/* { dg-final { scan-tree-dump-times "Maximum lmul = 2" 2 "vect" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr127075.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr127075.c
new file mode 100644
index 00000000000..651eecd28ef
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr127075.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d -mrvv-max-lmul=conv-dynamic" } 
*/
+
+/* Ensure we choose no larger than LMUL2. LMUL4 and LMUL8 cause spilling.  */
+
+#include <stdint.h>
+
+void
+wide (uint8_t *__restrict a, uint8_t *__restrict b,
+      uint8_t *__restrict c, uint8_t *__restrict d,
+      int64_t *__restrict o0, int64_t *__restrict o1,
+      int64_t *__restrict o2, int64_t *__restrict o3,
+      int64_t *__restrict o4, int64_t *__restrict o5, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      int64_t va = a[i], vb = b[i], vc = c[i], vd = d[i];
+      int64_t t0 = va + vb, t1 = vb + vc, t2 = vc + vd, t3 = vd + va;
+      int64_t t4 = va * vb, t5 = vb * vc, t6 = vc * vd, t7 = vd * va;
+      o0[i] = t0 + t4;
+      o1[i] = t1 + t5;
+      o2[i] = t2 + t6;
+      o3[i] = t3 + t7;
+      o4[i] = t0 * t1 + t2 * t3;
+      o5[i] = t4 * t5 + t6 * t7;
+    }
+}
+
+/* { dg-final { scan-assembler-not "vs\[1248\]r" } } */
-- 
2.55.0

Reply via email to