This patch fixes this issue happens on GCC-13.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110560

This patch should be backported to GCC-13.
GCC-14 has rewritten this function, so there is no issue.

PR target/110560

gcc/ChangeLog:

        * config/riscv/riscv-vsetvl.cc (local_eliminate_vsetvl_insn): Fix bug.
---
 gcc/config/riscv/riscv-vsetvl.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index 35403b5679c..3355ca4e3fb 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -1078,6 +1078,10 @@ local_eliminate_vsetvl_insn (const vector_insn_info &dem)
 
          if (has_vtype_op (i->rtl ()))
            {
+             if (!PREV_INSN (i->rtl ()))
+               return;
+             if (!NONJUMP_INSN_P (PREV_INSN (i->rtl ())))
+               return;
              if (!vsetvl_discard_result_insn_p (PREV_INSN (i->rtl ())))
                return;
              rtx avl = get_avl (i->rtl ());
-- 
2.17.1

Reply via email to