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

commit r17-6628-gfb412af72edf69c8437bce09685d0d636db9d31e
Author: Kito Cheng <[email protected]>
Date:   Sat Oct 24 22:44:55 2026 +0800

    RISC-V: Work around SiFive erratum MAL-9174/MAL-9191
    
    On sifive-p870-d, a non-segment vector indexed load whose destination
    overlaps its index cannot restart correctly after a trap.  The elements
    from the faulting one onward are already written, so the index is clobbered
    and the restarted load reads from the wrong address.  SiFive tracks this
    erratum as both MAL-9174 and MAL-9191.
    
    Add -mfix-sifive-mal-9174, which keeps the destination from overlapping the
    index, and -mfix-sifive-mal-9191 as its alias.  It is on by default for
    sifive-p870-d.
    
    The new index_load_overlap attribute turns off the overlap alternatives when
    the workaround is on.  The same-EEW pattern also gets early-clobber
    alternatives.  They are marked with `?` so the code does not change when the
    workaround is off (without `?`, IRA gets slightly different costs and gives
    different results).
    
    gcc/ChangeLog:
    
            * config/riscv/riscv-cores.def (sifive-p870-d): Add erratum
            SIFIVE_MAL_9174.
            * config/riscv/riscv-errata.def (SIFIVE_MAL_9174): New erratum.
            (sifive-mal-9191): New alias.
            * config/riscv/riscv.md (index_load_overlap): New attribute.
            (enabled): Disable index_load_overlap alternatives for MAL-9174.
            * config/riscv/riscv.opt (mfix-sifive-mal-9174): New option.
            (mfix-sifive-mal-9191): New alias.
            * config/riscv/vector.md
            (@pred_indexed_<order>load<mode>_same_eew): Add early-clobber
            alternatives and set index_load_overlap.
            (@pred_indexed_<order>load<mode>_x2_smaller_eew): Set
            index_load_overlap.
            (@pred_indexed_<order>load<mode>_x4_smaller_eew): Likewise.
            (@pred_indexed_<order>load<mode>_x8_smaller_eew): Likewise.
            * doc/install.texi (--with-errata): List sifive-mal-9174 and
            sifive-mal-9191.
            * doc/invoke.texi (RISC-V Options): Document -mfix-sifive-mal-9174
            and -mfix-sifive-mal-9191.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/riscv/rvv/base/sifive-mal-9174-1.c: New test.
            * gcc.target/riscv/rvv/base/sifive-mal-9174-2.c: New test.
            * gcc.target/riscv/rvv/base/sifive-mal-9174-3.c: New test.
            * gcc.target/riscv/rvv/base/sifive-mal-9174-4.c: New test.
            * gcc.target/riscv/rvv/base/sifive-mal-9174-5.c: New test.
            * gcc.target/riscv/rvv/base/sifive-mal-9174-6.c: New test.

Diff:
---
 gcc/config/riscv/riscv-cores.def                   |  1 +
 gcc/config/riscv/riscv-errata.def                  |  3 ++
 gcc/config/riscv/riscv.md                          |  9 +++++
 gcc/config/riscv/riscv.opt                         |  8 ++++
 gcc/config/riscv/vector.md                         | 34 +++++++++-------
 gcc/doc/install.texi                               |  6 +++
 gcc/doc/invoke.texi                                | 25 ++++++++++++
 .../gcc.target/riscv/rvv/base/sifive-mal-9174-1.c  | 46 ++++++++++++++++++++++
 .../gcc.target/riscv/rvv/base/sifive-mal-9174-2.c  | 46 ++++++++++++++++++++++
 .../gcc.target/riscv/rvv/base/sifive-mal-9174-3.c  | 46 ++++++++++++++++++++++
 .../gcc.target/riscv/rvv/base/sifive-mal-9174-4.c  | 46 ++++++++++++++++++++++
 .../gcc.target/riscv/rvv/base/sifive-mal-9174-5.c  | 46 ++++++++++++++++++++++
 .../gcc.target/riscv/rvv/base/sifive-mal-9174-6.c  | 46 ++++++++++++++++++++++
 13 files changed, 348 insertions(+), 14 deletions(-)

