https://gcc.gnu.org/g:f6ff8dc86aa77532192a70c54a1448dc2a083520

commit r17-6429-gf6ff8dc86aa77532192a70c54a1448dc2a083520
Author: Robin Dapp <[email protected]>
Date:   Wed Nov 18 12:01:27 2026 +0100

    RISC-V: Always record largest type for conv-dynamic [PR128841].
    
    If the type is unusable for -mrvv-max-lmul=conv-dynamic in
    record_type_sizes, we just return.  It can happen that all types
    are unusable and we end up dereferencing a NULL largest_type.
    
    This patch always records a char type so we have something to work with
    later, even if we don't raise LMUL.
    
            PR target/128841
    
    gcc/ChangeLog:
    
            * config/riscv/riscv-vector-costs.cc (costs::record_type_sizes):
            Record char as largest_type if type is unusable.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/riscv/rvv/autovec/pr128841.c: New test.

Diff:
---
 gcc/config/riscv/riscv-vector-costs.cc                |  6 +++++-
 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr128841.c | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv-vector-costs.cc 
b/gcc/config/riscv/riscv-vector-costs.cc
index d26a390793c3..5d9ed242eee6 100644
--- a/gcc/config/riscv/riscv-vector-costs.cc
+++ b/gcc/config/riscv/riscv-vector-costs.cc
@@ -1545,7 +1545,11 @@ costs::record_type_sizes (vect_cost_for_stmt kind, 
stmt_vec_info stmt_info,
       || TREE_CODE (type) == BOOLEAN_TYPE
       || !TYPE_SIZE (type)
       || !tree_fits_uhwi_p (TYPE_SIZE (type)))
-    return;
+    {
+      if (!m_largest_type)
+       m_largest_type = char_type_node;
+      return;
+    }
 
   unsigned HOST_WIDE_INT size = tree_to_uhwi (TYPE_SIZE (type));
   if (!m_largest_type || size > tree_to_uhwi (TYPE_SIZE (m_largest_type)))
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr128841.c 
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr128841.c
new file mode 100644
index 000000000000..271d5e0f9af2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr128841.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=rv64gcbv -mabi=lp64d -mrvv-max-lmul=conv-dynamic" 
} */
+
+short selectend_nurb_bp_1;
+char selectend_nurb_sel;
+void swap_selection_bpoint();
+void selectend_nurb(char doswap) {
+  int nu_3;
+  while (nu_3--)
+    if (selectend_nurb_bp_1) {
+      if (doswap)
+        swap_selection_bpoint();
+      else
+        selectend_nurb_sel = 1;
+      if (selectend_nurb_sel)
+        break;
+    }
+}

Reply via email to