[PATCH] RISC-V: prevent NULL_RTX dereference in riscv_macro_fusion_pair_p ()

> A number of folks have had their fingers in this code and it's going to take
> a few submissions to do everything we want to do.
>
> This patch is primarily concerned with avoiding signaling that fusion can
> occur in cases where it obviously should not be signaling fusion.

Hi Jeff,

With this change, we're liable to ICE whenever prev_set or curr_set are
NULL_RTX.  For a fix, how about something like the below?

Thanks,
Artemiy

Introduced in r16-1984-g83d19b5d842dad, initializers for
{prev,curr}_dest_regno can cause an ICE if the respective insn isn't a
single set.  Rectify this by inserting a NULL_RTX check before using
{prev,curr}_set.

Regtested on riscv32.

gcc/
	* config/riscv/riscv.cc (riscv_macro_fusion_pair_p): Protect
	from a NULL PREV_SET or CURR_SET.
This commit is contained in:
Artemiy Volkov
2025-07-19 08:03:02 -06:00
committed by Jeff Law
parent e6e5040097
commit 7999eb8672

View File

@ -10359,10 +10359,10 @@ riscv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr)
bool simple_sets_p = prev_set && curr_set && !any_condjump_p (curr);
bool sched1 = can_create_pseudo_p ();
unsigned int prev_dest_regno = (REG_P (SET_DEST (prev_set))
unsigned int prev_dest_regno = (prev_set && REG_P (SET_DEST (prev_set))
? REGNO (SET_DEST (prev_set))
: FIRST_PSEUDO_REGISTER);
unsigned int curr_dest_regno = (REG_P (SET_DEST (curr_set))
unsigned int curr_dest_regno = (curr_set && REG_P (SET_DEST (curr_set))
? REGNO (SET_DEST (curr_set))
: FIRST_PSEUDO_REGISTER);