]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: vsetvl: Add null check for fault-first loop [PR122652].
authorRobin Dapp <rdapp@ventanamicro.com>
Wed, 12 Nov 2025 09:17:47 +0000 (10:17 +0100)
committerRobin Dapp <rdapp@ventanamicro.com>
Mon, 1 Dec 2025 15:27:53 +0000 (16:27 +0100)
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.

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
gcc/testsuite/gcc.target/riscv/rvv/base/pr122652.c [new file with mode: 0644]

index 580ac9cbe8e88a98a93a787479f2242c6e9f374a..127187b455520a3f9e5846a34ccf7194c2bade1b 100644 (file)
@@ -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 (file)
index 0000000..bd8f1b4
--- /dev/null
@@ -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);
+  }
+}