diff --git a/gcc/config/riscv/riscv-cores.def b/gcc/config/riscv/riscv-cores.def
index 7d9995d92787..ea83e01386fe 100644
--- a/gcc/config/riscv/riscv-cores.def
+++ b/gcc/config/riscv/riscv-cores.def
@@ -204,6 +204,7 @@ RISCV_CORE("sifive-p870-d",   
"rv64imafdcbv_zic64b_zicbom_zicbop_zicboz_"
                              /* MVENDORID */ 0x489,
                              /* MARCHID */ 0x8000000000000109ULL,
                              /* MIMPID */ 0x14250606ULL)
+RISCV_CORE_ERRATUM("sifive-p870-d", SIFIVE_MAL_9174)
 
 RISCV_CORE("thead-c906",      
"rv64imafdc_xtheadba_xtheadbb_xtheadbs_xtheadcmo_"
                              "xtheadcondmov_xtheadfmemidx_xtheadmac_"
diff --git a/gcc/config/riscv/riscv-errata.def 
b/gcc/config/riscv/riscv-errata.def
index 66787ab9f7d0..d666cd2e0802 100644
--- a/gcc/config/riscv/riscv-errata.def
+++ b/gcc/config/riscv/riscv-errata.def
@@ -42,5 +42,8 @@
 #define RISCV_ERRATUM_ALIAS(ALIAS, ID)
 #endif
 
+RISCV_ERRATUM(SIFIVE_MAL_9174, "sifive-mal-9174", riscv_fix_sifive_mal_9174)
+RISCV_ERRATUM_ALIAS("sifive-mal-9191", SIFIVE_MAL_9174)
+
 #undef RISCV_ERRATUM
 #undef RISCV_ERRATUM_ALIAS
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md
index f45d003e1f76..175718832dbf 100644
--- a/gcc/config/riscv/riscv.md
+++ b/gcc/config/riscv/riscv.md
@@ -603,6 +603,11 @@
        ]
        (const_string "no")))
 
+;; This attribute marks the vector indexed load alternatives that let the
+;; destination overlap the index.
+(define_attr "index_load_overlap" "no,yes"
+  (const_string "no"))
+
 ;; Attribute to control enable or disable instructions.
 (define_attr "enabled" "no,yes"
   (cond [
@@ -614,6 +619,10 @@
 
     (eq_attr "spec_restriction_disabled" "yes")
     (const_string "no")
+
+    (and (eq_attr "index_load_overlap" "yes")
+        (match_test "RISCV_ERRATUM_P (SIFIVE_MAL_9174)"))
+    (const_string "no")
   ]
   (const_string "yes")))
 
diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt
index 3226367bf8a9..61d629c45c95 100644
--- a/gcc/config/riscv/riscv.opt
+++ b/gcc/config/riscv/riscv.opt
@@ -144,6 +144,14 @@ mvector-strict-align
 Target Save Var(rvv_vector_strict_align) Init(1)
 Do not create element-misaligned vector memory accesses.
 
+mfix-sifive-mal-9174
+Target Save Var(riscv_fix_sifive_mal_9174) Init(-1)
+Work around SiFive erratum MAL-9174.
+
+mfix-sifive-mal-9191
+Target Alias(mfix-sifive-mal-9174)
+Work around SiFive erratum MAL-9191.
+
 Enum
 Name(code_model) Type(enum riscv_code_model)
 Known code models (for use with the -mcmodel= option):
diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md
index d8a4b47855da..8120084f6c5d 100644
--- a/gcc/config/riscv/vector.md
+++ b/gcc/config/riscv/vector.md
@@ -2612,27 +2612,30 @@
 ;; - 7.6. Vector Indexed Instructions
 ;; 
-------------------------------------------------------------------------------
 
