LGTM :)
On Mon, Dec 1, 2025 at 7:44 PM Robin Dapp <[email protected]> wrote: > > Hi, > > For a fault-first load we store the first instruction that read its VL > result. The loop to do so uses next_nondebug_insn () which returns > nullptr when we are at the end. Check for that before accessing the > next insn. > > Regtested on rv64gcbv_zvl512b, going to commit if the CI is clean. > > Regards > Robin > > PR target/122652 > > gcc/ChangeLog: > > * config/riscv/riscv-vsetvl.cc: Add nullptr check. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/rvv/base/pr122652.c: New test. > --- > gcc/config/riscv/riscv-vsetvl.cc | 2 +- > .../gcc.target/riscv/rvv/base/pr122652.c | 22 +++++++++++++++++++ > 2 files changed, 23 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/pr122652.c > > diff --git a/gcc/config/riscv/riscv-vsetvl.cc > b/gcc/config/riscv/riscv-vsetvl.cc > index 580ac9cbe8e..127187b4555 100644 > --- a/gcc/config/riscv/riscv-vsetvl.cc > +++ b/gcc/config/riscv/riscv-vsetvl.cc > @@ -1176,7 +1176,7 @@ public: > if (fault_first_load_p (insn->rtl ())) > { > for (insn_info *i = insn->next_nondebug_insn (); > - i->bb () == insn->bb (); i = i->next_nondebug_insn ()) > + i && i->bb () == insn->bb (); i = i->next_nondebug_insn ()) > { > if (find_access (i->defs (), VL_REGNUM)) > break; > diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/pr122652.c > b/gcc/testsuite/gcc.target/riscv/rvv/base/pr122652.c > new file mode 100644 > index 00000000000..bd8f1b4d3ef > --- /dev/null > +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/pr122652.c > @@ -0,0 +1,22 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d" } */ > + > +#include "riscv_vector.h" > + > +int a; > +int b(); > + > +int c() { > + if (b()) > + a = 0; > +} > + > +void d() { > + for (; c() + d;) { > + long e, h; > + char *f; > + __rvv_uint16mf4_t g; > + __rvv_uint8mf8x3_t i = __riscv_vlseg3e8ff_v_u8mf8x3(f, &h, e); > + __riscv_vsoxseg3ei16_v_u8mf8x3(0, g, i, 0); > + } > +} > -- > 2.51.1 >
