From: Ju-Zhe Zhong <juzhe.zh...@rivai.ai> gcc/ChangeLog:
* config/riscv/riscv-vsetvl.cc (count_regno_occurrences): New function. (pass_vsetvl::cleanup_insns): Fix bug. --- gcc/config/riscv/riscv-vsetvl.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 1b66e3b9eeb..43e2cf08377 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -1592,6 +1592,19 @@ backward_propagate_worthwhile_p (const basic_block cfg_bb, return true; } +/* Count the number of REGNO in RINSN. */ +int +count_regno_occurrences (rtx_insn *rinsn, unsigned int regno) +{ + int count = 0; + extract_insn (rinsn); + for (int i = 0; i < recog_data.n_operands; i++) + if (REG_P (recog_data.operand[i]) + && REGNO (recog_data.operand[i]) == regno) + count++; + return count; +} + avl_info::avl_info (const avl_info &other) { m_value = other.get_value (); @@ -3924,7 +3937,7 @@ pass_vsetvl::cleanup_insns (void) const if (!has_vl_op (rinsn) || !REG_P (get_vl (rinsn))) continue; rtx avl = get_vl (rinsn); - if (count_occurrences (PATTERN (rinsn), avl, 0) == 1) + if (count_regno_occurrences (rinsn, REGNO (avl)) == 1) { /* Get the list of uses for the new instruction. */ auto attempt = crtl->ssa->new_change_attempt (); -- 2.36.3