-;; DEST eew is same as SOURCE eew, DEST register can overlap SOURCE.
+;; DEST eew is same as SOURCE eew, DEST register can overlap SOURCE,
+;; except for the last four alternatives, which are for SiFive erratum
+;; MAL-9174 (also MAL-9191).
 (define_insn "@pred_indexed_<order>load<mode>_same_eew"
-  [(set (match_operand:VINDEXED 0 "register_operand"        "=vd, vr,vd, vr")
+  [(set (match_operand:VINDEXED 0 "register_operand"        "=vd, vr,vd, 
vr,?&vd,?&vr,?&vd,?&vr")
        (if_then_else:VINDEXED
          (unspec:<VM>
-           [(match_operand:<VM> 1 "vector_mask_operand"    " vm,Wc1,vm,Wc1")
-            (match_operand 5 "vector_length_operand"       "rvl,rvl,rvl,rvl")
-            (match_operand 6 "const_int_operand"           "  i,  i, i,  i")
-            (match_operand 7 "const_int_operand"           "  i,  i, i,  i")
-            (match_operand 8 "const_int_operand"           "  i,  i, i,  i")
+           [(match_operand:<VM> 1 "vector_mask_operand"    " vm,Wc1,vm,Wc1, 
vm,Wc1, vm,Wc1")
+            (match_operand 5 "vector_length_operand"       
"rvl,rvl,rvl,rvl,rvl,rvl,rvl,rvl")
+            (match_operand 6 "const_int_operand"           "  i,  i, i,  i,  
i,  i,  i,  i")
+            (match_operand 7 "const_int_operand"           "  i,  i, i,  i,  
i,  i,  i,  i")
+            (match_operand 8 "const_int_operand"           "  i,  i, i,  i,  
i,  i,  i,  i")
             (reg:SI VL_REGNUM)
             (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE)
          (unspec:VINDEXED
-           [(match_operand 3 "pmode_reg_or_0_operand"      " rJ, rJ,rJ, rJ")
+           [(match_operand 3 "pmode_reg_or_0_operand"      " rJ, rJ,rJ, rJ, 
rJ, rJ, rJ, rJ")
             (mem:BLK (scratch))
-            (match_operand:<VINDEX> 4 "register_operand"   " vr, vr,vr, vr")] 
ORDER)
-         (match_operand:VINDEXED 2 "vector_merge_operand"  " vu, vu, 0,  0")))]
+            (match_operand:<VINDEX> 4 "register_operand"   " vr, vr,vr, vr, 
vr, vr, vr, vr")] ORDER)
+         (match_operand:VINDEXED 2 "vector_merge_operand"  " vu, vu, 0,  0, 
vu, vu,  0,  0")))]
   "TARGET_VECTOR"
   "vl<order>xei<sew>.v\t%0,(%z3),%4%p1"
   [(set_attr "type" "vld<order>x")
-   (set_attr "mode" "<MODE>")])
+   (set_attr "mode" "<MODE>")
+   (set_attr "index_load_overlap" "yes,yes,yes,yes,no,no,no,no")])
 
 ;; DEST eew is greater than SOURCE eew.
 (define_insn "@pred_indexed_<order>load<mode>_x2_greater_eew"
@@ -2718,7 +2721,8 @@
   "TARGET_VECTOR"
   "vl<order>xei<double_ext_sew>.v\t%0,(%z3),%4%p1"
   [(set_attr "type" "vld<order>x")
-   (set_attr "mode" "<MODE>")])
+   (set_attr "mode" "<MODE>")
+   (set_attr "index_load_overlap" "yes,yes,yes,yes,no,no")])
 
 (define_insn "@pred_indexed_<order>load<mode>_x4_smaller_eew"
   [(set (match_operand:VEEWTRUNC4 0 "register_operand"             "=vd, vd, 
vr, vr,  &vr,  &vr")
@@ -2739,7 +2743,8 @@
   "TARGET_VECTOR"
   "vl<order>xei<quad_ext_sew>.v\t%0,(%z3),%4%p1"
   [(set_attr "type" "vld<order>x")
-   (set_attr "mode" "<MODE>")])
+   (set_attr "mode" "<MODE>")
+   (set_attr "index_load_overlap" "yes,yes,yes,yes,no,no")])
 
 (define_insn "@pred_indexed_<order>load<mode>_x8_smaller_eew"
   [(set (match_operand:VEEWTRUNC8 0 "register_operand"            "=vd, vd, 
vr, vr,  &vr,  &vr")
@@ -2760,7 +2765,8 @@
   "TARGET_VECTOR"
   "vl<order>xei<oct_ext_sew>.v\t%0,(%z3),%4%p1"
   [(set_attr "type" "vld<order>x")
-   (set_attr "mode" "<MODE>")])
+   (set_attr "mode" "<MODE>")
+   (set_attr "index_load_overlap" "yes,yes,yes,yes,no,no")])
 
 (define_insn "@pred_indexed_<order>store<mode>_same_eew"
   [(set (mem:BLK (scratch))
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 71272395fc1f..45285733d644 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1934,6 +1934,12 @@ comma-separated @var{list} by default, as if the matching
 @option{-mfix-@var{erratum}} options were given.  @var{list} can also be
 @samp{all} for every erratum GCC knows about, or @samp{none}, which is the
 default.  The @option{-mno-fix-@var{erratum}} options still disable them.
+The errata GCC knows about are:
+@table @code
+@item sifive-mal-9174
+@itemx sifive-mal-9191
+See @option{-mfix-sifive-mal-9174}.
+@end table
 
 @item --enable-__cxa_atexit
 Define if you want to use @code{__cxa_atexit}, rather than @code{atexit},
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d724cad22f0d..a8185b5c7809 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1342,6 +1342,7 @@ See RS/6000 and PowerPC Options.
 -msave-restore  -mno-shorten-memrefs
 -mstrict-align  -mscalar-strict-align  -mno-vector-strict-align
 -mzilsd-word-align  -mzilsd-strict-align
+-mfix-sifive-mal-9174  -mfix-sifive-mal-9191
 -mcmodel=medlow  -mcmodel=medany  -mcmodel=large
 -mexplicit-relocs  -mrelax  -mriscv-attribute
 -malign-data=@var{type}
@@ -31695,6 +31696,30 @@ The precedence among @option{-mzilsd-word-align},
 @option{-mno-strict-align}, @option{-mscalar-strict-align}, and
 @option{-mno-scalar-strict-align} is determined by the last one specified.
 
+@opindex mfix-sifive-mal-9174
+@opindex mno-fix-sifive-mal-9174
+@opindex mfix-sifive-mal-9191
+@opindex mno-fix-sifive-mal-9191
+@item -mfix-sifive-mal-9174
+@itemx -mno-fix-sifive-mal-9174
+@itemx -mfix-sifive-mal-9191
+@itemx -mno-fix-sifive-mal-9191
+Enable or disable the workaround for SiFive erratum MAL-9174, also known
+as MAL-9191, which keeps the destination of a vector indexed load from
+overlapping its index.  On the affected cores, a trap in the middle of
+such a load can clobber the index, so the load reads from the wrong
+address when it is restarted.
+
+By default, the workarounds for the errata of the processor selected by
+@option{-mcpu} are enabled, along with the ones given by the
+@option{--with-errata} configure option.  @option{-mtune} has no effect
+on them.  The errata of each processor are:
+
+@table @samp
+@item sifive-p870-d
+@samp{sifive-mal-9174} (also @samp{sifive-mal-9191})
+@end table
+
 @opindex mmax-vectorization
 @opindex mno-max-vectorization
 @item -mmax-vectorization
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-1.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-1.c
new file mode 100644
index 000000000000..9a19a32e8a05
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-1.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -mfix-sifive-mal-9174" } */
+
+/* The destination of an indexed load must not overlap the index.  */
+
+#include <riscv_vector.h>
+
+vint32m1_t
+tama (int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1 (base, index, vl);
+}
+
+vint32m1_t
+tamu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1_m (m, base, index, vl);
+}
+
+vint32m1_t
+tu (int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tu (merge, base, index, vl);
+}
+
+vint32m1_t
+tumu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tumu (m, merge, base, index, vl);
+}
+
+vint8mf8_t
+se (void *base, vuint64m1_t index, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8 (base, index, vl);
+}
+
+vint8mf8_t
+se_tu (void *base, vuint64m1_t index, vint8mf8_t merge, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8_tu (merge, base, index, vl);
+}
+
+/* { dg-final { scan-assembler-not 
{vl[ou]xei[0-9]+\.v\s+v([0-9]+),\([^)]*\),v\1\M} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-2.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-2.c
new file mode 100644
index 000000000000..ccd8c84477b7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-2.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -mcpu=sifive-p870-d" } */
+
+/* -mcpu=sifive-p870-d enables the workaround.  */
+
+#include <riscv_vector.h>
+
+vint32m1_t
+tama (int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1 (base, index, vl);
+}
+
+vint32m1_t
+tamu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1_m (m, base, index, vl);
+}
+
+vint32m1_t
+tu (int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tu (merge, base, index, vl);
+}
+
+vint32m1_t
+tumu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tumu (m, merge, base, index, vl);
+}
+
+vint8mf8_t
+se (void *base, vuint64m1_t index, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8 (base, index, vl);
+}
+
+vint8mf8_t
+se_tu (void *base, vuint64m1_t index, vint8mf8_t merge, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8_tu (merge, base, index, vl);
+}
+
+/* { dg-final { scan-assembler-not 
{vl[ou]xei[0-9]+\.v\s+v([0-9]+),\([^)]*\),v\1\M} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-3.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-3.c
new file mode 100644
index 000000000000..b70db59fc615
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-3.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -mcpu=sifive-p870-d 
-mno-fix-sifive-mal-9174" } */
+
+/* -mno-fix-sifive-mal-9174 overrides -mcpu.  */
+
+#include <riscv_vector.h>
+
+vint32m1_t
+tama (int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1 (base, index, vl);
+}
+
+vint32m1_t
+tamu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1_m (m, base, index, vl);
+}
+
+vint32m1_t
+tu (int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tu (merge, base, index, vl);
+}
+
+vint32m1_t
+tumu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tumu (m, merge, base, index, vl);
+}
+
+vint8mf8_t
+se (void *base, vuint64m1_t index, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8 (base, index, vl);
+}
+
+vint8mf8_t
+se_tu (void *base, vuint64m1_t index, vint8mf8_t merge, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8_tu (merge, base, index, vl);
+}
+
+/* { dg-final { scan-assembler 
{vl[ou]xei[0-9]+\.v\s+v([0-9]+),\([^)]*\),v\1\M} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-4.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-4.c
new file mode 100644
index 000000000000..ee4df93b424f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-4.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -mtune=sifive-p870-d" } */
+
+/* -mtune does not enable the workaround.  */
+
+#include <riscv_vector.h>
+
+vint32m1_t
+tama (int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1 (base, index, vl);
+}
+
+vint32m1_t
+tamu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1_m (m, base, index, vl);
+}
+
+vint32m1_t
+tu (int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tu (merge, base, index, vl);
+}
+
+vint32m1_t
+tumu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tumu (m, merge, base, index, vl);
+}
+
+vint8mf8_t
+se (void *base, vuint64m1_t index, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8 (base, index, vl);
+}
+
+vint8mf8_t
+se_tu (void *base, vuint64m1_t index, vint8mf8_t merge, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8_tu (merge, base, index, vl);
+}
+
+/* { dg-final { scan-assembler 
{vl[ou]xei[0-9]+\.v\s+v([0-9]+),\([^)]*\),v\1\M} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-5.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-5.c
new file mode 100644
index 000000000000..20937c41a962
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-5.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -mfix-sifive-mal-9191" } */
+
+/* -mfix-sifive-mal-9191 is an alias of -mfix-sifive-mal-9174.  */
+
+#include <riscv_vector.h>
+
+vint32m1_t
+tama (int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1 (base, index, vl);
+}
+
+vint32m1_t
+tamu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1_m (m, base, index, vl);
+}
+
+vint32m1_t
+tu (int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tu (merge, base, index, vl);
+}
+
+vint32m1_t
+tumu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tumu (m, merge, base, index, vl);
+}
+
+vint8mf8_t
+se (void *base, vuint64m1_t index, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8 (base, index, vl);
+}
+
+vint8mf8_t
+se_tu (void *base, vuint64m1_t index, vint8mf8_t merge, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8_tu (merge, base, index, vl);
+}
+
+/* { dg-final { scan-assembler-not 
{vl[ou]xei[0-9]+\.v\s+v([0-9]+),\([^)]*\),v\1\M} } } */
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-6.c 
b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-6.c
new file mode 100644
index 000000000000..176ac1fcf5d0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/base/sifive-mal-9174-6.c
@@ -0,0 +1,46 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64d -O2 -mcpu=sifive-p870-d 
-mno-fix-sifive-mal-9191" } */
+
+/* -mno-fix-sifive-mal-9191 overrides -mcpu.  */
+
+#include <riscv_vector.h>
+
+vint32m1_t
+tama (int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1 (base, index, vl);
+}
+
+vint32m1_t
+tamu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  return __riscv_vluxei32_v_i32m1_m (m, base, index, vl);
+}
+
+vint32m1_t
+tu (int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tu (merge, base, index, vl);
+}
+
+vint32m1_t
+tumu (vbool32_t m, int *base, vuint32m1_t index, size_t vl)
+{
+  vint32m1_t merge = __riscv_vreinterpret_v_u32m1_i32m1 (index);
+  return __riscv_vluxei32_v_i32m1_tumu (m, merge, base, index, vl);
+}
+
+vint8mf8_t
+se (void *base, vuint64m1_t index, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8 (base, index, vl);
+}
+
+vint8mf8_t
+se_tu (void *base, vuint64m1_t index, vint8mf8_t merge, size_t vl)
+{
+  return __riscv_vluxei64_v_i8mf8_tu (merge, base, index, vl);
+}
+
+/* { dg-final { scan-assembler 
{vl[ou]xei[0-9]+\.v\s+v([0-9]+),\([^)]*\),v\1\M} } } */

Reply via email to