https://gcc.gnu.org/g:78873c4dcee4b92347501b898f426d4302e374c0

commit r17-5969-g78873c4dcee4b92347501b898f426d4302e374c0
Author: Zhongyao Chen <[email protected]>
Date:   Thu Oct 29 17:25:11 2026 +0800

    RISC-V: Remove redundant VLA niters check in better_main_loop_than_p
    
    In better_main_loop_than_p we keep the current LMUL if the loop NITERS > VF.
    Because we try M8 first, this early exit locks in M8 before
    compare_inside_loop_cost is called.
    
    In pr113112-3.c (NITERS = 25) the vect dump shows:
    
      Vector inside of loop cost: 105
      ***** Analysis succeeded with vector mode RVVM8SI
      ...
      Vector inside of loop cost: 49
      ***** Analysis succeeded with vector mode RVVMF2QI
      Comparing two main loops (RVVMF2QI at VF 8 vs RVVM8SI at VF 8)
      Keep current LMUL loop because known NITERS exceed the new VF
    
    Because 25 > 8, we reject RVVMF2QI even though both have VF 8 and
    RVVMF2QI has lower inside cost.
    
    Furthermore, this check is redundant with compare_loop_overhead,
    which already compares estimated vector loop iterations and branch overhead.
    
    This patch removes it and also fixes the XFAILs in pr113112-3.c.
    
    gcc/ChangeLog:
    
            * config/riscv/riscv-vector-costs.cc 
(costs::better_main_loop_than_p):
            Remove redundant VLA niters heuristic.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/vect/costmodel/riscv/rvv/pr113112-3.c: Remove XFAILs.
    
    Signed-off-by: Zhongyao Chen <[email protected]>

Diff:
---
 gcc/config/riscv/riscv-vector-costs.cc                | 19 -------------------
 .../gcc.dg/vect/costmodel/riscv/rvv/pr113112-3.c      |  6 +++---
 2 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-costs.cc 
b/gcc/config/riscv/riscv-vector-costs.cc
index 70194ec70c32..d26a390793c3 100644
--- a/gcc/config/riscv/riscv-vector-costs.cc
+++ b/gcc/config/riscv/riscv-vector-costs.cc
@@ -1216,25 +1216,6 @@ costs::better_main_loop_than_p (const vector_costs 
*uncast_other) const
          return other_prefer_unrolled;
        }
     }
-  else if (riscv_vla_mode_p (other_loop_vinfo->vector_mode))
-    {
-      /* We don't want modes that would span more scalar iterations than
-        we actually have.
-        ??? We might want to revisit this in the light of VLMAX-dependent
-        vs VL-dependent latency.  */
-      if (LOOP_VINFO_NITERS_KNOWN_P (other_loop_vinfo))
-       {
-         if (maybe_gt (LOOP_VINFO_INT_NITERS (this_loop_vinfo),
-                       LOOP_VINFO_VECT_FACTOR (this_loop_vinfo)))
-           {
-             if (dump_enabled_p ())
-               dump_printf_loc (MSG_NOTE, vect_location,
-                                "Keep current LMUL loop because"
-                                " known NITERS exceed the new VF\n");
-             return false;
-           }
-       }
-    }
 
   /* Fall back to generic costing if either iteration count is unknown.  For
      known iteration counts, include loop overhead when comparing different
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113112-3.c 
b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113112-3.c
index 03d9f020bffd..86241e705767 100644
--- a/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113112-3.c
+++ b/gcc/testsuite/gcc.dg/vect/costmodel/riscv/rvv/pr113112-3.c
@@ -15,6 +15,6 @@ void bad1(int v1, int v2)
     }
 }
 
-/* { dg-final { scan-assembler {e32,m2} { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-not {jr} { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-times {ret} 1 { xfail *-*-* } } } */
+/* { dg-final { scan-assembler {e32,m2} } } */
+/* { dg-final { scan-assembler-not {jr} } } */
+/* { dg-final { scan-assembler-times {ret} 1 } } */

Reply via email to