On Fri, May 15, 2026 at 6:10 PM Richard Sandiford
<[email protected]> wrote:
>
> "H.J. Lu" <[email protected]> writes:
> > Mark accessible caller-saved registers as live to prevent IRA from
> > generating invalid instructions when call_used_regs includes registers
> > disabled by ISA selections.
> >
> > PR rtl-optimization/125321
> > * ira.cc (update_equiv_regs_prescan): Mark a register as live
> > only if it is accessible.
>
> You didn't mention where you saw this, but FWIW, it seems to fix
> an ICE in:
>
> /* { dg-options "-O2 -masm=att -mno-mmx -mno-80387 -msse" } */
>
> extern void callee_clobbered () [[gnu::preserve_none]];
> extern void callee_preserved () [[gnu::no_caller_saved_registers]];
> extern void callee_sysv () [[gnu::sysv_abi]];
> extern void callee_ms () [[gnu::ms_abi]];
>
> #define TEST(PREFIX, ATTR) \
>   void PREFIX##_clobbered () [[ATTR]] { callee_clobbered (); } \
>   void PREFIX##_preserved () [[ATTR]] { callee_preserved (); } \
>   void PREFIX##_sysv () [[ATTR]] { callee_sysv (); } \
>   void PREFIX##_ms () [[ATTR]] { callee_ms (); }
>
> TEST (clobbered, gnu::preserve_none)
> TEST (preserved, gnu::no_caller_saved_registers)
> TEST (sysv, gnu::sysv_abi)
> TEST (ms, gnu::ms_abi)
>
> /* { dg-final { scan-assembler-not "%st" } } */
> /* { dg-final { scan-assembler "%xmm" } } */
>
> with the x86 function_abi patch.  The ICE was from reg-stack.cc,
> but I agree that a change there would probably just be papering
> over the problem.

If a register is disabled in the caller, there is nothing that the caller can
do about it.

> > From 314a6328eb9bcdc9bbbd201f79fa8ab0a48c0f5e Mon Sep 17 00:00:00 2001
> > From: "H.J. Lu" <[email protected]>
> > Date: Fri, 15 May 2026 08:01:56 +0800
> > Subject: [PATCH] ira: Mark a register as live only if it is accessible
> >
> > Mark accessible caller-saved registers as live to prevent IRA from
> > generating invalid instructions when call_used_regs includes registers
> > disabled by ISA selections.
> >
> >       PR rtl-optimization/125321
> >       * ira.cc (update_equiv_regs_prescan): Mark a register as live
> >       only if it is accessible.
> >
> > Signed-off-by: H.J. Lu <[email protected]>
> > ---
> >  gcc/ira.cc | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/gcc/ira.cc b/gcc/ira.cc
> > index 85c7ec419b3..fdb4f66fb2f 100644
> > --- a/gcc/ira.cc
> > +++ b/gcc/ira.cc
> > @@ -3610,9 +3610,11 @@ update_equiv_regs_prescan (void)
> >       }
> >
> >    HARD_REG_SET extra_caller_saves = callee_abis.caller_save_regs 
> > (*crtl->abi);
> > +  /* Mark a register as live only if it is accessible.  */
> >    if (!hard_reg_set_empty_p (extra_caller_saves))
> >      for (unsigned int regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
> > -      if (TEST_HARD_REG_BIT (extra_caller_saves, regno))
> > +      if (TEST_HARD_REG_BIT (accessible_reg_set, regno)
> > +       && TEST_HARD_REG_BIT (extra_caller_saves, regno))
> >       df_set_regs_ever_live (regno, true);
> >  }
>
> I think it'd be better to change:
>
>   return result;
>
> to:
>
>   return result & accessible_reg_set;
>
> in function_abi_aggregator::caller_save_regs, since other callers might
> otherwise have the same issue.

I will give it a try.

Thanks.

> Thanks,
> Richard



-- 
H.J.

Reply via email to