From: Kito Cheng Date: Wed, 24 Apr 2024 08:54:44 +0000 (+0800) Subject: RISC-V: Fix recursive vsetvli checking [PR114172] X-Git-Tag: releases/gcc-13.3.0~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67e50daa5bd05f16d98c2dc651af2d6fa8335186;p=thirdparty%2Fgcc.git RISC-V: Fix recursive vsetvli checking [PR114172] extract_single_source will recursive checking the sources to make sure if it's single source, however it may cause infinite recursive when the source is come from itself, so it should just skip first source to prevent that. NOTE: This logic has existing on trunk/GCC 14, but it included in a big vsetvli improvement patch, which is not backport to GCC 13. ``` void saxpy_rvv_m8(float *y, long vl) { for (;;) { vl = __riscv_vsetvl_e32m8(vl); //ICE vfloat32m8_t y_vec; __riscv_vse32_v_f32m8(y, y_vec, vl); } } ``` gcc/ChangeLog: PR target/114172 * config/riscv/riscv-vsetvl.cc (extract_single_source): Skip first set. gcc/testsuite/ChangeLog: PR target/114172 * gcc.target/riscv/rvv/vsetvl/pr114172.c: New. --- diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 9dca2ce709dc..36d2e6e6f203 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -1196,6 +1196,10 @@ extract_single_source (set_info *set) return nullptr; for (const set_info *set : sets) { + /* Skip first set, this can prevent us run into infinite recursive + checking if first set is come from itself. */ + if (set == *sets.begin ()) + continue; /* If there is a head or end insn, we conservative return NULL so that VSETVL PASS will insert vsetvl directly. */ if (set->insn ()->is_artificial ()) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c new file mode 100644 index 000000000000..ed1494666d64 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/vsetvl/pr114172.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -fno-tree-vectorize" } */ + +#include "riscv_vector.h" + +void e(long, vfloat32m4_t); + +void b(long c) { + for (;;) { + c = __riscv_vsetvl_e32m4(c); + vfloat32m4_t d; + e(c, d); + } +}