On 8/22/24 12:46, Patrick O'Neill wrote:
These cases are handled in the expander
(riscv-v.cc:expand_const_vector). We need the vector builder to detect
these cases so extract that out into a new riscv-v.h header file.

gcc/ChangeLog:

        * config/riscv/riscv-v.cc (class rvv_builder): Move to riscv-v.h.
        * config/riscv/riscv.cc (riscv_const_insns): Emit placeholder costs for
        bool/stepped const vectors.
        * config/riscv/riscv-v.h: New file.

Signed-off-by: Patrick O'Neill <patr...@rivosinc.com>
---
<snip>
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index eb1c172d1ce..a820cadd205 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -75,6 +75,7 @@ along with GCC; see the file COPYING3.  If not see
  #include "gcse.h"
  #include "tree-dfa.h"
  #include "target-globals.h"
+#include "riscv-v.h"
/* This file should be included last. */
  #include "target-def.h"
@@ -2145,6 +2146,10 @@ riscv_const_insns (rtx x, bool allow_new_pseudos)
            rtx elt;
            if (const_vec_duplicate_p (x, &elt))
              {
+               if (GET_MODE_CLASS (GET_MODE (x)) == MODE_VECTOR_BOOL)
+                 /* Duplicate values of 0/1 can be emitted using vmv.v.i.  */
+                 return 1;
+
                /* We don't allow CONST_VECTOR for DI vector on RV32
                   system since the ELT constant value can not held
                   within a single register to disable reload a DI
@@ -2184,6 +2189,43 @@ riscv_const_insns (rtx x, bool allow_new_pseudos)
                   accurately according to BASE && STEP.  */
                return 1;
              }
+
+           if (CONST_VECTOR_STEPPED_P (x))
+             {
+               /* Some cases are unhandled so we need construct a builder to
+                  detect/allow those cases to be handled by the fallthrough
+                  handler.  */
+               unsigned int nelts_per_pattern = CONST_VECTOR_NELTS_PER_PATTERN 
(x);
+               unsigned int npatterns = CONST_VECTOR_NPATTERNS (x);
+               rvv_builder builder (mode, npatterns, nelts_per_pattern);
+               for (unsigned int i = 0; i < nelts_per_pattern; i++)
+                 {
+                   for (unsigned int j = 0; j < npatterns; j++)
+                     builder.quick_push (CONST_VECTOR_ELT (x, i * npatterns + 
j));
+                 }
+               builder.finalize ();
+
+               if (builder.single_step_npatterns_p ())
+                 {
+                   if (builder.npatterns_all_equal_p ())
+                     {
+                       /* TODO: This cost is not accurate.  */
+                       return 1;
+                     }
+                   else
+                     {
+                       /* TODO: This cost is not accurate.  */
+                       return 1;
+                     }
+                 }
+               else if (builder.interleaved_stepped_npatterns_p ())
+                 {
+                   /* TODO: This cost is not accurate.  */
+                   return 1;
+                 }
+
+               /* Fallthrough to catch all pattern.  */

Precommit highlighted that patches 6-8 fail to build.

This comment should instead be a return 0; since the catch all pattern isn't added till patch 9.

Patch 9 should then replace the return 0; with this comment.

I'll fix this before landing or in v2.

Patrick

+             }
          }
/* TODO: We may support more const vector in the future. */

Reply via email to