On Wed, Jul 02, 2025 at 08:15:40PM -0600, Jeff Law wrote:
> 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

------------ 8< ------------

>From 0c0a463b30a4dd30b50d9854f55b0a594bebefc1 Mon Sep 17 00:00:00 2001
From: Artemiy Volkov <artem...@acm.org>
Date: Wed, 16 Jul 2025 16:12:02 +0000
Subject: [PATCH] RISC-V: prevent NULL_RTX dereference in
 riscv_macro_fusion_pair_p ()

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.

Signed-off-by: Artemiy Volkov <artem...@acm.org>
---
 gcc/config/riscv/riscv.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 1275b034cf8..0517e797494 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -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);
 
-- 
2.43.0

Reply via email to